public void StringChecks() { var valueToTest = "Abc Def Xyz Bin"; // Constraint-style asserts: Assert.That("", Is.Empty); Assert.That(valueToTest, Is.Not.Empty); Assert.That(valueToTest, Does.Contain("Def")); Assert.That(valueToTest, Does.Not.Contain("Bang")); Assert.That(valueToTest, Does.StartWith("Abc")); Assert.That(valueToTest, Does.Not.StartWith("Def")); Assert.That(valueToTest, Does.EndWith("Bin")); Assert.That(valueToTest, Does.Not.EndWith("Xyz")); Assert.That(valueToTest, Is.EqualTo("abc def xyz bin").IgnoreCase); Assert.That(valueToTest, Is.Not.EqualTo("something else").IgnoreCase); Assert.That(valueToTest, Does.Match("^Abc.*Bin$")); Assert.That(valueToTest, Does.Not.Match("^Abc.*Def$")); // Classic-style asserts: StringAssert.Contains("Def", valueToTest); StringAssert.DoesNotContain("Bang", valueToTest); StringAssert.StartsWith("Abc", valueToTest); StringAssert.DoesNotStartWith("Def", valueToTest); StringAssert.EndsWith("Bin", valueToTest); StringAssert.DoesNotEndWith("Xyz", valueToTest); StringAssert.AreEqualIgnoringCase("abc def xyz bin", valueToTest); StringAssert.AreNotEqualIgnoringCase("something else", valueToTest); StringAssert.IsMatch("^Abc.*Bin$", valueToTest); //first param is a regex pattern StringAssert.DoesNotMatch("^Abc.*Def$", valueToTest); //first param is a regex pattern }
public void VirtualDirOnlyMakesRouteWithNoWildcardPrefix() { //Arrange var portalInfo = new ArrayList { new PortalInfo { PortalID = 0 } }; _mockPortalController.Setup(x => x.GetPortals()).Returns(portalInfo); var mockPac = new Mock <IPortalAliasController>(); mockPac.Setup(x => x.GetPortalAliasByPortalId(0)).Returns(new[] { new PortalAliasInfo { HTTPAlias = "www.foo.com/vdir" } }); TestablePortalAliasController.SetTestableInstance(mockPac.Object); var mockGlobals = new Mock <IGlobals>(); mockGlobals.Setup(x => x.ApplicationPath).Returns("/vdir"); TestableGlobals.SetTestableInstance(mockGlobals.Object); var routeCollection = new RouteCollection(); var srm = new ServicesRoutingManager(routeCollection); //Act srm.MapRoute("folder", "url", new[] { "foo" }); //Assert Assert.AreEqual(1, routeCollection.Count); var route = (Route)routeCollection[0]; StringAssert.DoesNotStartWith("{", route.Url); }
public void TestConfiguration() { ChromeOptions options = new ChromeOptions(); options.AddArgument("--headless"); IWebDriver driver = new ChromeDriver(options); Eyes eyes = new Eyes(); try { Configuration conf = new Configuration(); conf.SetServerUrl("https://testeyes.applitools.com").SetApiKey("HSNghRv9zMtkhcmwj99injSggnd2a8zUY390OiyNRWoQ110"); eyes.Open(driver, "test configuration", "test server url 1", new Size(800, 600)); TestResults results1 = eyes.Close(); eyes.SetConfiguration(conf); eyes.Open(driver, "test configuration", "test server url 2", new Size(800, 600)); TestResults results2 = eyes.Close(); StringAssert.DoesNotStartWith("https://testeyesapi.applitools.com", results1.ApiUrls.Session); StringAssert.StartsWith("https://testeyesapi.applitools.com", results2.ApiUrls.Session); } finally { driver.Quit(); } }
public void StringChecks() { var valueToTest = "Foo Bar Baz Bin"; // Constraint-style asserts: Assert.That("", Is.Empty); Assert.That(valueToTest, Is.Not.Empty); Assert.That(valueToTest, Does.Contain("Bar")); Assert.That(valueToTest, Does.Not.Contain("Bang")); Assert.That(valueToTest, Does.StartWith("Foo")); Assert.That(valueToTest, Does.Not.StartWith("Bar")); Assert.That(valueToTest, Does.EndWith("Bin")); Assert.That(valueToTest, Does.Not.EndWith("Baz")); Assert.That(valueToTest, Is.EqualTo("foo bar baz bin").IgnoreCase); Assert.That(valueToTest, Is.Not.EqualTo("something else").IgnoreCase); Assert.That(valueToTest, Does.Match("^Foo.*Bin$")); // param is a regex pattern Assert.That(valueToTest, Does.Not.Match("^Foo.*Bar$")); // param is a regex pattern // Classic-style asserts: StringAssert.Contains("Bar", valueToTest); StringAssert.DoesNotContain("Bang", valueToTest); StringAssert.StartsWith("Foo", valueToTest); StringAssert.DoesNotStartWith("Bar", valueToTest); StringAssert.EndsWith("Bin", valueToTest); StringAssert.DoesNotEndWith("Baz", valueToTest); StringAssert.AreEqualIgnoringCase("foo bar baz bin", valueToTest); StringAssert.AreNotEqualIgnoringCase("something else", valueToTest); StringAssert.IsMatch("^Foo.*Bin$", valueToTest); //first param is a regex pattern StringAssert.DoesNotMatch("^Foo.*Bar$", valueToTest); //first param is a regex pattern }
public void CDToTildeShouldNotChangeIntoTildeDirectory() { var rootPath = base.SetupFileSystemWithStructure(new[] { "/~/x" }); var currentLocation = ("Set-Location " + rootPath + "; Set-Location ~; (Get-Location).Path").Exec(); StringAssert.DoesNotStartWith(rootPath, currentLocation); }
public void StringStartsWith() { // You can test starting substrings. var text = "four score and seven years ago"; StringAssert.StartsWith("four", text); StringAssert.DoesNotStartWith("five", text); }
public void GetsWordsString() { var words = WordGenerator.GetRandomWordString(10); Assert.IsNotNull(words); Assert.Greater(words.Length, 24); StringAssert.DoesNotStartWith(" ", words); StringAssert.DoesNotEndWith(" ", words); }
public void StartsWith_Test() { string actual = "dcc"; string expected = "d"; StringAssert.StartsWith(expected, actual); expected = "c"; StringAssert.DoesNotStartWith(expected, actual); }
public void stringNotStartWith_Test() { var testor = new TestorTheBarbarian(); //Nunit Classic Model StringAssert.DoesNotStartWith("Bug", testor.Name); //NUnit Constraint model Assert.That(testor.Name, Is.Not.StringStarting("Bug")); //shouldly syntax testor.Name.ShouldNotStartWith("Bug"); }
public void TestFinished_AdditionalReportAttributes() { var work = TestBuilder.CreateWorkItem(typeof(FixtureWithTestFixtureAttribute), "SomeTest"); work.Context.Listener = _reporter; TestBuilder.ExecuteWorkItem(work); var endReport = _listener.Reports.LastOrDefault(); Assert.NotNull(endReport); StringAssert.DoesNotStartWith("<start", endReport); StringAssert.Contains($"parentId=\"{work.Test.Parent?.Id}\"", endReport); }
public void ResolveRelativePathNotAffectedByCurrentDirectory() { string currentDirectory = Directory.GetCurrentDirectory(); try { string tempDirectory = Path.GetTempPath(); Directory.SetCurrentDirectory(tempDirectory); string resolvedPath = PathHelper.ResolvePath(_basePath, "RepoDir"); StringAssert.DoesNotStartWith(tempDirectory, resolvedPath); } finally { Directory.SetCurrentDirectory(currentDirectory); } }
public void testStrings() { string actual = "ABCDEFG"; StringAssert.Contains("BCD", actual); StringAssert.DoesNotContain("DCB", actual); StringAssert.StartsWith("ABC", actual); StringAssert.DoesNotStartWith("BCD", actual); StringAssert.EndsWith("FG", actual); StringAssert.DoesNotEndWith("BCD", actual); StringAssert.AreEqualIgnoringCase("abcdefg", actual); StringAssert.AreNotEqualIgnoringCase("aaaaaaa", actual); StringAssert.IsMatch("A.+", actual); StringAssert.DoesNotMatch("K", actual); }
public void StringAssertsTest() { string s = "The best way to explain it is to do it"; StringAssert.Contains("explain", s, "No match found"); StringAssert.DoesNotContain("Alice", s); StringAssert.StartsWith("The", s, "No {0} found in {1}", new string[2] { "this", "that" }); StringAssert.DoesNotStartWith("An", s); StringAssert.EndsWith("do it", s, "Incorrect ending"); StringAssert.DoesNotEndWith("do that", s); string x = "ThE bEst WaY to eXplaiN iT iS tO dO iT"; StringAssert.AreEqualIgnoringCase(x, s, "No match found"); }
public void StringAssertsTest() { StringAssert.Contains("world", "Hello world!"); StringAssert.DoesNotContain("word", "Hello world!"); StringAssert.StartsWith("Hello", "Hello world!"); StringAssert.DoesNotStartWith("Hell0", "Hello world!"); StringAssert.EndsWith("world!", "Hello world!"); StringAssert.DoesNotEndWith("world?", "Hello world!"); StringAssert.AreEqualIgnoringCase("Hello world!", "hello WORLD!"); StringAssert.AreNotEqualIgnoringCase("Hello world!", "hello WORD!"); StringAssert.IsMatch(@"\w*\s\w*", "Hello world!"); StringAssert.DoesNotMatch(@"\w\s\s\w", "Hello world!"); }
public void TestKeyValueParse() { // Given string[] pairs = { "key=value", "k=v", "except=bro", "awesome====123123", " keytrimmed = value trimmed " }; // When IReadOnlyDictionary <string, object> args = MetadataParser.Parse(pairs); // Then Assert.AreEqual(pairs.Length, args.Count); foreach (KeyValuePair <string, object> arg in args) { Assert.NotNull(arg.Value, "Argument value should not be null."); StringAssert.DoesNotStartWith(" ", arg.Key, "Arguments key should be trimmed."); StringAssert.DoesNotEndWith(" ", arg.Key, "Arguments key should be trimmed."); StringAssert.DoesNotStartWith(" ", (string)arg.Value, "Arguments value should be trimmed."); StringAssert.DoesNotEndWith(" ", (string)arg.Value, "Arguments value should be trimmed."); } }
public void TestKeyValueParse() { // Given var pairs = new string[] { "key=value", "k=v", "except=bro", "awesome====123123", " keytrimmed = value trimmed " }; // When var args = _parser.Parse(pairs); // Then Assert.AreEqual(pairs.Length, args.Count); foreach (var arg in args) { Assert.NotNull(arg.Value, "Argument value should not be null."); StringAssert.DoesNotStartWith(" ", arg.Key, "Arguments key should be trimmed."); StringAssert.DoesNotEndWith(" ", arg.Key, "Arguments key should be trimmed."); StringAssert.DoesNotStartWith(" ", (string)arg.Value, "Arguments value should be trimmed."); StringAssert.DoesNotEndWith(" ", (string)arg.Value, "Arguments value should be trimmed."); } }
public void stringNotStartWith_Test() { var testor = new TestorTheBarbarian(); //comment above and uncomment below to fail test //var testor = new Enemy() { Name = "Bugra" }; //Nunit Classic Model StringAssert.DoesNotStartWith("Bug", testor.Name); // --> Expected: not String starting with "Bug" But was: "Bugra" //NUnit Constraint model Assert.That(testor.Name, Is.Not.StringStarting("Bug")); // --> Expected: not String starting with "Bug" But was: "Bugra" //FluentAssertions syntax testor.Name.Should().NotStartWith("Bug"); // --> Result Message: Expected string that does not start with "Bug", but found "Bugra". //with optional description testor.Name.Should().NotStartWith("Bug", because: "testor isn't Bugra"); // --> Result Message: Expected string that does not start with "Bug" because testor isn't Bugra, but found "Bugra". }
public void DoesNotStartWithFails() { StringAssert.DoesNotStartWith("abc", "abc**"); }
public void test3() { StringAssert.DoesNotStartWith("a", "b"); }
public static void ShouldNotStartWith(this string actual, string expected) { StringAssert.DoesNotStartWith(expected, actual); }
/// <summary> /// Tests whether the specified string begins with the specified substring /// and throws an exception if the test string does not start with the /// substring. /// </summary> /// <param name="assert">The <see cref="StringAssert"/> instance to extend.</param> /// <param name="value"> /// The string that is expected to begin with <paramref name="substring"/>. /// </param> /// <param name="substring"> /// The string expected to be a prefix of <paramref name="value"/>. /// </param> /// <param name="message"> /// The message to include in the exception when <paramref name="value"/> /// does not begin with <paramref name="substring"/>. The message is /// shown in test results. /// </param> /// <param name="comparisonType"> /// The comparison method to compare strings <paramref name="comparisonType"/>. /// </param> /// <exception cref="AssertFailedException"> /// Thrown if <paramref name="value"/> does not begin with /// <paramref name="substring"/>. /// </exception> public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message, StringComparison comparisonType) { assert.DoesNotStartWith(value, substring, message, comparisonType, Empty); }
private void InternalTestException(IsolatedMode mode, string methodSig, string expectedException, LineNumberInfo[] expectedInfos) { // Parse the methodSig var assemblyName = "ProductionStackTrace.Test.Library"; var defaultNamespace = assemblyName; var m = _regexMethodSig.Match(methodSig); if (m == Match.Empty) { throw new ArgumentException("Invalid methodSig: " + methodSig); } var className = m.Groups["Class"].ToString().TrimEnd('.'); var methodName = m.Groups["Method"].ToString(); var methodParams = m.Groups["Params"].ToString(); // Execute in isolated environment with or without access to // PDB symbols information (meaning native stack trace either has // or doesn't have line number info) // // Customization in the .csproj file for this Test project in the // "AfterBuild" target will setup two subfolders - lib and libpdb. // 'lib' will contain just the DLL, and 'libpdb' will have DLL + PDB. // // Also original PDB location will be deleted, so that PDB can only // be found if it's on the Symbols Paths or in the folder as DLL. var env = new IsolatedEnvironment(); env.LibPaths.Add(mode == IsolatedMode.NoSymbols ? "lib" : "libpdb"); var r = env.Run(string.Format("{1}.{2}, {0}", assemblyName, defaultNamespace, className), methodName); Assert.IsNotNull(r.Exception); Assert.IsNotNullOrEmpty(r.ExceptionStackTrace); Assert.IsNotNullOrEmpty(r.ExceptionReport); StringAssert.StartsWith(expectedException + "\r\n", r.ExceptionStackTrace); StringAssert.StartsWith(expectedException + "\r\n", r.ExceptionReport); StringAssert.Contains(" at " + defaultNamespace + "." + methodSig, r.ExceptionStackTrace); Assert.AreNotEqual(r.ExceptionStackTrace, r.ExceptionReport); if (mode == IsolatedMode.NoSymbols) { StringAssert.DoesNotContain(":line ", r.ExceptionStackTrace); } else { StringAssert.Contains(":line ", r.ExceptionStackTrace); } var interpret = new ExceptionReportInterpreter(); var sb = new StringBuilder(); string parsedReport; if (mode != IsolatedMode.NoSymbols) { interpret.SymbolPaths.Add("libpdb"); } // Run interpreter with no access to symbols // It should produce the same stack trace as the internal exception interpret.Translate(new StringReader(r.ExceptionReport), new StringWriter(sb)); parsedReport = sb.ToString(); // Parsed report should be exactly the same as we would obtain // from the original stack trace. // // - If the original stack trace was run without symbols, then // interpreter didn't have access to symbols either, and so // the output should match Assert.AreEqual(r.ExceptionStackTrace, parsedReport.TrimEnd()); if (mode == IsolatedMode.NoSymbols) { // If we ran original report with no access to symbols, then // run it again - now with PDB symbols. The stack trace should now // include line number info sb.Clear(); interpret.SymbolPaths.Add("libpdb"); interpret.Translate(new StringReader(r.ExceptionReport), new StringWriter(sb)); parsedReport = sb.ToString(); StringAssert.DoesNotStartWith(parsedReport, r.ExceptionReport); // check it is different Assert.AreNotEqual(r.ExceptionStackTrace, parsedReport); // check it is not same as default stack trace } // Check that the expected line number info is present foreach (var info in expectedInfos) { StringAssert.Contains("\\" + info.File + ":line " + info.LineNo, parsedReport); // check it has the line info } }
/// <summary> /// Tests whether the specified string begins with the specified substring /// and throws an exception if the test string does not start with the /// substring. /// </summary> /// <param name="assert">The <see cref="StringAssert"/> instance to extend.</param> /// <param name="value"> /// The string that is expected to begin with <paramref name="substring"/>. /// </param> /// <param name="substring"> /// The string expected to be a prefix of <paramref name="value"/>. /// </param> /// <param name="message"> /// The message to include in the exception when <paramref name="value"/> /// does not begin with <paramref name="substring"/>. The message is /// shown in test results. /// </param> /// <exception cref="AssertFailedException"> /// Thrown if <paramref name="value"/> does not begin with /// <paramref name="substring"/>. /// </exception> public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message) { assert.DoesNotStartWith(value, substring, message, StringComparison.Ordinal); }
/// <summary> /// Tests whether the specified string begins with the specified substring /// and throws an exception if the test string does not start with the /// substring. /// </summary> /// <param name="assert">The <see cref="StringAssert"/> instance to extend.</param> /// <param name="value"> /// The string that is expected to begin with <paramref name="substring"/>. /// </param> /// <param name="substring"> /// The string expected to be a prefix of <paramref name="value"/>. /// </param> /// <exception cref="AssertFailedException"> /// Thrown if <paramref name="value"/> does not begin with /// <paramref name="substring"/>. /// </exception> public static void DoesNotStartWith(this StringAssert assert, string value, string substring) { assert.DoesNotStartWith(value, substring, String.Empty, StringComparison.Ordinal); }
public void It_does_not_include_a_byte_order_mark_when_rendering_to_strings() { var output = Render.StringToString("{{foo}}", new { foo = "bar" }); StringAssert.DoesNotStartWith(output, "\uFEFF"); }
[TestCase("hoge", "HOGEaaa")] // Test OK. public void DoesNotStartWithTest(string expected, string actual) { StringAssert.DoesNotStartWith(expected, actual); }
public void DoesNotStartWith() { StringAssert.DoesNotStartWith("x", "abc"); }
/// <summary> /// Tests whether the specified string begins with the specified substring /// and throws an exception if the test string does not start with the /// substring. /// </summary> /// <param name="assert">The <see cref="StringAssert"/> instance to extend.</param> /// <param name="value"> /// The string that is expected to begin with <paramref name="substring"/>. /// </param> /// <param name="substring"> /// The string expected to be a prefix of <paramref name="value"/>. /// </param> /// <param name="message"> /// The message to include in the exception when <paramref name="value"/> /// does not begin with <paramref name="substring"/>. The message is /// shown in test results. /// </param> /// <param name="parameters"> /// An array of parameters to use when formatting <paramref name="message"/>. /// </param> /// <exception cref="AssertFailedException"> /// Thrown if <paramref name="value"/> does not begin with /// <paramref name="substring"/>. /// </exception> public static void DoesNotStartWith(this StringAssert assert, string value, string substring, string message, params object?[] parameters) { assert.DoesNotStartWith(value, substring, message, StringComparison.Ordinal, parameters); }
public void DoesNotStartWithFails() { Assert.Throws <AssertionException>(() => StringAssert.DoesNotStartWith("abc", "abc**")); }
private static bool Assert(string actual, ExpectTo expectsTo, string expected, string message) { expected = expected.TrimEnd(); actual = actual.TrimEnd(); bool r; switch (expectsTo) { case ExpectTo.Contain: r = actual == null && expected == null || actual != null && expected != null && actual.Contains(expected); if (!r && message != null) { StringAssert.Contains(expected, actual, $"{message} - The actual string should contain the expected string."); } return(r); case ExpectTo.EndWith: r = expected == null && actual == null || actual != null && expected != null && actual.EndsWith(expected, StringComparison.Ordinal); if (!r && message != null) { StringAssert.EndsWith(expected, actual, $"{message} - The actual string should end with the expected string."); } return(r); case ExpectTo.Equal: r = expected == actual; if (!r && message != null) { UnitTestingAssert.AreEqual(expected, actual, $"{message} - The actual string should equal to the expected string."); } return(r); case ExpectTo.EqualIgnoringCase: r = string.Equals(expected, actual, StringComparison.InvariantCultureIgnoreCase); if (!r && message != null) { StringAssert.AreEqualIgnoringCase(expected, actual, $"{message}: The actual string does not equal ignoring case to the expected string."); } return(r); case ExpectTo.Match: r = expected == null && actual == null || expected != null && actual != null && Regex.IsMatch(actual, expected); if (!r && message != null) { StringAssert.IsMatch(expected, actual, $"{message} - The actual string should match the expected string pattern."); } return(r); case ExpectTo.NotEndWith: r = (actual == null) != (expected == null) || expected != null && actual != null && !actual.EndsWith(expected, StringComparison.Ordinal); if (!r && message != null) { StringAssert.DoesNotEndWith(expected, actual, $"{message} - The actual string should not end with the expected string."); } return(r); case ExpectTo.NotEqual: r = actual != expected; if (!r && message != null) { UnitTestingAssert.AreNotEqual(expected, actual, $"{message}: The actual string should not equal to the expected string."); } return(r); case ExpectTo.NotEqualIgnoringCase: r = (expected == null) != (actual == null) || expected != null && actual != null && !expected.Equals(actual, StringComparison.OrdinalIgnoreCase); if (!r && message != null) { StringAssert.AreNotEqualIgnoringCase(expected, actual, $"{message} - The actual string should not equal ignoring case to the expected string."); } return(r); case ExpectTo.NotMatch: r = (expected == null) != (actual == null) || expected != null && actual != null && !Regex.IsMatch(actual, expected); if (!r && message != null) { StringAssert.DoesNotMatch(expected, actual, $"{message} - The actual string should not match the expected string."); } return(r); case ExpectTo.NotStartWith: r = (expected == null) != (actual == null) || actual != null && expected != null && !actual.StartsWith(expected, StringComparison.Ordinal); if (!r && message != null) { StringAssert.DoesNotStartWith(expected, actual, $"{message} - The actual string should not start with the expected string."); } return(r); case ExpectTo.StartWith: r = (expected == null) && (actual == null) || actual != null && expected != null && actual.StartsWith(expected, StringComparison.Ordinal); if (!r && message != null) { StringAssert.StartsWith(expected, actual, $"{message} - The actual string should start with the expected string."); } return(r); default: throw new InvalidOperationException($"Expect to {expectsTo} is invalid."); } }