Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void NullsAllowedInContainer()
        {
            List <object> list = new List <object> {
                null, 16, "Hi there"
            };

            Assert.Contains("Hi there", list);
        }
Ejemplo n.º 3
0
        public void ItemInContainer()
        {
            List <int> list = new List <int> {
                42
            };

            Assert.Contains(42, list);
        }
Ejemplo n.º 4
0
        public void CanUseComparer()
        {
            List <int> list = new List <int> {
                42
            };

            Assert.Contains(43, list, new MyComparer());
        }
Ejemplo n.º 5
0
        public void CanFindNullInContainer()
        {
            List <object> list = new List <object> {
                16, null, "Hi there"
            };

            Assert.Contains(null, list);
        }
Ejemplo n.º 6
0
            public void StackTraceForThrowsIsOriginalThrowNotAssertThrows()
            {
                var wasFilterStackTraceAssemblyPrefix = AssertException.FilterStackTraceAssemblyPrefix;

                AssertException.FilterStackTraceAssemblyPrefix = "Should.Core";
                Assert.ThrowsDelegate throwsDelegate = ThrowingMethod;
                try
                {
                    Assert.Throws <InvalidCastException>(throwsDelegate);
                }
                catch (AssertActualExpectedException exception)
                {
                    Assert.Contains(GetMethodFullName(throwsDelegate), exception.StackTrace);
                    Assert.DoesNotContain("Should.Core", exception.StackTrace);
                }
                finally
                {
                    AssertException.FilterStackTraceAssemblyPrefix = wasFilterStackTraceAssemblyPrefix;
                }
            }
Ejemplo n.º 7
0
            public void StackTraceForThrowsIsOriginalThrowNotAssertThrows()
            {
                var wasFilterStackTraceAssemblyPrefix = AssertException.FilterStackTraceAssemblyPrefix;

                AssertException.FilterStackTraceAssemblyPrefix = "Should.Core";
                StubAccessor accessor = new StubAccessor();

                Assert.ThrowsDelegateWithReturn throwsDelegateWithReturn = () => accessor.FailingProperty;
                try
                {
                    Assert.Throws <InvalidCastException>(throwsDelegateWithReturn);
                }
                catch (AssertActualExpectedException exception)
                {
                    Assert.Contains(GetMethodFullName(throwsDelegateWithReturn), exception.StackTrace);
                    Assert.DoesNotContain("Should.Core", exception.StackTrace);
                }
                finally
                {
                    AssertException.FilterStackTraceAssemblyPrefix = wasFilterStackTraceAssemblyPrefix;
                }
            }
Ejemplo n.º 8
0
 public void SubstringNotFound()
 {
     Assert.Throws <ContainsException>(() => Assert.Contains("hey", "Hello, world!"));
 }
Ejemplo n.º 9
0
 public void SubstringContainsIsCaseSensitiveByDefault()
 {
     Assert.Throws <ContainsException>(() => Assert.Contains("WORLD", "Hello, world!"));
 }
Ejemplo n.º 10
0
 public void CanSearchForSubstringsCaseInsensitive()
 {
     Assert.Contains("WORLD", "Hello, world!", StringComparison.InvariantCultureIgnoreCase);
 }
Ejemplo n.º 11
0
 public void CanSearchForSubstrings()
 {
     Assert.Contains("wor", "Hello, world!");
 }