Esempio n. 1
0
        public void When_treating_a_value_type_as_a_complex_type_it_should_compare_them_by_members()
        {
            // Arrange
            var subject = new ClassWithValueSemanticsOnSingleProperty {
                Key = "SameKey", NestedProperty = "SomeValue"
            };

            var expected = new ClassWithValueSemanticsOnSingleProperty {
                Key = "SameKey", NestedProperty = "OtherValue"
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected,
                                                               options => options.ComparingByMembers <ClassWithValueSemanticsOnSingleProperty>());

            // Assert
            act.Should().Throw <XunitException>().WithMessage("*NestedProperty*OtherValue*SomeValue*");
        }
Esempio n. 2
0
        public void When_treating_a_type_as_reference_type_but_it_was_already_marked_as_value_type_it_should_throw()
        {
            // Arrange
            var subject = new ClassWithValueSemanticsOnSingleProperty {
                Key = "Don't care"
            };

            var expected = new ClassWithValueSemanticsOnSingleProperty {
                Key = "Don't care"
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected, options => options
                                                               .ComparingByValue <ClassWithValueSemanticsOnSingleProperty>()
                                                               .ComparingByMembers <ClassWithValueSemanticsOnSingleProperty>());

            // Assert
            act.Should().Throw <InvalidOperationException>().WithMessage(
                $"*compare {nameof(ClassWithValueSemanticsOnSingleProperty)}*members*already*value*");
        }
Esempio n. 3
0
 protected bool Equals(ClassWithValueSemanticsOnSingleProperty other)
 {
     return(Key == other.Key);
 }