public void InSqlFunctionTest() { using (var session = factory.OpenSession()) { CreateObjects(typeof(Simple), session); var inExpression = Restrictions.In( Projections.SqlFunction( "substring", NHibernateUtil.String, Projections.Property("Name"), Projections.Constant(1), Projections.Constant(1)), new object[] { "A", "B" }); var sql = inExpression.ToSqlString(criteria, criteriaQuery, new CollectionHelper.EmptyMapClass <string, IFilter>()); // Allow some dialectal differences in function name and parameter style. Assert.That(sql.ToString(), Does.StartWith("substring(sql_alias.Name").Or.StartsWith("substr(sql_alias.Name")); Assert.That(sql.ToString(), Does.EndWith(") in (?, ?)")); // Ensure no parameters are duplicated. var parameters = criteriaQuery.CollectedParameters.ToList(); Assert.That(parameters.Count, Is.EqualTo(4)); Assert.That(parameters[0].Value, Is.EqualTo(1)); Assert.That(parameters[1].Value, Is.EqualTo(1)); Assert.That(parameters[2].Value, Is.EqualTo("A")); Assert.That(parameters[3].Value, Is.EqualTo("B")); } }
public async Task Gif_is_a_gif() { var gif = await GiphyController.GetRandomGif("test"); Assert.That(gif, Does.StartWith("http")); Assert.That(gif, Does.EndWith("/giphy.gif")); }
public void ReadALargeAmountOfData() { driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("macbeth.html"); string source = driver.PageSource.Trim().ToLower(); Assert.That(source, Does.EndWith("</html>")); }
public void ShouldAllowSendingKeyUp() { driver.Url = javascriptPage; IWebElement keysEventInput = driver.FindElement(By.Id("theworks")); // Scroll the element into view before attempting any actions on it. ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView();", keysEventInput); IAction pressShift = new Actions(driver).KeyDown(keysEventInput, Keys.Shift).Build(); pressShift.Perform(); IWebElement keyLoggingElement = driver.FindElement(By.Id("result")); string eventsText = keyLoggingElement.Text; Assert.That(keyLoggingElement.Text, Does.EndWith("keydown")); IAction releaseShift = new Actions(driver).KeyUp(keysEventInput, Keys.Shift).Build(); releaseShift.Perform(); eventsText = keyLoggingElement.Text; Assert.That(keyLoggingElement.Text, Does.EndWith("keyup")); }
public void Can_create_gist() { var gateway = new GitHubGateway(AccessToken); var gist = gateway.CreateGithubGist( description: "Hello World Examples", isPublic: true, files: new Dictionary <string, string> { ["hello_world_ruby.txt"] = "Run `ruby hello_world.rb` to print Hello World", ["hello_world_python.txt"] = "Run `python hello_world.py` to print Hello World", }); gist.PrintDump(); Assert.That(gist.Owner.Login, Is.EqualTo("gistlyn")); Assert.That(gist.Owner.Url, Is.EqualTo("https://api.github.com/users/gistlyn")); Assert.That(gist.Owner.Html_Url, Is.EqualTo("https://github.com/gistlyn")); var file = gist.Files["hello_world_ruby.txt"]; Assert.That(file.Filename, Is.EqualTo("hello_world_ruby.txt")); Assert.That(file.Type, Is.EqualTo("text/plain")); Assert.That(file.Language, Is.EqualTo("Text")); Assert.That(file.Raw_Url, Does.EndWith("/hello_world_ruby.txt")); Assert.That(file.Size, Is.GreaterThan(0)); Assert.That(file.Content, Does.Contain("Run `ruby hello_world.rb` to print Hello World")); file = gist.Files["hello_world_python.txt"]; Assert.That(file.Filename, Is.EqualTo("hello_world_python.txt")); Assert.That(file.Type, Is.EqualTo("text/plain")); Assert.That(file.Language, Is.EqualTo("Text")); Assert.That(file.Raw_Url, Does.EndWith("/hello_world_python.txt")); Assert.That(file.Size, Is.GreaterThan(0)); Assert.That(file.Content, Does.Contain("Run `python hello_world.py` to print Hello World")); }
public void Invoke(int id, SettingValue src, IEnumerable <string> args, string filename, bool precopy) { var dest = Create(Combine(args, filename)); // see remarks dest.Value.EmbedFonts = src.EmbedFonts; dest.Value.Downsampling = src.Downsampling; using (var vm = new MainViewModel(dest)) { Set(vm, src); var vms = vm.General; Assert.That(vms.Destination, Does.EndWith(vms.Format.GetExtension())); Assert.That(IO.Exists(vms.Source), Is.True, vms.Source); Assert.That(IO.Exists(vms.Destination), Is.False, vms.Destination); // Test for SaveOption if (precopy) { IO.Copy(GetSource("Sample.pdf"), vms.Destination); } vm.Subscribe <DialogMessage>(SetMessage); Assert.That(Test(vm), Is.True, $"Timeout (No.{id})"); } Assert.That(IO.Exists(dest.Value.Source), Is.False, dest.Value.Source); Assert.That(IsCreated(dest.Value.Destination), Is.True, dest.DocumentName.Source); }
public void StringTestsExamples() { //Commenting out failing Assertions but leaving for examples string name = "Sarah"; //Assert.That(name, Is.Empty);//fail Assert.That(name, Is.Not.Empty); Assert.That(name, Is.EqualTo("Sarah")); //Assert.That(name, Is.EqualTo("SARAH"));//fail Assert.That(name, Is.EqualTo("SARAH").IgnoreCase); Assert.That(name, Does.StartWith("Sa")); Assert.That(name, Does.EndWith("ah")); Assert.That(name, Does.Contain("ara")); Assert.That(name, Does.Not.Contain("Brian")); Assert.That(name, Does.StartWith("Sa") .And.EndWith("rah")); Assert.That(name, Does.StartWith("xyz") .Or.EndWith("rah")); }
public void Gets_location_for_correct_window_scope() { Driver.Click(Link("Open pop up window")); var popUp = new BrowserWindow(DefaultSessionConfiguration, new WindowFinder(Driver, "Pop Up Window", Root, DefaultOptions), Driver, null, null, null, DisambiguationStrategy); Assert.That(Driver.Location(popUp).AbsoluteUri, Does.EndWith("src/Coypu.Drivers.Tests/html/popup.htm")); }
public void Check_Entry_Five_73x_Is_Parsed() { var entry = EntriesToMatch_73x[4]; var match = LogDataService.CheckIsLongEntryMatch(entry); var data = LogDataService.ParseLogDataItem(entry, match); Assert.That(data, Is.Not.Null); var expectedDate = DateTime.Parse("2015-11-17 09:03:59.502"); Assert.That(data.Date, Is.EqualTo(expectedDate)); Assert.That(data.Level, Is.EqualTo("ERROR")); Assert.That(data.Logger, Is.EqualTo("Umbraco.Core.UmbracoApplicationBase")); Assert.That(data.Message, Does.StartWith("An unhandled exception occurred")); Assert.That(data.Message, Does.EndWith("And lots of other messages here some with square brackets in like [these]...")); Assert.That(data.ThreadId, Is.EqualTo("1")); Assert.That(data.ProcessId, Is.EqualTo("5308")); Assert.That(data.DomainId, Is.EqualTo("2")); }
public void Check_Entry_Six_73x_Is_Parsed() { var entry = EntriesToMatch_73x[5]; var match = LogDataService.CheckIsLongEntryMatch(entry); var data = LogDataService.ParseLogDataItem(entry, match); Assert.That(data, Is.Not.Null); var expectedDate = DateTime.Parse("2015-12-14 10:26:51.147"); Assert.That(data.Date, Is.EqualTo(expectedDate)); Assert.That(data.Level, Is.EqualTo("INFO")); Assert.That(data.Logger, Is.EqualTo("Umbraco.Core.UmbracoApplicationBase")); Assert.That(data.Message, Does.StartWith("Application shutdown. Details: ConfigurationChange")); Assert.That(data.Message, Does.EndWith("at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()")); Assert.That(data.ThreadId, Is.EqualTo("9")); Assert.That(data.ProcessId, Is.EqualTo("8060")); Assert.That(data.DomainId, Is.EqualTo("2")); }
public void Check_Entry_Four_73x_Is_Parsed() { var entry = EntriesToMatch_73x[3]; var match = LogDataService.CheckIsLongEntryMatch(entry); var data = LogDataService.ParseLogDataItem(entry, match); Assert.That(data, Is.Not.Null); var expectedDate = DateTime.Parse("2015-09-16 16:41:08.651"); Assert.That(data.Date, Is.EqualTo(expectedDate)); Assert.That(data.Level, Is.EqualTo("ERROR")); Assert.That(data.Logger, Is.EqualTo("umbraco.content")); Assert.That(data.Message, Does.StartWith("Failed to load Xml from file.")); Assert.That(data.Message, Does.EndWith("at umbraco.content.LoadXmlFromFile()")); Assert.That(data.ThreadId, Is.EqualTo("42")); Assert.That(data.ProcessId, Is.EqualTo("7548")); Assert.That(data.DomainId, Is.EqualTo("8")); }
public void Check_Entry_Three_73x_Is_Parsed() { var entry = EntriesToMatch_73x[2]; var match = LogDataService.CheckIsLongEntryMatch(entry); var data = LogDataService.ParseLogDataItem(entry, match); Assert.That(data, Is.Not.Null); var expectedDate = DateTime.Parse("2016-01-21 22:16:47.114"); Assert.That(data.Date, Is.EqualTo(expectedDate)); Assert.That(data.Level, Is.EqualTo("ERROR")); Assert.That(data.Logger, Is.EqualTo("Umbraco.Web.WebApi.Filters.AngularAntiForgeryHelper")); Assert.That(data.Message, Does.StartWith("Could not validate XSRF token")); Assert.That(data.Message, Does.EndWith("at Umbraco.Web.WebApi.Filters.AngularAntiForgeryHelper.ValidateTokens(String cookieToken, String headerToken)")); Assert.That(data.ThreadId, Is.EqualTo("7")); Assert.That(data.ProcessId, Is.EqualTo("10176")); Assert.That(data.DomainId, Is.EqualTo("4")); }
public async Task DeriveTextCommandParameters_UnmappedEnum() { using var conn = await OpenConnectionAsync(); await conn.ExecuteNonQueryAsync("CREATE TYPE fruit AS ENUM ('Apple', 'Cherry', 'Plum')"); conn.ReloadTypes(); await using var _ = DeferAsync(async() => { await conn.ExecuteNonQueryAsync("DROP TYPE fruit"); conn.ReloadTypes(); }); var cmd = new NpgsqlCommand("SELECT :x::fruit", conn); const string val1 = "Apple"; var val2 = new string[] { "Cherry", "Plum" }; NpgsqlCommandBuilder.DeriveParameters(cmd); Assert.That(cmd.Parameters, Has.Count.EqualTo(1)); Assert.That(cmd.Parameters[0].ParameterName, Is.EqualTo("x")); Assert.That(cmd.Parameters[0].NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Unknown)); Assert.That(cmd.Parameters[0].PostgresType, Is.InstanceOf <PostgresEnumType>()); Assert.That(cmd.Parameters[0].PostgresType !.Name, Is.EqualTo("fruit")); Assert.That(cmd.Parameters[0].DataTypeName, Does.EndWith("fruit")); cmd.Parameters[0].Value = val1; using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow); Assert.That(reader.Read(), Is.True); Assert.That(reader.GetString(0), Is.EqualTo(val1)); }
public void FormatAsBold_WhenCalled_ReturnsWithDoubleAsterix(string text, string expected) { var formatter = new MarkdownFormatter(); var result = formatter.FormatAsBold(text); // specific Assert.That(result, Is.EqualTo(expected).IgnoreCase); // general StringAssert.StartsWith("**", result); StringAssert.Contains(text, result); StringAssert.EndsWith("**", result); // general Assert.That(result, Does.StartWith("**")); Assert.That(result, Does.Contain(text).IgnoreCase); Assert.That(result, Does.EndWith("**")); // dotnet add package FluentAssertions result.Should() .StartWith("**") .And .EndWith("**") .And .Contain(text); }
public void A_chapter_constructed_with_a_group_url_fragment_name_and_twitter_name_gets_a_logo_file_name_and_join_url() { var chapter = new Chapter(null, "DummyGroupUrl", "DummyName", "DummyTwitterName"); Assert.That(chapter.LogoFileName, Is.EqualTo("DummyGroupUrl_200.png")); Assert.That(chapter.JoinUrl.ToString(), Does.EndWith("/DummyGroupUrl/join/")); }
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 async Task DeriveParameters_text_mapped_composite() { using var conn = await OpenConnectionAsync(); await using var _ = await GetTempTypeName(conn, out var type); await conn.ExecuteNonQueryAsync($"CREATE TYPE {type} AS (x int, some_text text)"); conn.ReloadTypes(); conn.TypeMapper.MapComposite <SomeComposite>(type); var expected1 = new SomeComposite { X = 8, SomeText = "foo" }; var expected2 = new[] { expected1, new SomeComposite { X = 9, SomeText = "bar" } }; using var cmd = new NpgsqlCommand($"SELECT @p1::{type}, @p2::{type}[]", conn); NpgsqlCommandBuilder.DeriveParameters(cmd); Assert.That(cmd.Parameters, Has.Count.EqualTo(2)); Assert.That(cmd.Parameters[0].ParameterName, Is.EqualTo("p1")); Assert.That(cmd.Parameters[0].NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Unknown)); Assert.That(cmd.Parameters[0].PostgresType, Is.InstanceOf <PostgresCompositeType>()); Assert.That(cmd.Parameters[0].DataTypeName, Does.EndWith(type)); var p1Fields = ((PostgresCompositeType)cmd.Parameters[0].PostgresType !).Fields; Assert.That(p1Fields[0].Name, Is.EqualTo("x")); Assert.That(p1Fields[1].Name, Is.EqualTo("some_text")); Assert.That(cmd.Parameters[1].ParameterName, Is.EqualTo("p2")); Assert.That(cmd.Parameters[1].NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Unknown)); Assert.That(cmd.Parameters[1].PostgresType, Is.InstanceOf <PostgresArrayType>()); Assert.That(cmd.Parameters[1].DataTypeName, Does.EndWith(type + "[]")); var p2Element = ((PostgresArrayType)cmd.Parameters[1].PostgresType !).Element; Assert.That(p2Element, Is.InstanceOf <PostgresCompositeType>()); Assert.That(p2Element.Name, Is.EqualTo(type)); var p2Fields = ((PostgresCompositeType)p2Element).Fields; Assert.That(p2Fields[0].Name, Is.EqualTo("x")); Assert.That(p2Fields[1].Name, Is.EqualTo("some_text")); cmd.Parameters[0].Value = expected1; cmd.Parameters[1].Value = expected2; using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleResult | CommandBehavior.SingleRow); Assert.That(reader.Read(), Is.True); Assert.That(reader.GetFieldValue <SomeComposite>(0).SomeText, Is.EqualTo(expected1.SomeText)); Assert.That(reader.GetFieldValue <SomeComposite>(0).X, Is.EqualTo(expected1.X)); for (var i = 0; i < 2; i++) { Assert.That(reader.GetFieldValue <SomeComposite[]>(1)[i].SomeText, Is.EqualTo(expected2[i].SomeText)); Assert.That(reader.GetFieldValue <SomeComposite[]>(1)[i].X, Is.EqualTo(expected2[i].X)); } }
public void ConcurrentGetOrAdd_ThreadSafeDictionary() { // Some have even go further and have totally rewrite an alternative to ConcurrentDictionary // That takes all into account, to have something performant hen reading (no locks) // And without the flows of the ConcurrentDictionary // The code is really complex (see all what have been put in the Pfz folder), // but as you can see in that example the ThreadSafeDictionary seems to effectively do what we need, // and without having to wrap our factory into a Lazy wrapper // sources: // https://www.codeproject.com/Articles/548406/Dictionary-plus-Locking-versus-ConcurrentDictionar var threadSafeDictionary = new ThreadSafeDictionary <long, string>(); var factoryCount = 0; var exceptionCount = 0; Parallel.For( 0, 50, i => { var added = false; string name; try { name = threadSafeDictionary.GetOrCreateValue( 6, n => { added = true; Interlocked.Increment(ref factoryCount); Thread.Sleep(10); if (factoryCount == 1) { throw new Exception("Issue while accessing a resource (network, file system, ...)"); } return("Six" + "-from-" + i); }); } catch (Exception) { Interlocked.Increment(ref exceptionCount); return; } Assert.That(name, Does.StartWith("Six")); if (added) { Assert.That(name, Does.EndWith("-from-" + i)); } else { Assert.That(name, Does.Not.EndWith("-from-" + i)); } }); Assert.That(factoryCount, Is.EqualTo(2)); Assert.That(exceptionCount, Is.EqualTo(1)); }
public void ShouldSurviveWhenLayoutFails_AndLayoutExceptionsAreSwallowed() { var output = FailingTargetOutput("failing_Logger_s3", false); Assert.That(output, Does.Contain("\"Message\":\"test message\"")); Assert.That(output, Does.Contain("\"flat1\":\"flat1\",\"TimeStamp\":\"")); Assert.That(output, Does.EndWith("\"prop1\":\"value1\",\"prop2\":2}")); }
public void ShouldSurviveWhenLayoutFails() { var output = FailingTargetOutput("failing_Logger_s1", true); Assert.That(output, Does.Contain("\"Message\":\"test message\"")); Assert.That(output, Does.Contain("\"flat1\":\"flat1\",\"TimeStamp\":\"")); Assert.That(output, Does.EndWith("\"prop1\":\"value1\",\"prop2\":2}")); }
private static void VerifyAttachment(UriDataAttachment attachment, string expectedName, string expectedDescription) { Assert.Multiple(() => { Assert.That(attachment.Uri.OriginalString, Does.EndWith(expectedName)); Assert.That(attachment.Description, Is.EqualTo(expectedDescription)); }); }
[TestCase("Нынешний год 2017")] //неправильный public void DoesContainWord(string a) { string b; var result = _math.DoesContainWord(a); b = DateTime.Now.Year.ToString(); //будет брать дату установленной в компьютере Assert.That(result, Does.EndWith(b)); }
public void FormatAsBold_ShouldReturnStringEndsWithStrongTag() { var sut = new HtmlFormatter(); var result = sut.FormatAsBold("hello"); Assert.That(result, Does.EndWith("</strong>")); }
public void RenderMessage_Good_ReturnCorrectJson() { var msg = new ScoreMessageJson(); msg.Initialize(0.98m, 0.75m, true); Assert.That(msg.RenderMessage(), Does.EndWith("\"success\":true,\"score\":0.98,\"threshold\":0.75}")); Assert.That(msg.RenderMessage(), Does.StartWith("{\"timestamp\":\"20")); }
public void RenderMessage_Insufficient_ReturnCorrectJson() { var msg = new ScoreMessageJson(); msg.Initialize(0.62m, 0.75m, false); Assert.That(msg.RenderMessage(), Does.EndWith("\"success\":false,\"score\":0.62,\"threshold\":0.75}")); Assert.That(msg.RenderMessage(), Does.StartWith("{\"timestamp\":\"20")); }
public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement(string value) { var result = _formater.FormatAsBold(value); Assert.That(result, Is.EqualTo($"<strong>{value}</strong>")); Assert.That(result, Does.StartWith("<strong")); Assert.That(result, Does.EndWith("</strong>")); }
public async Task ReadALargeAmountOfData() { await driver.GoToUrl(EnvironmentManager.Instance.UrlBuilder.WhereIs("macbeth.html")); string source = await driver.PageSource().Trim().ToLower(); Assert.That(source, Does.EndWith("</html>")); }
public void ShouldExtractToVersionedFolderWithDefaultPath() { variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath()); convention.Install(new RunningDeployment(PackageLocation, variables)); Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Does.EndWith(Path.Combine("Acme.Web", "1.0.0"))); }
public void Archive() { var restRequest = MockRestResponse(); Client.TextBroadcastsApi.Archive(10L); Assert.AreEqual(Method.POST, restRequest.Value.Method); Assert.That(restRequest.Value.Resource, Does.EndWith("/10/archive")); }
public void FormatAsBold_GivenString_ReturnStringWrappedWithStrongElements(string input) { var result = formatter.FormatAsBold(input); //specific assertion Assert.That(result, Does.StartWith("<strong>")); Assert.That(result, Does.EndWith("</strong>")); }