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_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 Execute(IEnumerable <string> messages, string expectation, string reason, params object[] reasonArgs) { using (new AssertionScope()) { var results = new AssertionResultSet(); foreach (string message in messages) { using (var scope = new AssertionScope()) { scope.AddNonReportable("context", Context); message.Should().MatchEquivalentOf(string.Format(Pattern, expectation), reason, reasonArgs); results.AddSet(message, scope.Discard()); } if (results.ContainsSuccessfulSet) { break; } } foreach (string failure in results.SelectClosestMatchFor()) { AssertionScope.Current.FailWith(failure); } } }
public void Execute(IEnumerable <string> messages, string expectation, string because, params object[] becauseArgs) { using (new AssertionScope()) { var results = new AssertionResultSet(); foreach (string message in messages) { using (var scope = new AssertionScope()) { scope.AddNonReportable("context", Context); message.Should().MatchEquivalentOf(expectation, because, becauseArgs); results.AddSet(message, scope.Discard()); } if (results.ContainsSuccessfulSet) { break; } } foreach (string failure in results.SelectClosestMatchFor()) { AssertionScope.Current.FailWith(failure.Replace("{", "{{").Replace("}", "}}")); } } }
public void AssertEquality(EquivalencyValidationContext context) { using (var scope = new AssertionScope()) { scope.AddReportable("configuration", config.ToString()); scope.AddNonReportable("objects", new ObjectTracker(config.CyclicReferenceHandling)); scope.BecauseOf(context.Because, context.BecauseArgs); AssertEqualityUsing(context); } }
public void AssertEquality(EquivalencyValidationContext context) { using (var scope = new AssertionScope()) { scope.AddReportable("configuration", config.ToString()); scope.AddNonReportable("objects", new ObjectTracker(config.CyclicReferenceHandling)); scope.BecauseOf(context.Reason, context.ReasonArgs); AssertEqualityUsing(context); } }
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 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 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."); } } } }
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 Message_should_have_named_placeholder_be_replaced_by_nonreportable_value() { // Arrange var scope = new AssertionScope(); scope.AddNonReportable("SomeKey", "SomeValue"); AssertionScope.Current.FailWith("{SomeKey}"); // Act Action act = scope.Dispose; // Assert act.Should().ThrowExactly <XunitException>() .WithMessage("SomeValue"); }
public void Message_should_not_have_nonreportable_values_appended_at_the_end() { // Arrange var scope = new AssertionScope(); scope.AddNonReportable("SomeKey", "SomeValue"); AssertionScope.Current.FailWith("{SomeKey}"); // Act Action act = scope.Dispose; // Assert act.Should().ThrowExactly <XunitException>() .Which.Message.Should().NotContain("With SomeKey:\nSomeValue"); }
public void When_adding_non_reportable_value_it_should_not_be_reported_after_the_message() { // Arrange var scope = new AssertionScope(); scope.AddNonReportable("SomeKey", "SomeValue"); AssertionScope.Current.FailWith("{SomeKey}"); // Act Action act = scope.Dispose; // Assert act.Should().ThrowExactly <XunitException>() .Which.Message.Should().NotContain("With SomeKey:\nSomeValue"); }