예제 #1
0
            public void Select_should_equal_Select()
            {
                IEnumerable <int> items  = IntGenerator.Range(1, 12);
                IEnumerable <int> others = IntGenerator.Range(1, 12);

                Assert.Equal(items, others);
            }
예제 #2
0
            public void Int32Int64Comparison()
            {
                long l64 = 0;
                int  i32 = 0;

                Assert.Equal <long>(l64, i32);
            }
예제 #3
0
            public void UInt64EqualsFails()
            {
                UInt64 expected = 25;
                UInt64 actual   = 42;

                Assert.Throws <EqualException>(() => Assert.Equal(expected, actual));
            }
예제 #4
0
            public void DecimalEqualsFails()
            {
                decimal expected = 25;
                decimal actual   = 42;

                Assert.Throws <EqualException>(() => Assert.Equal(expected, actual));
            }
예제 #5
0
        public void IsNotTypeThrowsExceptionWhenWrongType()
        {
            AssertException exception =
                Assert.Throws <IsNotTypeException>(() => Assert.IsNotType <InvalidCastException>(new InvalidCastException()));

            Assert.Equal("Assert.IsNotType() Failure", exception.UserMessage);
        }
예제 #6
0
            public void DoubleEqualsFails()
            {
                double expected = 25.3;
                double actual   = 42.0;

                Assert.Throws <EqualException>(() => Assert.Equal(expected, actual));
            }
예제 #7
0
            public void NullableValueTypesCanBeNull()
            {
                DateTime?dt1 = null;
                DateTime?dt2 = null;

                Assert.Equal(dt1, dt2);
            }
예제 #8
0
            public void String()
            {
                string s1 = "test";
                string s2 = new StringBuilder(s1).ToString();

                Assert.True(s1.Equals(s2));
                Assert.Equal(s2, s1);
            }
예제 #9
0
            public void NullValuesInArraysCreateCorrectExceptionMessage()
            {
                Exception ex = Record.Exception(
                    () => Assert.Equal(new [] { null, "hello" }, new [] { null, "world" }));

                Assert.IsType <EqualException>(ex);
                Assert.Equal("Assert.Equal() Failure\r\nPosition: First difference is at position 1\r\nExpected: System.String[] { (null), hello }\r\nActual:   System.String[] { (null), world }", ex.Message);
            }
예제 #10
0
            public void ArrayValuesAreDifferentNotEqual()
            {
                string[] expected = { "@", "d", "v", "d" };
                string[] actual   = { "@", "a", "ab", "b" };

                Assert.Throws <EqualException>(() => Assert.Equal(expected, actual));
                Assert.NotEqual(expected, actual);
            }
예제 #11
0
            public void ArraysOfDifferentLengthsAreNotEqual()
            {
                string[] expected = { "@", "a", "ab", "b", "c" };
                string[] actual   = { "@", "a", "ab", "b" };

                Assert.Throws <EqualException>(() => Assert.Equal(expected, actual));
                Assert.NotEqual(expected, actual);
            }
예제 #12
0
            public void When_comparing_base_Generic_IComparable_object_Should_equate()
            {
                EquatableObject        baseObj    = new EquatableObject();
                DerivedEquatableObject derivedObj = new DerivedEquatableObject();

                Assert.Equal(derivedObj, baseObj);
                Assert.True(baseObj.Equals__Called);
            }
예제 #13
0
            public void When_comparing_object_with_default_equality_behavior_to_derived_class_Should_fail()
            {
                var obj        = new DefaultEqualityObject();
                var derivedObj = new DerivedDefaultEqualityObject();
                var ex         = Record.Exception(() => Assert.Equal(obj, derivedObj));

                Assert.IsType <EqualException>(ex);
            }
예제 #14
0
            public void Array()
            {
                string[] expected = { "@", "a", "ab", "b" };
                string[] actual   = { "@", "a", "ab", "b" };

                Assert.Equal(expected, actual);
                Assert.Throws <NotEqualException>(() => Assert.NotEqual(expected, actual));
            }
예제 #15
0
            public void SingleWithSingleItemCollectionReturnsTheItem()
            {
                string[] collection = new[] { "Hello" };

                string result = Assert.Single(collection);

                Assert.Equal("Hello", result);
            }
예제 #16
0
        public void TraceAssertFailureWithFullDetails()
        {
            TraceAssertException ex = Assert.Throws <TraceAssertException>(() => Trace.Assert(false, "message", "detailed message"));

            Assert.Equal("message", ex.AssertMessage);
            Assert.Equal("detailed message", ex.AssertDetailedMessage);
            Assert.Equal("Debug.Assert() Failure : message" + Environment.NewLine + "Detailed Message:" + Environment.NewLine + "detailed message", ex.Message);
        }
