Skip to content

Commit

Permalink
[up] to NUnit 4 with respective refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed Feb 18, 2025
1 parent afc1ecd commit cfdeebb
Show file tree
Hide file tree
Showing 51 changed files with 716 additions and 760 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.*" />
<PackageReference Include="NUnit" Version="3.13.*" />
<PackageReference Include="NUnit" Version="4.3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void SetUp()
}

#endregion SetUp

[Test]
public void MapTo_CorrectDestinationAndSourceExpressions_MappedCorrectly()
{
Expand All @@ -34,8 +33,8 @@ public void MapTo_CorrectDestinationAndSourceExpressions_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Type, source.Category);
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Type, Is.EqualTo(source.Category));
}

[Test]
Expand All @@ -47,11 +46,11 @@ public void MapTo_CorrectDestinationAndSourceExpressions_ValidMappingCreated()

// Act & Assert

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, s => s.Category)
.MapTo(d => d.Source, s => s)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
Assert.DoesNotThrow(() => cfg.CreateMapper());
.MapTo(d => d.Source, s => s)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);
Assert.That(() => cfg.CreateMapper(), Throws.Nothing);
}

[Test]
Expand All @@ -65,8 +64,8 @@ public void MapTo_CorrectDestinationExpressionAndSourcePath_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Type, source.Category);
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Type, Is.EqualTo(source.Category));
}

[Test]
Expand All @@ -78,11 +77,11 @@ public void MapTo_CorrectDestinationExpressionAndSourcePath_ValidMappingCreated(

// Act & Assert

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, "Category")
.MapTo(d => d.Source, s => s)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
Assert.DoesNotThrow(() => cfg.CreateMapper());
.MapTo(d => d.Source, s => s)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);
Assert.That(() => cfg.CreateMapper(), Throws.Nothing);
}

[Test]
Expand All @@ -94,14 +93,14 @@ public void MapTo_NullDestinationMemberExpression_ThrowsAutoMapperConfigurationE

// Act & Assert

Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationExpression!, s => s.Category)));
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationExpression!, s => s.Category)), Throws.TypeOf<AutoMapperConfigurationException>());

Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationExpression!, "Category")));
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationExpression!, "Category")), Throws.TypeOf<AutoMapperConfigurationException>());

Assert.Throws<ArgumentException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => null, s => s.Category)));
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => null, s => s.Category)), Throws.TypeOf<ArgumentException>());
}

[Test]
Expand All @@ -113,19 +112,19 @@ public void MapTo_NullOrEmptyDestinationMemberName_ThrowsAutoMapperConfiguration

// Act & Assert

Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationName!, s => s.Category)));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("", s => s.Category)));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(" ", s => s.Category)));

Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationName!, "Category")));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("", "Category")));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(" ", "Category")));
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationName!, s => s.Category)), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("", s => s.Category)), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(" ", s => s.Category)), Throws.TypeOf<AutoMapperConfigurationException>());

Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(nullDestinationName!, "Category")), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("", "Category")), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(" ", "Category")), Throws.TypeOf<AutoMapperConfigurationException>());
}

[Test]
Expand All @@ -137,19 +136,19 @@ public void MapTo_NullOrEmptySourceMemberPath_ThrowsAutoMapperConfigurationExcep

// Act & Assert

Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, nullSourcePath!)));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, "")));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, " ")));

Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", nullSourcePath!)));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", "")));
Assert.Throws<AutoMapperConfigurationException>(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", " ")));
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, nullSourcePath!)), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, "")), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, " ")), Throws.TypeOf<AutoMapperConfigurationException>());

Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", nullSourcePath!)), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", "")), Throws.TypeOf<AutoMapperConfigurationException>());
Assert.That(() => new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", " ")), Throws.TypeOf<AutoMapperConfigurationException>());
}

[Test]
Expand All @@ -165,8 +164,8 @@ public void MapTo_NullSourceMemberExpression_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Source, source.ToString());
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Source, Is.EqualTo(source.ToString()));

// Arrange

Expand All @@ -176,8 +175,8 @@ public void MapTo_NullSourceMemberExpression_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Source, source.ToString());
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Source, Is.EqualTo(source.ToString()));
}

[Test]
Expand All @@ -190,15 +189,15 @@ public void MapTo_NullSourceMemberExpression_ValidMappingCreated()

// Act & Assert

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, nullSourceExpression)
.MapTo(d => d.Source, nullSourceExpression)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.MapTo(d => d.Source, nullSourceExpression)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", nullSourceExpression)
.MapTo(d => d.Source, nullSourceExpression)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.MapTo(d => d.Source, nullSourceExpression)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);
}

[Test]
Expand All @@ -212,8 +211,8 @@ public void MapTo_NullValueSourceMemberExpression_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Type, null);
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Type, Is.Null);

// Arrange

Expand All @@ -223,8 +222,8 @@ public void MapTo_NullValueSourceMemberExpression_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Type, null);
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Type, Is.Null);
}

[Test]
Expand All @@ -236,15 +235,15 @@ public void MapTo_NullValueSourceMemberExpression_ValidMappingCreated()

