Skip to content

1.3.0: Nested Types #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ All notable changes to Fluentify will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.3.0] - 2024-12-03

## Added

- Support for Fluentify on nested classes and records (#3).

## Fixed

Expand Down
5 changes: 3 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
Expand All @@ -13,8 +13,9 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.11.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.3.0.106239" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="System.Formats.Asn1" Version="9.0.0" />
<PackageVersion Include="Valuify" Version="1.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
Expand Down
2 changes: 1 addition & 1 deletion build/Tests.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
<ExcludeByAttribute>Obsolete</ExcludeByAttribute>
<ExcludeByFile>**/*.Designer.cs</ExcludeByFile>
<NoWarn>CA1859;CA1861</NoWarn>
<NoWarn>CA1859;CA1861;xUnit1044;xUnit1045;</NoWarn>
<RootNamespace>$(MSBuildProjectName.Replace('.Tests', ''))</RootNamespace>
<TargetFrameworks>net9.0</TargetFrameworks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Fluentify.Console.Class.NestedInClassTests;

public sealed class WhenWithAgeIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInClass.Simple? subject = default;

// Act
Func<NestedInClass.Simple> act = () => subject!.WithAge(1);

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Theory]
[InlineData(1)]
[InlineData(-1)]
[InlineData(0)]
[InlineData(int.MinValue)]
[InlineData(int.MaxValue)]
public void GivenAnAgeThenTheValueIsApplied(int age)
{
// Arrange
var original = new NestedInClass.Simple
{
Age = Random.Shared.Next(),
Attributes = [new(), new()],
Name = "Avery Brooks",
};

// Act
NestedInClass.Simple actual = original.WithAge(age);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(age);
_ = actual.Attributes.Should().BeEquivalentTo(original.Attributes);
_ = actual.Name.Should().BeEquivalentTo(original.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Fluentify.Console.Class.NestedInClassTests;

public sealed class WhenWithAttributesIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInClass.Simple? subject = default;

// Act
Func<NestedInClass.Simple> act = () => subject!.WithAttributes(new object());

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Fact]
public void GivenAttributesThenTheValueIsApplied()
{
// Arrange
object[] attributes = [new()];

var original = new NestedInClass.Simple
{
Age = Random.Shared.Next(),
Attributes = [],
Name = "Avery Brooks",
};

// Act
NestedInClass.Simple actual = original.WithAttributes(attributes);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(original.Age);
_ = actual.Attributes.Should().BeEquivalentTo(attributes);
_ = actual.Name.Should().Be(original.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Fluentify.Console.Class.NestedInClassTests;

public sealed class WhenWithNameIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInClass.Simple? subject = default;

// Act
Func<NestedInClass.Simple> act = () => subject!.WithName("Avery Brooks");

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Theory]
[InlineData("Avery Brooks")]
[InlineData("")]
[InlineData(" ")]
public void GivenANameThenTheValueIsApplied(string name)
{
// Arrange
var original = new NestedInClass.Simple
{
Age = Random.Shared.Next(),
Attributes = [new(), new()],
Name = "Patrick Stewart",
};

// Act
NestedInClass.Simple actual = original.WithName(name);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(original.Age);
_ = actual.Attributes.Should().BeEquivalentTo(original.Attributes);
_ = actual.Name.Should().BeEquivalentTo(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Fluentify.Console.Class.NestedInInterfaceTests;

public sealed class WhenWithAgeIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInInterface.Simple? subject = default;

// Act
Func<NestedInInterface.Simple> act = () => subject!.WithAge(1);

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Theory]
[InlineData(1)]
[InlineData(-1)]
[InlineData(0)]
[InlineData(int.MinValue)]
[InlineData(int.MaxValue)]
public void GivenAnAgeThenTheValueIsApplied(int age)
{
// Arrange
var original = new NestedInInterface.Simple
{
Age = Random.Shared.Next(),
Attributes = [new(), new()],
Name = "Avery Brooks",
};

// Act
NestedInInterface.Simple actual = original.WithAge(age);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(age);
_ = actual.Attributes.Should().BeEquivalentTo(original.Attributes);
_ = actual.Name.Should().BeEquivalentTo(original.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Fluentify.Console.Class.NestedInInterfaceTests;

public sealed class WhenWithAttributesIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInInterface.Simple? subject = default;

// Act
Func<NestedInInterface.Simple> act = () => subject!.WithAttributes(new object());

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Fact]
public void GivenAttributesThenTheValueIsApplied()
{
// Arrange
object[] attributes = [new()];

var original = new NestedInInterface.Simple
{
Age = Random.Shared.Next(),
Attributes = [],
Name = "Avery Brooks",
};

// Act
NestedInInterface.Simple actual = original.WithAttributes(attributes);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(original.Age);
_ = actual.Attributes.Should().BeEquivalentTo(attributes);
_ = actual.Name.Should().Be(original.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Fluentify.Console.Class.NestedInInterfaceTests;

public sealed class WhenWithNameIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInInterface.Simple? subject = default;

// Act
Func<NestedInInterface.Simple> act = () => subject!.WithName("Avery Brooks");

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Theory]
[InlineData("Avery Brooks")]
[InlineData("")]
[InlineData(" ")]
public void GivenANameThenTheValueIsApplied(string name)
{
// Arrange
var original = new NestedInInterface.Simple
{
Age = Random.Shared.Next(),
Attributes = [new(), new()],
Name = "Patrick Stewart",
};

// Act
NestedInInterface.Simple actual = original.WithName(name);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(original.Age);
_ = actual.Attributes.Should().BeEquivalentTo(original.Attributes);
_ = actual.Name.Should().BeEquivalentTo(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Fluentify.Console.Class.NestedInReadOnlyStructTests;

public sealed class WhenWithAgeIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInReadOnlyStruct.Simple? subject = default;

// Act
Func<NestedInReadOnlyStruct.Simple> act = () => subject!.WithAge(1);

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Theory]
[InlineData(1)]
[InlineData(-1)]
[InlineData(0)]
[InlineData(int.MinValue)]
[InlineData(int.MaxValue)]
public void GivenAnAgeThenTheValueIsApplied(int age)
{
// Arrange
var original = new NestedInReadOnlyStruct.Simple
{
Age = Random.Shared.Next(),
Attributes = [new(), new()],
Name = "Avery Brooks",
};

// Act
NestedInReadOnlyStruct.Simple actual = original.WithAge(age);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(age);
_ = actual.Attributes.Should().BeEquivalentTo(original.Attributes);
_ = actual.Name.Should().BeEquivalentTo(original.Name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Fluentify.Console.Class.NestedInReadOnlyStructTests;

public sealed class WhenWithAttributesIsCalled
{
[Fact]
public void GivenNullSubjectThenArgumentNullExceptionIsThrown()
{
// Arrange
NestedInReadOnlyStruct.Simple? subject = default;

// Act
Func<NestedInReadOnlyStruct.Simple> act = () => subject!.WithAttributes(new object());

// Assert
_ = act.Should().Throw<ArgumentNullException>()
.WithParameterName(nameof(subject));
}

[Fact]
public void GivenAttributesThenTheValueIsApplied()
{
// Arrange
object[] attributes = [new()];

var original = new NestedInReadOnlyStruct.Simple
{
Age = Random.Shared.Next(),
Attributes = [],
Name = "Avery Brooks",
};

// Act
NestedInReadOnlyStruct.Simple actual = original.WithAttributes(attributes);

// Assert
_ = actual.Should().NotBeSameAs(original);
_ = actual.Age.Should().Be(original.Age);
_ = actual.Attributes.Should().BeEquivalentTo(attributes);
_ = actual.Name.Should().Be(original.Name);
}
}
Loading