Skip to content

Commit

Permalink
Merge pull request #1881 from ITaluone/code-style-fixes
Browse files Browse the repository at this point in the history
Code style fixes
  • Loading branch information
jnyrup committed Apr 7, 2022
2 parents b456f5b + a2fd3eb commit d6ad279
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 47 deletions.
Expand Up @@ -40,7 +40,7 @@ public IMember Match(IMember expectedMember, object subject, INode parent, IEqui
{
path = path.WithCollectionAsRoot();
}

if (path.IsEquivalentTo(expectedMember.PathAndName))
{
var member = MemberFactory.Find(subject, subjectPath.MemberName, expectedMember.Type, parent);
Expand Down
Expand Up @@ -13,8 +13,7 @@ internal class MultiDimensionalArrayEquivalencyStep : IEquivalencyStep
{
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
{
Array expectationAsArray = comparands.Expectation as Array;
if (expectationAsArray is null || expectationAsArray?.Rank == 1)
if (comparands.Expectation is not Array expectationAsArray || expectationAsArray?.Rank == 1)
{
return EquivalencyResult.ContinueWithNext;
}
Expand Down
Expand Up @@ -811,7 +811,7 @@ private void RemoveSelectionRule<T>()
{
selectionRules.RemoveAll(selectionRule => selectionRule is T);
}

protected TSelf AddSelectionRule(IMemberSelectionRule selectionRule)
{
selectionRules.Add(selectionRule);
Expand Down
Expand Up @@ -11,9 +11,8 @@ public class DataSetEquivalencyStep : EquivalencyStep<DataSet>
protected override EquivalencyResult OnHandle(Comparands comparands, IEquivalencyValidationContext context, IEquivalencyValidator nestedValidator)
{
var subject = comparands.Subject as DataSet;
var expectation = comparands.Expectation as DataSet;

if (expectation is null)
if (comparands.Expectation is not DataSet expectation)
{
if (subject is not null)
{
Expand Down
37 changes: 19 additions & 18 deletions Tests/Benchmarks/UsersOfGetClosedGenericInterfaces.cs
Expand Up @@ -24,14 +24,13 @@ public class UsersOfGetClosedGenericInterfaces
private GenericEnumerableEquivalencyStep enumerableStep;

private IEquivalencyValidationContext context;
private IEquivalencyAssertionOptions config;

private class Context : IEquivalencyValidationContext
{
public INode CurrentNode { get; }
public Reason Reason { get; }
public Tracer Tracer { get; }
public IEquivalencyAssertionOptions Options { get; }
public IEquivalencyAssertionOptions Options { get; internal set; }
public bool IsCyclicReference(object expectation) => throw new NotImplementedException();

public IEquivalencyValidationContext AsNestedMember(IMember expectationMember) => throw new NotImplementedException();
Expand Down Expand Up @@ -148,25 +147,27 @@ public void GlobalSetup()
break;

default:
{
if (DataType == typeof(TimeSpan))
values[i] = faker.Date.Future() - faker.Date.Future();
else if (DataType == typeof(Guid))
values[i] = faker.Random.Guid();
else if (DataType == typeof(Dictionary<int, int>))
values[i] = new Dictionary<int, int>() { { faker.Random.Int(), faker.Random.Int() } };
else if (DataType == typeof(IEnumerable<int>))
values[i] = new int[] { faker.Random.Int(), faker.Random.Int() };
else
throw new Exception("Unable to populate data of type " + DataType);

break;
}
{
if (DataType == typeof(TimeSpan))
values[i] = faker.Date.Future() - faker.Date.Future();
else if (DataType == typeof(Guid))
values[i] = faker.Random.Guid();
else if (DataType == typeof(Dictionary<int, int>))
values[i] = new Dictionary<int, int>() { { faker.Random.Int(), faker.Random.Int() } };
else if (DataType == typeof(IEnumerable<int>))
values[i] = new int[] { faker.Random.Int(), faker.Random.Int() };
else
throw new Exception("Unable to populate data of type " + DataType);

break;
}
}
}

context = new Context();
config = new Config();
context = new Context()
{
Options = new Config()
};
}

[Benchmark]
Expand Down
34 changes: 22 additions & 12 deletions Tests/FluentAssertions.Equivalency.Specs/CollectionSpecs.cs
Expand Up @@ -350,12 +350,14 @@ public void

var logbookEntry = new LogbookEntryProjection
{
Logbook = logbook, LogbookRelations = new[] { new LogbookRelation { Logbook = logbook } }
Logbook = logbook,
LogbookRelations = new[] { new LogbookRelation { Logbook = logbook } }
};

var equivalentLogbookEntry = new LogbookEntryProjection
{
Logbook = logbook, LogbookRelations = new[] { new LogbookRelation { Logbook = logbook } }
Logbook = logbook,
LogbookRelations = new[] { new LogbookRelation { Logbook = logbook } }
};

// Act
Expand Down Expand Up @@ -748,7 +750,9 @@ public void When_all_subject_items_are_equivalent_to_expectation_object_it_shoul
// Act
Action action = () => subject.Should().AllBeEquivalentTo(new
{
Name = "someDto", Age = 1, Birthdate = default(DateTime)
Name = "someDto",
Age = 1,
Birthdate = default(DateTime)
});

// Assert
Expand All @@ -768,9 +772,11 @@ public void When_all_subject_items_are_equivalent_to_expectation_object_it_shoul

// Act
Action action = () => subject.Should().AllBeEquivalentTo(new
{
Name = "someDto", Age = 1, Birthdate = default(DateTime)
})
{
Name = "someDto",
Age = 1,
Birthdate = default(DateTime)
})
.And.HaveCount(3);

// Assert
Expand Down Expand Up @@ -1108,12 +1114,14 @@ public void When_nested_objects_are_excluded_from_collections_it_should_use_simp
// Arrange
var actual = new MyObject
{
MyString = "identical string", Child = new ClassIdentifiedById { Id = 1, MyChildString = "identical string" }
MyString = "identical string",
Child = new ClassIdentifiedById { Id = 1, MyChildString = "identical string" }
};

var expectation = new MyObject
{
MyString = "identical string", Child = new ClassIdentifiedById { Id = 1, MyChildString = "DIFFERENT STRING" }
MyString = "identical string",
Child = new ClassIdentifiedById { Id = 1, MyChildString = "DIFFERENT STRING" }
};

IList<MyObject> actualList = new List<MyObject> { actual };
Expand Down Expand Up @@ -1478,7 +1486,7 @@ public void When_the_length_of_the_first_dimension_differs_between_the_arrays_it
public void When_the_number_of_dimensions_of_the_arrays_are_not_the_same_it_should_throw()
{
// Arrange
var actual = new[,,]
var actual = new[, ,]
{
{
{ 1 },
Expand Down Expand Up @@ -1721,7 +1729,9 @@ public void
// Act
Action act = () => result.Should().BeEquivalentTo(new Dictionary<string, int?>
{
["A"] = 0, ["B"] = 0, ["C"] = null
["A"] = 0,
["B"] = 0,
["C"] = null
});

// Assert
Expand Down Expand Up @@ -2114,8 +2124,8 @@ public static IEnumerable<object[]> ArrayTestData()
};

return from x in arrays
from y in arrays
select new object[] { x, y };
from y in arrays
select new object[] { x, y };
}

[Fact]
Expand Down
Expand Up @@ -440,7 +440,7 @@ public void Exclusion_of_missing_members_works_with_mapping()

var expectation = new
{
Property2 = 2,
Property2 = 2,
Ignore = 3
};

Expand All @@ -463,7 +463,7 @@ public void Mapping_works_with_exclusion_of_missing_members()

var expectation = new
{
Property2 = 2,
Property2 = 2,
Ignore = 3
};

Expand All @@ -484,13 +484,13 @@ public void Can_map_members_of_a_root_collection()
EntityId = 1,
Name = "Test"
};

var dto = new EntityDto
{
Id = 1,
Name = "Test"
};

var entityCol = new[] { entity };
var dtoCol = new[] { dto };

Expand Down
15 changes: 10 additions & 5 deletions Tests/FluentAssertions.Equivalency.Specs/NestedPropertiesSpecs.cs
Expand Up @@ -13,12 +13,14 @@ public void When_all_the_properties_of_the_nested_objects_are_equal_it_should_su
// Arrange
var subject = new Root
{
Text = "Root", Level = new Level1 { Text = "Level1", Level = new Level2 { Text = "Level2" } }
Text = "Root",
Level = new Level1 { Text = "Level1", Level = new Level2 { Text = "Level2" } }
};

var expected = new RootDto
{
Text = "Root", Level = new Level1Dto { Text = "Level1", Level = new Level2Dto { Text = "Level2" } }
Text = "Root",
Level = new Level1Dto { Text = "Level1", Level = new Level2Dto { Text = "Level2" } }
};

// Act
Expand Down Expand Up @@ -53,15 +55,17 @@ public void
{
Property = new ClassWithValueSemanticsOnSingleProperty
{
Key = "123", NestedProperty = "Should be ignored"
Key = "123",
NestedProperty = "Should be ignored"
}
};

var expected = new
{
Property = new ClassWithValueSemanticsOnSingleProperty
{
Key = "123", NestedProperty = "Should be ignored as well"
Key = "123",
NestedProperty = "Should be ignored as well"
}
};

Expand Down Expand Up @@ -249,7 +253,8 @@ public void When_deeply_nested_properties_do_not_have_all_equal_values_it_should
// Arrange
var root = new Root
{
Text = "Root", Level = new Level1 { Text = "Level1", Level = new Level2 { Text = "Level2" } }
Text = "Root",
Level = new Level1 { Text = "Level1", Level = new Level2 { Text = "Level2" } }
};

var rootDto = new RootDto
Expand Down
Expand Up @@ -4,6 +4,9 @@

namespace FluentAssertions.Specs.Collections
{
/// <summary>
/// This part contains tests that address AllSatisfy
/// </summary>
public partial class GenericCollectionAssertionOfStringSpecs
{
public class AllSatisfy
Expand Down
Expand Up @@ -9,6 +9,9 @@

namespace FluentAssertions.Specs.Collections
{
/// <summary>
/// This part of the class contains assertions of general generic string collections
/// </summary>
public partial class GenericCollectionAssertionOfStringSpecs
{
[Fact]
Expand Down
4 changes: 2 additions & 2 deletions Tests/UWP.Specs/Properties/AssemblyInfo.cs
Expand Up @@ -10,8 +10,8 @@
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyMetadata("TargetPlatform","UAP")]
[assembly: AssemblyMetadata("TargetPlatform", "UAP")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
[assembly: ComVisible(false)]

0 comments on commit d6ad279

Please sign in to comment.