// Act & Assert

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type, s => null)
.MapTo(d => d.Source, s => null)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.MapTo(d => d.Source, s => null)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type", s => null)
.MapTo("Source", s => null)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.MapTo("Source", s => null)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);
}

[Test]
Expand All @@ -258,8 +257,8 @@ public void MapTo_WithoutSourceMemberExpression_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Source, source.ToString());
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Source, Is.EqualTo(source.ToString()));

// Arrange

Expand All @@ -269,8 +268,8 @@ public void MapTo_WithoutSourceMemberExpression_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Source, source.ToString());
Assert.That(dto = mapper.Map<FoodDto>(source), Is.Not.Null);
Assert.That(dto.Source, Is.EqualTo(source.ToString()));
}

[Test]
Expand All @@ -282,14 +281,14 @@ public void MapTo_WithoutSourceMemberExpression_ValidMappingCreated()

// Act & Assert

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo(d => d.Type)
.MapTo(d => d.Source)));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.MapTo(d => d.Source)), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, FoodDto>()
.MapTo("Type")
.MapTo("Source")));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.MapTo("Source")), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class ProfileExpressionExtensionsTests
{
#region SetUp

private readonly FoodSource source = new() { Category = "Fruit", Name = "Apple", Count = 5 };
private FoodDto? dto;
private IFoodDto? dtoBase;
private readonly FoodSource _source = new() { Category = "Fruit", Name = "Apple", Count = 5 };
private FoodDto? _dto;
private IFoodDto? _dtoBase;

[SetUp]
public void SetUp()
{
dtoBase = null;
dto = null;
_dtoBase = null;
_dto = null;
}

#endregion SetUp
Expand All @@ -32,10 +32,10 @@ public void CreateMap_WithDestinationBaseType_ValidMappingCreated()

// Act & Assert

Assert.DoesNotThrow(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, IFoodDto, FoodDto>()
Assert.That(() => cfg = new MapperConfiguration(c => c.CreateMap<FoodSource, IFoodDto, FoodDto>()
.ForMember(d => d.Type, o => o.MapFrom(s => s.Category))
.ForMember(d => d.Source, o => o.Ignore())));
Assert.DoesNotThrow(() => cfg.AssertConfigurationIsValid());
.ForMember(d => d.Source, o => o.Ignore())), Throws.Nothing);
Assert.That(() => cfg.AssertConfigurationIsValid(), Throws.Nothing);
}

[Test]
Expand All @@ -49,10 +49,10 @@ public void MapToType_ToDestinationBaseType_MappedCorrectly()

// Act & Assert

Assert.NotNull(dtoBase = mapper.Map<IFoodDto>(source));
Assert.AreEqual(dtoBase.Type, source.Category);
Assert.AreEqual(dtoBase.Name, source.Name);
Assert.AreEqual(dtoBase.Count, source.Count);
Assert.That(_dtoBase = mapper.Map<IFoodDto>(_source), Is.Not.Null);
Assert.That(_dtoBase.Type, Is.EqualTo(_source.Category));
Assert.That(_dtoBase.Name, Is.EqualTo(_source.Name));
Assert.That(_dtoBase.Count, Is.EqualTo(_source.Count));
}

[Test]
Expand All @@ -66,9 +66,9 @@ public void MapToType_ToDestinationType_MappedCorrectly()

// Act & Assert

Assert.NotNull(dto = mapper.Map<FoodDto>(source));
Assert.AreEqual(dto.Type, source.Category);
Assert.AreEqual(dto.Name, source.Name);
Assert.AreEqual(dto.Count, source.Count);
Assert.That(_dto = mapper.Map<FoodDto>(_source), Is.Not.Null);
Assert.That(_dto.Type, Is.EqualTo(_source.Category));
Assert.That(_dto.Name, Is.EqualTo(_source.Name));
Assert.That(_dto.Count, Is.EqualTo(_source.Count));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.*" />
<PackageReference Include="NUnit" Version="3.13.*" />
<PackageReference Include="NUnit" Version="4.3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.*" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Simplify.Bus.Impl.Tests/BusAsync2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task Send_SingleRequestHandler_ExecutedOnceWithCorrectParameterAndR
// Assert

handler.Verify(x => x.Handle(It.Is<TestRequest>(r => r == request)), Times.Once);
Assert.AreEqual(response, result);
Assert.That(result, Is.EqualTo(response));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/Simplify.Bus.Impl.Tests/Simplify.Bus.Impl.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.*" />
<PackageReference Include="Moq" Version="4.20.*" />
<PackageReference Include="NUnit" Version="3.13.*" />
<PackageReference Include="NUnit" Version="4.3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.*" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.*" />
<PackageReference Include="NUnit" Version="3.13.*" />
<PackageReference Include="NUnit" Version="4.3.*" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.*" />
<PackageReference Include="FluentValidation" Version="11.4.*" />
<PackageReference Include="Simplify.DI.Provider.SimpleInjector" Version="1.11.*" />
Expand Down
Loading

0 comments on commit cfdeebb

Please sign in to comment.