public void SubstringTests() { string phrase = "Hello World!"; string[] array = new string[] { "abc", "bad", "dba" }; // Classic Syntax StringAssert.Contains("World", phrase); // Constraint Syntax Assert.That(phrase, Does.Contain("World")); // Only available using new syntax Assert.That(phrase, Does.Not.Contain("goodbye")); Assert.That(phrase, Does.Contain("WORLD").IgnoreCase); Assert.That(phrase, Does.Not.Contain("BYE").IgnoreCase); Assert.That(array, Is.All.Contains("b")); // Inherited syntax Expect(phrase, Contains("World")); // Only available using new syntax Expect(phrase, Not.Contains("goodbye")); Expect(phrase, Contains("WORLD").IgnoreCase); Expect(phrase, Not.Contains("BYE").IgnoreCase); Expect(array, All.Contains("b")); }
public void SubstringTests() { string phrase = "Hello World!"; string[] array = new string[] { "abc", "bad", "dba" }; // Classic Syntax EnsureBase <Ensure> .Strings.Contains("World", phrase); // Helper syntax Ensure.That(phrase, Text.Contains("World")); // Only available using new syntax Ensure.That(phrase, Text.DoesNotContain("goodbye")); Ensure.That(phrase, Text.Contains("WORLD").IgnoreCase); Ensure.That(phrase, Text.DoesNotContain("BYE").IgnoreCase); Ensure.That(array, Text.All.Contains("b")); // Inherited syntax EnsuranceHelper.Expect(phrase, Contains("World")); // Only available using new syntax EnsuranceHelper.Expect(phrase, Not.Contains("goodbye")); EnsuranceHelper.Expect(phrase, Contains("WORLD").IgnoreCase); EnsuranceHelper.Expect(phrase, Not.Contains("BYE").IgnoreCase); EnsuranceHelper.Expect(array, All.Contains("b")); }
public void InheritedContains() { int[] iarray = new int[] { 1, 2, 3 }; string[] sarray = new string[] { "a", "b", "c" }; // Inherited syntax Expect(iarray, Contains(3)); Expect(sarray, Contains("b")); Expect(sarray, Not.Contains("x")); }
public void Remove_Always_RemovesLastForm() { var forms = Create(); forms.Forms = GetForms(3); var last = forms.Forms.Last(); forms.Remove(); Expect(forms.Forms, Not.Contains(last)); Expect(forms.Forms, Count.EqualTo(2)); }
public void CollectionContainsTests() { int[] iarray = new int[] { 1, 2, 3 }; string[] sarray = new string[] { "a", "b", "c" }; // Classic syntax Assert.Contains(3, iarray); Assert.Contains("b", sarray); CollectionAssert.Contains(iarray, 3); CollectionAssert.Contains(sarray, "b"); CollectionAssert.DoesNotContain(sarray, "x"); // Showing that Contains uses object equality CollectionAssert.DoesNotContain(iarray, 1.0d); // Helper syntax Assert.That(iarray, Has.Member(3)); Assert.That(sarray, Has.Member("b")); Assert.That(sarray, Has.No.Member("x")); // Showing that Contains uses object equality Assert.That(iarray, Has.No.Member(1.0d)); // Only available using the new syntax // Note that EqualTo and SameAs do NOT give // identical results to Contains because // Contains uses Object.Equals() Assert.That(iarray, Has.Some.EqualTo(3)); Assert.That(iarray, Has.Member(3)); Assert.That(sarray, Has.Some.EqualTo("b")); Assert.That(sarray, Has.None.EqualTo("x")); Assert.That(iarray, Has.None.SameAs(1.0d)); Assert.That(iarray, Has.All.LessThan(10)); Assert.That(sarray, Has.All.Length(1)); Assert.That(sarray, Has.None.Property("Length").GreaterThan(3)); // Inherited syntax Expect(iarray, Contains(3)); Expect(sarray, Contains("b")); Expect(sarray, Not.Contains("x")); // Only available using new syntax // Note that EqualTo and SameAs do NOT give // identical results to Contains because // Contains uses Object.Equals() Expect(iarray, Some.EqualTo(3)); Expect(sarray, Some.EqualTo("b")); Expect(sarray, None.EqualTo("x")); Expect(iarray, All.LessThan(10)); Expect(sarray, All.Length(1)); Expect(sarray, None.Property("Length").GreaterThan(3)); }
public void ToString_Credentials_Unreadable() { // Arrange var credentials = new Credentials(); credentials.User = "******"; credentials.Password = "******"; // Act string data = credentials.ToString(); // Assert Expect(data, Not.Contains(credentials.User)); Expect(data, Not.Contains(credentials.Password)); }
public void CollectionContainsTests() { int[] iarray = new int[] { 1, 2, 3 }; string[] sarray = new string[] { "a", "b", "c" }; // Classic syntax Assert.Contains(3, iarray); Assert.Contains("b", sarray); CollectionAssert.Contains(iarray, 3); CollectionAssert.Contains(sarray, "b"); CollectionAssert.DoesNotContain(sarray, "x"); // Helper syntax Assert.That(iarray, List.Contains(3)); Assert.That(sarray, List.Contains("b")); Assert.That(sarray, List.Not.Contains("x")); // Inherited syntax Expect(iarray, Contains(3)); Expect(sarray, Contains("b")); Expect(sarray, Not.Contains("x")); }