mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Implements tests for commit eaca69bf2a
This commit is contained in:
1 parent
94a67aded4
commit
d185c77999
15 files changed
+527
-128
No files matched your search
+130
@@ -134,6 +134,136 @@ public class SharedReferenceResolverTests
|
||||
Assert.Equal("horror", resolvedTag.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResolveAsync_WhenIncomingNamesDifferOnlyByWhitespaceAndCasing_ShouldCollapseThemToTheNormalizedName()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity firstTag = _tagEntityFixture.Create(name: " Horror ");
|
||||
TagEntity secondTag = _tagEntityFixture.Create(name: "HORROR");
|
||||
TagEntity thirdTag = _tagEntityFixture.Create(name: "horror");
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyDictionary<string, TagEntity>> resolveResult = await SharedReferenceResolver.ResolveAsync(_mockContext, [firstTag, secondTag, thirdTag], Errors.Metadata.TagNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(resolveResult.IsFailure);
|
||||
Assert.Single(resolveResult.Value);
|
||||
Assert.Same(firstTag, resolveResult.Value["horror"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResolveAsync_WhenAStoredNormalizedNameExistsAndTheIncomingNameIsPaddedAndMixedCase_ShouldReturnTheStoredInstance()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity storedTag = _tagEntityFixture.Create(name: "horror");
|
||||
_mockContext.Set<TagEntity>().Add(storedTag);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Detach the stored row, so that the resolution cannot take the tracked shortcut and must read it from the storage medium.
|
||||
_mockContext.ChangeTracker.Clear();
|
||||
TagEntity incomingTag = _tagEntityFixture.Create(name: " HoRRoR ");
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyDictionary<string, TagEntity>> resolveResult = await SharedReferenceResolver.ResolveAsync(_mockContext, [incomingTag], Errors.Metadata.TagNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(resolveResult.IsFailure);
|
||||
Assert.Single(resolveResult.Value);
|
||||
TagEntity resolvedTag = resolveResult.Value["horror"];
|
||||
Assert.NotSame(incomingTag, resolvedTag);
|
||||
Assert.Equal("horror", resolvedTag.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResolveAsync_WhenATrackedLegacyMixedCaseRowExistsAndTheIncomingNameIsNormalized_ShouldReturnTheTrackedInstance()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity trackedTag = _tagEntityFixture.Create(name: "Horror");
|
||||
_mockContext.Set<TagEntity>().Add(trackedTag);
|
||||
TagEntity incomingTag = _tagEntityFixture.Create(name: "horror");
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyDictionary<string, TagEntity>> resolveResult = await SharedReferenceResolver.ResolveAsync(_mockContext, [incomingTag], Errors.Metadata.TagNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(resolveResult.IsFailure);
|
||||
Assert.Same(trackedTag, resolveResult.Value["horror"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResolveAsync_WhenANonAsciiUppercaseNameMatchesAStoredLowercaseName_ShouldReturnTheStoredInstance()
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity storedGenre = _genreEntityFixture.Create(name: "électro");
|
||||
_mockContext.Set<GenreEntity>().Add(storedGenre);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Detach the stored row, so that the resolution cannot take the tracked shortcut and must read it from the storage medium.
|
||||
_mockContext.ChangeTracker.Clear();
|
||||
GenreEntity incomingGenre = _genreEntityFixture.Create(name: "ÉLECTRO");
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyDictionary<string, GenreEntity>> resolveResult = await SharedReferenceResolver.ResolveAsync(_mockContext, [incomingGenre], Errors.Metadata.GenreNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(resolveResult.IsFailure);
|
||||
Assert.Single(resolveResult.Value);
|
||||
GenreEntity resolvedGenre = resolveResult.Value["électro"];
|
||||
Assert.NotSame(incomingGenre, resolvedGenre);
|
||||
Assert.Equal("électro", resolvedGenre.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Normalize_WhenANameIsPaddedAndMixedCase_ShouldMapToTheResolvedInstance()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity resolvedTag = _tagEntityFixture.Create(name: "horror");
|
||||
TagEntity incomingTag = _tagEntityFixture.Create(name: " HoRRoR ");
|
||||
Result<IReadOnlyDictionary<string, TagEntity>> resolveResult = await SharedReferenceResolver.ResolveAsync(_mockContext, [resolvedTag], Errors.Metadata.TagNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Act
|
||||
IReadOnlyCollection<TagEntity> normalizedTags = SharedReferenceResolver.Normalize([incomingTag], resolveResult.Value);
|
||||
|
||||
// Assert
|
||||
Assert.Same(resolvedTag, Assert.Single(normalizedTags));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileAsync_WhenAStoredNormalizedNameExistsAndTheIncomingNameIsPaddedAndMixedCase_ShouldReuseTheStoredInstance()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity storedTag = _tagEntityFixture.Create(name: "horror");
|
||||
_mockContext.Set<TagEntity>().Add(storedTag);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
List<TagEntity> trackedTags = [];
|
||||
TagEntity incomingTag = _tagEntityFixture.Create(name: " HoRRoR ");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await SharedReferenceResolver.ReconcileAsync(_mockContext, trackedTags, [incomingTag], Errors.Metadata.TagNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Same(storedTag, Assert.Single(trackedTags));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReconcileAsync_WhenANewNameIsRepeatedWithDifferentCasingAndWhitespace_ShouldAddASingleInstance()
|
||||
{
|
||||
// Arrange
|
||||
List<TagEntity> trackedTags = [];
|
||||
TagEntity firstTag = _tagEntityFixture.Create(name: " Horror ");
|
||||
TagEntity secondTag = _tagEntityFixture.Create(name: "HORROR");
|
||||
TagEntity thirdTag = _tagEntityFixture.Create(name: "horror");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await SharedReferenceResolver.ReconcileAsync(_mockContext, trackedTags, [firstTag, secondTag, thirdTag], Errors.Metadata.TagNameCannotBeEmpty, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Same(firstTag, Assert.Single(trackedTags));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResolveAsync_WhenThereAreNoIncomingEntities_ShouldReturnAnEmptyDictionary()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user