A unit test generation extension for Visual Studio that aims to always produce code that compiles - covering the basic cases automatically and preparing as much as it can for the complex cases.
Get the extension from the Visual Studio Marketplace:
Alternatively see the releases on GitHub:
Demonstrates how properties that have matching constructor parameters are checked that they are initialized automatically
public class ExampleClass
{
public ExampleClass(int identity, string description, Guid uniqueCode)
{
Identity = identity;
Description = description;
UniqueCode = uniqueCode;
}
public int Identity { get; }
public string Description { get; }
public Guid UniqueCode { get; }
}
public class ExampleClassTests
{
private readonly ExampleClass _testClass;
private int _identity;
private string _description;
private Guid _uniqueCode;
public ExampleClassTests()
{
_identity = 534011718;
_description = "TestValue237820880";
_uniqueCode = new Guid("97408286-a3e4-cf95-ff46-699c73c4a1cd");
_testClass = new ExampleClass(_identity, _description, _uniqueCode);
}
[Fact]
public void CanConstruct()
{
// Act
var instance = new ExampleClass(_identity, _description, _uniqueCode);
// Assert
instance.Should().NotBeNull();
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void CannotConstructWithInvalidDescription(string value)
{
FluentActions.Invoking(() => new ExampleClass(_identity, value, _uniqueCode)).Should().Throw<ArgumentNullException>().WithParameterName("description");
}
[Fact]
public void IdentityIsInitializedCorrectly()
{
_testClass.Identity.Should().Be(_identity);
}
[Fact]
public void DescriptionIsInitializedCorrectly()
{
_testClass.Description.Should().Be(_description);
}
[Fact]
public void UniqueCodeIsInitializedCorrectly()
{
_testClass.UniqueCode.Should().Be(_uniqueCode);
}
}