Skip to content

Commit 73d0fdf

Browse files
committed
feat: migrate unit tests to use Shouldly assertions and clean up global usings
1 parent c1eb01e commit 73d0fdf

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
global using System.Net;
2-
global using Xunit;
3-
global using FluentAssertions;
4-
global using Microsoft.AspNetCore.Http;
5-
global using Newtonsoft.Json;
6-
global using Shouldly;
1+
global using Shouldly;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
global using Xunit;
2-
global using FluentAssertions;
32
global using Shouldly;

Chapter-4-applying-tactical-domain-driven-design/Fitnet.Common/Fitnet.Common.Core.UnitTests/ValueObjectTests.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace EvolutionaryArchitecture.Fitnet.Common.Core.UnitTests;
22

3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
37
public class ValueObjectTests
48
{
59
private const int DefaultIntProperty = 1;
@@ -13,10 +17,10 @@ internal void Given_two_same_type_objects_When_values_are_the_same_Then_should_b
1317
var secondObject = new FakeValueObject();
1418

1519
// Act & Assert
16-
firstObject.Should().Be(secondObject);
17-
firstObject.Equals(secondObject).Should().BeTrue();
18-
(firstObject == secondObject).Should().BeTrue();
19-
(firstObject != secondObject).Should().BeFalse();
20+
firstObject.ShouldBe(secondObject);
21+
firstObject.Equals(secondObject).ShouldBeTrue();
22+
(firstObject == secondObject).ShouldBeTrue();
23+
(firstObject != secondObject).ShouldBeFalse();
2024
}
2125

2226
[Fact]
@@ -28,14 +32,14 @@ internal void Given_two_same_type_objects_When_values_are_not_the_same_Then_shou
2832
var thirdObject = new FakeValueObject(property2: Guid.NewGuid().ToString());
2933

3034
// Act & Assert
31-
firstObject.Should().NotBe(secondObject);
32-
firstObject.Equals(secondObject).Should().BeFalse();
33-
(firstObject == secondObject).Should().BeFalse();
34-
(firstObject != secondObject).Should().BeTrue();
35-
firstObject.Should().NotBe(thirdObject);
36-
firstObject.Equals(thirdObject).Should().BeFalse();
37-
(firstObject == thirdObject).Should().BeFalse();
38-
(firstObject != thirdObject).Should().BeTrue();
35+
firstObject.ShouldNotBe(secondObject);
36+
firstObject.Equals(secondObject).ShouldBeFalse();
37+
(firstObject == secondObject).ShouldBeFalse();
38+
(firstObject != secondObject).ShouldBeTrue();
39+
firstObject.ShouldNotBe(thirdObject);
40+
firstObject.Equals(thirdObject).ShouldBeFalse();
41+
(firstObject == thirdObject).ShouldBeFalse();
42+
(firstObject != thirdObject).ShouldBeTrue();
3943
}
4044

4145
[Fact]
@@ -46,7 +50,7 @@ internal void Given_two_same_type_objects_When_values_are_the_same_Then_should_h
4650
var secondObject = new FakeValueObject();
4751

4852
// Act & Assert
49-
firstObject.GetHashCode().Should().Be(secondObject.GetHashCode());
53+
firstObject.GetHashCode().ShouldBe(secondObject.GetHashCode());
5054
}
5155

5256
[Fact]
@@ -57,10 +61,10 @@ internal void Given_two_different_type_objects_When_values_are_the_same_Then_sho
5761
var secondObject = new AnotherTypeFakeValueObject();
5862

5963
// Act & Assert
60-
firstObject.Should().NotBe(secondObject);
61-
firstObject.Equals(secondObject).Should().BeFalse();
62-
(firstObject == secondObject).Should().BeFalse();
63-
(firstObject != secondObject).Should().BeTrue();
64+
// firstObject.ShouldNotBe(secondObject);
65+
firstObject.Equals(secondObject).ShouldBeFalse();
66+
(firstObject == secondObject).ShouldBeFalse();
67+
(firstObject != secondObject).ShouldBeTrue();
6468
}
6569

6670
[Fact]
@@ -80,8 +84,8 @@ internal void Given_multiple_objects_When_looking_for_specific_one_Then_should_r
8084
var result = valueObjects.Where(vo => vo == targetValueObject).ToList();
8185

8286
// Assert
83-
result.Should().HaveCount(2);
84-
result.Should().AllBeEquivalentTo(targetValueObject);
87+
result.Count.ShouldBe(2);
88+
result.ForEach(vo => vo.ShouldBe(targetValueObject));
8589
}
8690

8791
[Fact]
@@ -101,7 +105,7 @@ internal void Given_multiple_objects_When_looking_for_non_existing_one_Then_shou
101105
var result = valueObjects.Where(vo => vo == targetValueObject).ToList();
102106

103107
// Assert
104-
result.Should().BeEmpty();
108+
result.ShouldBeEmpty();
105109
}
106110

107111
private class FakeValueObject(int property1 = DefaultIntProperty, string property2 = DefaultStringProperty) : ValueObject
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
global using System.Reflection;
22
global using JetBrains.Annotations;
3-
global using Xunit;
43
global using Microsoft.AspNetCore.Mvc.Testing;
54
global using Microsoft.AspNetCore.Hosting;
65
global using Microsoft.Extensions.Configuration;

0 commit comments

Comments
 (0)