Skip to content

Commit 598bb2c

Browse files
committed
Refactor
1 parent 1b2de5e commit 598bb2c

File tree

4 files changed

+31
-64
lines changed

4 files changed

+31
-64
lines changed

Testing/Advanced/Advanced.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -7,16 +7,16 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="ApprovalTests" Version="6.0.0" />
11-
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
10+
<PackageReference Include="ApprovalTests" Version="7.0.0" />
11+
<PackageReference Include="BenchmarkDotNet" Version="0.15.4" />
1212
<PackageReference Include="FakeItEasy" Version="8.3.0" />
13-
<PackageReference Include="FluentAssertions" Version="6.12.0" />
14-
<PackageReference Include="log4net" Version="2.0.17" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
16-
<PackageReference Include="NUnit" Version="4.1.0" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
18-
<PackageReference Include="Selenium.WebDriver" Version="4.22.0" />
19-
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="131.0.6778.8700" />
13+
<PackageReference Include="FluentAssertions" Version="8.8.0" />
14+
<PackageReference Include="log4net" Version="3.2.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
16+
<PackageReference Include="NUnit" Version="4.4.0" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
18+
<PackageReference Include="Selenium.WebDriver" Version="4.38.0" />
19+
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="142.0.7444.5900" />
2020
</ItemGroup>
2121

2222
</Project>

Testing/Basic/Basic.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -7,16 +7,16 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="coverlet.collector" Version="6.0.2">
10+
<PackageReference Include="coverlet.collector" Version="6.0.4">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="FluentAssertions" Version="6.12.0" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
16-
<PackageReference Include="NUnit" Version="4.1.0" />
17-
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
18-
<PackageReference Include="xunit" Version="2.8.1" />
19-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
14+
<PackageReference Include="FluentAssertions" Version="8.8.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
16+
<PackageReference Include="NUnit" Version="4.4.0" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
18+
<PackageReference Include="xunit" Version="2.9.3" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
2020
<PrivateAssets>all</PrivateAssets>
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
</PackageReference>

Testing/Basic/Homework/1. ObjectComparison/ObjectComparison.cs

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public class ObjectComparison
1212
private static Person tsarCopyDifferent = new Person("Ivan IV The Kind", 54, 170, 70, new Person("Vasili III of Russia", 28, 170, 60, null));
1313

1414
private static Person person0Parents = new Person("1", 1, 1, 1, null);
15-
private static Person person0ParentsCopy = Person.Copy(person0Parents);
15+
private static Person person0ParentsCopy = person0Parents.Copy()!;
1616
private static Person person0ParentsLimits = new Person(string.Empty, int.MaxValue, int.MinValue, 0, null);
17-
private static Person person0ParentsLimitsCopy = Person.Copy(person0ParentsLimits);
17+
private static Person person0ParentsLimitsCopy = person0ParentsLimits.Copy()!;
1818
private static Person person1Parents = new Person("1", 1, 1, 1, new Person("2", 2, 2, 2, null));
19-
private static Person person1ParentsСopy = Person.Copy(person1Parents);
19+
private static Person person1ParentsСopy = person1Parents.Copy()!;
2020
private static Person person1ParentsDifferent = new Person("1", 1, 1, 1, new Person("3", 3, 3, 3, null));
2121
private static Person person2Parents = new Person("1", 1, 1, 1, new Person("2", 2, 2, 2, new Person("3", 3, 3, 3, null)));
22-
private static Person person2ParentsCopy = Person.Copy(person2Parents);
22+
private static Person person2ParentsCopy = person2Parents.Copy()!;
2323
private static Person person2ParentsDifferent = new Person("1", 1, 1, 1, new Person("2", 2, 2, 2, new Person("5", 5, 5, 5, null)));
2424
#endregion
2525

@@ -81,27 +81,7 @@ public void AreEqual_NotThrows_OnEqualPersons(Person? actual, Person? expected)
8181
actual.Should().BeEquivalentTo(expected, options =>
8282
options
8383
.Excluding(t => t.Id)
84-
.Using<Person>(ctx =>
85-
{
86-
AreEqual_NotThrows_OnEqualFields(ctx.Subject, ctx.Expectation);
87-
if (ctx.Subject != null && ctx.Expectation != null)
88-
{
89-
if (ctx.Subject.Parent != null && ctx.Expectation.Parent != null)
90-
{
91-
AreEqual_NotThrows_OnEqualPersons(ctx.Subject.Parent, ctx.Expectation.Parent);
92-
}
93-
else
94-
{
95-
ctx.Subject.Parent.Should().BeEquivalentTo(ctx.Expectation.Parent, options =>
96-
options
97-
.Excluding(t => t.Id)
98-
.Excluding(t => t.Parent)
99-
);
100-
}
101-
}
102-
}
103-
)
104-
.WhenTypeIs<Person>()
84+
.Excluding(t => t.Path.EndsWith("Id"))
10585
);
10686
}
10787

@@ -122,27 +102,11 @@ public void AreEqual_Throw_OnDifferentPersons(Person? actual, Person? expected)
122102
actual.Should().NotBeEquivalentTo(expected, options =>
123103
options
124104
.Excluding(t => t.Id)
125-
.Using<Person>(ctx =>
126-
{
127-
AreEqual_NotThrows_OnEqualFields(ctx.Subject, ctx.Expectation);
128-
if (ctx.Subject != null && ctx.Expectation != null)
129-
{
130-
if (ctx.Subject.Parent != null && ctx.Expectation.Parent != null)
131-
{
132-
AreEqual_NotThrows_OnEqualPersons(ctx.Subject.Parent, ctx.Expectation.Parent);
133-
}
134-
else
135-
{
136-
(ctx.Subject.Parent == null && ctx.Expectation.Parent == null).Should().BeTrue();
137-
}
138-
}
139-
}
140-
)
141-
.WhenTypeIs<Person>()
105+
.Excluding(t => t.Path.EndsWith("Id"))
142106
);
143107
}
144108

145-
//Как будто бы если оставлять обобщенный метод кода становится меньше
109+
// А что так можно было что ли?
146110

147111
// При добавлении новых полей в Person придется расширять условие в return еще больше;
148112
// Тест должен пройти по всем Parent прежде чем дать результат,

Testing/Basic/Homework/1. ObjectComparison/Person.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ public class Person
66
public static int IdCounter = 0;
77
public int Age, Height, Weight;
88
public string Name;
9-
public Person Parent;
9+
public Person? Parent;
1010
public int Id;
1111

12-
public Person(string name, int age, int height, int weight, Person parent)
12+
public Person(string name, int age, int height, int weight, Person? parent)
1313
{
1414
Id = IdCounter++;
1515
Name = name;
@@ -18,13 +18,16 @@ public Person(string name, int age, int height, int weight, Person parent)
1818
Weight = weight;
1919
Parent = parent;
2020
}
21+
22+
public Person? Copy() => Copy(this)!;
2123

2224
public static Person? Copy(Person? source)
2325
{
2426
if (source is null)
2527
{
2628
return null;
2729
}
28-
return new Person(source.Name, source.Age, source.Height, source.Weight, Person.Copy(source.Parent));
30+
return new Person(source.Name, source.Age, source.Height, source.Weight, Person.Copy(source.Parent!)!);
2931
}
32+
3033
}

0 commit comments

Comments
 (0)