예제 #17
0
        public void TraceAssertFailureWithNoMessage()
        {
            TraceAssertException ex = Assert.Throws <TraceAssertException>(() => Trace.Assert(false));

            Assert.Equal("", ex.AssertMessage);
            Assert.Equal("", ex.AssertDetailedMessage);
            Assert.Equal("Debug.Assert() Failure", ex.Message);
        }
예제 #18
0
        public void ItemNotInContainer()
        {
            List <int> list = new List <int>();

            ContainsException ex = Assert.Throws <ContainsException>(() => Assert.Contains(42, list));

            Assert.Equal("Assert.Contains() failure: Not found: 42", ex.Message);
        }
예제 #19
0
        public void IsAssignableFromThrowsExceptionWhenWrongType()
        {
            AssertException exception =
                Assert.Throws <IsAssignableFromException>(
                    () => Assert.IsAssignableFrom <InvalidCastException>(new InvalidOperationException()));

            Assert.Equal("Assert.IsAssignableFrom() Failure", exception.UserMessage);
        }
예제 #20
0
            public void When_copmaring_derived_IEquitable_object_Should_equate()
            {
                EquatableObject        baseObj    = new EquatableObject();
                DerivedEquatableObject derivedObj = new DerivedEquatableObject();

                Assert.Equal(baseObj, derivedObj);
                Assert.True(baseObj.Equals__Called);
            }
예제 #21
0
        public void ContainerIsEmpty()
        {
            List <int> list = new List <int>();

            NotEmptyException ex =
                Assert.Throws <NotEmptyException>(() => Assert.NotEmpty(list));

            Assert.Equal("Assert.NotEmpty() failure", ex.Message);
        }
예제 #22
0
            public void SingleWithMultiItemCollectionThrows()
            {
                string[] collection = new[] { "Hello", "World!" };

                Exception ex = Record.Exception(() => Assert.Single(collection));

                Assert.IsType <SingleException>(ex);
                Assert.Equal("The collection contained 2 elements instead of 1.", ex.Message);
            }
예제 #23
0
            public void SingleWithEmptyCollectionThrows()
            {
                object[] collection = new object[0];

                Exception ex = Record.Exception(() => Assert.Single(collection));

                Assert.IsType <SingleException>(ex);
                Assert.Equal("The collection contained 0 elements instead of 1.", ex.Message);
            }
        public void PreservesExpectedAndActual()
        {
            AssertActualExpectedException ex =
                new AssertActualExpectedException(2, 1, null);

            Assert.Equal("1", ex.Actual);
            Assert.Equal("2", ex.Expected);
            Assert.Null(ex.UserMessage);
        }
예제 #25
0
        public void NotEqualWithCustomComparer()
        {
            string expected = "TestString";
            string actual   = "testString";

            Assert.False(actual == expected);
            Assert.Equal(expected, actual, StringComparer.CurrentCultureIgnoreCase);
            Assert.NotEqual(expected, actual, StringComparer.CurrentCulture);
        }
예제 #26
0
            public void EqualsString()
            {
                string testString = "Test String";
                string expected   = testString;
                string actual     = testString;

                Assert.True(actual == expected);
                Assert.Equal(expected, actual);
            }
예제 #27
0
            public void SingleWithSingleItemCollectionReturnsTheItem()
            {
                ArrayList collection = new ArrayList {
                    "Hello"
                };

                object result = Assert.Single(collection);

                Assert.Equal("Hello", result);
            }
예제 #28
0
            public void IsNotEmpty()
            {
                List <int> list = new List <int>();

                list.Add(42);

                EmptyException ex = Assert.Throws <EmptyException>(() => Assert.Empty(list));

                Assert.Equal("Assert.Empty() failure", ex.Message);
            }
예제 #29
0
            public void EqualsUInt64()
            {
                ulong  valueType      = 35;
                UInt64 referenceValue = 35;

                Assert.True(valueType == referenceValue);
                Assert.Equal(referenceValue, valueType);
                Assert.Equal <ulong>(valueType, 35);
                Assert.Equal <ulong>(referenceValue, 35);
            }
예제 #30
0
            public void When_comparing_object_with_overriden_equality_behavior_to_derived_object_Should_use_overriden_behavior()
            {
                var obj        = new CustomEqualityObject();
                var derivedObj = new DerivedCustomEqualityObject();

                Assert.Equal(obj, derivedObj);

                Assert.True(obj.EqualsCalled);
                Assert.Equal(obj.EqualsCalledOn, derivedObj);
            }