public void AssertEqualityUsing(EquivalencyValidationContext context) { if (ContinueRecursion(context.PropertyPath)) { AssertionScope scope = AssertionScope.Current; scope.AddNonReportable("context", context.IsRoot ? "subject" : context.PropertyDescription); scope.AddNonReportable("subject", context.Subject); scope.AddNonReportable("expectation", context.Expectation); var objectTracker = scope.Get <ObjectTracker>("objects"); if (!objectTracker.IsCyclicReference(new ObjectReference(context.Subject, context.PropertyPath))) { bool wasHandled = false; foreach (var strategy in steps.Where(s => s.CanHandle(context, config))) { if (strategy.Handle(context, this, config)) { wasHandled = true; break; } } if (!wasHandled) { Execute.Assertion.FailWith( "No IEquivalencyStep was found to handle the context. " + "This is likely a bug in Fluent Assertions."); } } } }
public void AssertEqualityUsing(IEquivalencyValidationContext context) { if (ContinueRecursion(context.SelectedMemberPath)) { AssertionScope scope = AssertionScope.Current; scope.AddNonReportable("context", (context.SelectedMemberDescription.Length == 0) ? "subject" : context.SelectedMemberDescription); scope.AddNonReportable("subject", context.Subject); scope.AddNonReportable("expectation", context.Expectation); var objectTracker = scope.Get <ObjectTracker>("objects"); if (!objectTracker.IsCyclicReference(new ObjectReference(context.Subject, context.SelectedMemberPath))) { bool wasHandled = AssertionOptions.EquivalencySteps .Where(s => s.CanHandle(context, config)) .Any(step => step.Handle(context, this, config)); if (!wasHandled) { Execute.Assertion.FailWith( "No IEquivalencyStep was found to handle the context. " + "This is likely a bug in Fluent Assertions."); } } } }
public void Get_default_value_when_key_is_not_present() { // Arrange var scope = new AssertionScope(); // Act var value = scope.Get <int>("SomeKey"); // Assert value.Should().Be(0); }
public void Value_should_be_of_requested_type() { // Arrange var scope = new AssertionScope(); scope.AddNonReportable("SomeKey", "SomeValue"); // Act var value = scope.Get <string>("SomeKey"); // Assert value.Should().BeOfType <string>(); }
public void When_adding_non_reportable_value_it_should_be_retrievable_from_context() { // Arrange var scope = new AssertionScope(); scope.AddNonReportable("SomeKey", "SomeValue"); // Act var value = scope.Get <string>("SomeKey"); // Assert value.Should().Be("SomeValue"); }
public void Get_value_when_key_is_present() { // Arrange var scope = new AssertionScope(); scope.AddNonReportable("SomeKey", "SomeValue"); scope.AddNonReportable("SomeOtherKey", "SomeOtherValue"); // Act var value = scope.Get <string>("SomeKey"); // Assert value.Should().Be("SomeValue"); }
public void Get_default_value_when_nullable_value_is_null() { // Arrange var scope = new AssertionScope(); #pragma warning disable IDE0004 // Remove Unnecessary Cast scope.AddNonReportable("SomeKey", (int?)null); #pragma warning restore IDE0004 // Remove Unnecessary Cast // Act var value = scope.Get <int>("SomeKey"); // Assert value.Should().Be(0); }
public void AssertEqualityUsing(EquivalencyValidationContext context) { AssertionScope scope = AssertionScope.Current; scope.AddNonReportable("context", context.IsRoot ? "subject" : context.PropertyDescription); scope.AddNonReportable("subject", context.Subject); scope.AddNonReportable("expectation", context.Expectation); var objectTracker = scope.Get <ObjectTracker>("objects"); if (!objectTracker.IsCyclicReference(new ObjectReference(context.Subject, context.PropertyPath))) { foreach (IEquivalencyStep strategy in steps.Where(s => s.CanHandle(context, config))) { if (strategy.Handle(context, this, config)) { break; } } } }
public void AssertEqualityUsing(IEquivalencyValidationContext context) { if (ContinueRecursion(context.SelectedMemberPath)) { AssertionScope scope = AssertionScope.Current; scope.Context = (context.SelectedMemberDescription.Length == 0) ? scope.Context : context.SelectedMemberDescription; scope.AddNonReportable("subject", context.Subject); scope.AddNonReportable("expectation", context.Expectation); var objectTracker = scope.Get <CyclicReferenceDetector>("objects"); bool isComplexType = IsComplexType(context.Expectation); var objectReference = new ObjectReference(context.Expectation, context.SelectedMemberPath, isComplexType); if (!objectTracker.IsCyclicReference(objectReference)) { bool wasHandled = false; foreach (var step in AssertionOptions.EquivalencySteps) { if (step.CanHandle(context, config)) { if (step.Handle(context, this, config)) { wasHandled = true; break; } } } if (!wasHandled) { Execute.Assertion.FailWith( "No IEquivalencyStep was found to handle the context. " + "This is likely a bug in Fluent Assertions."); } } } }