public void CssClassWellFormatted() { Services.AddSingleton <NavigationManager>(new MockNavigationManager("http://localhost/")); var renderedComponent = RenderComponent <AlertLink>(); renderedComponent.Find("a").ClassName.Should().Contain("alert-link", Exactly.Once()); }
public static object[][] PassingConstraints() => new object[][] { new object[] { AtLeast.Once(), 1 }, new object[] { AtLeast.Once(), 2 }, new object[] { AtLeast.Twice(), 2 }, new object[] { AtLeast.Twice(), 3 }, new object[] { AtLeast.Thrice(), 3 }, new object[] { AtLeast.Thrice(), 4 }, new object[] { AtLeast.Times(4), 4 }, new object[] { AtLeast.Times(4), 5 }, new object[] { AtMost.Once(), 0 }, new object[] { AtMost.Once(), 1 }, new object[] { AtMost.Twice(), 1 }, new object[] { AtMost.Twice(), 2 }, new object[] { AtMost.Thrice(), 2 }, new object[] { AtMost.Thrice(), 3 }, new object[] { AtMost.Times(4), 3 }, new object[] { AtMost.Times(4), 4 }, new object[] { Exactly.Once(), 1 }, new object[] { Exactly.Twice(), 2 }, new object[] { Exactly.Thrice(), 3 }, new object[] { Exactly.Times(4), 4 }, new object[] { LessThan.Twice(), 1 }, new object[] { LessThan.Thrice(), 2 }, new object[] { LessThan.Times(4), 3 }, new object[] { MoreThan.Once(), 2 }, new object[] { MoreThan.Twice(), 3 }, new object[] { MoreThan.Thrice(), 4 }, new object[] { MoreThan.Times(4), 5 }, };
public async Task ThenTheDeliveryModesForEachProviderAreDisplayed(string not) { var json = DataFileManager.GetFile("course-providers.json"); var expectedApiResponse = JsonConvert.DeserializeObject <TrainingCourseProviders>(json); var response = _context.Get <HttpResponseMessage>(ContextKeys.HttpResponse); var actualContent = await response.Content.ReadAsStringAsync(); foreach (var mode in Enum.GetValues(typeof(DeliveryModeType)).Cast <DeliveryModeType>()) { if (mode == DeliveryModeType.NotFound || mode == DeliveryModeType.National) { continue; } var modeName = mode.GetDescription().Replace("’", "’");// for some reason HtmlEncode doesn't encode '’' if (not == string.Empty) { actualContent.Should().Contain(modeName, Exactly.Times(expectedApiResponse.Total + 1));// additional time in the filter ui } else { actualContent.Should().NotContain(modeName); } } }
public void CadenaConMasDeUnaOcurrencia() { _cadenaNoVacioXL.Should().Contain("pero", MoreThan.Twice()); _cadenaNoVacioXL.Should().Contain("pero", MoreThan.Times(2)); _cadenaNoVacioXL.Should().Contain("pero", Exactly.Times(3)); _cadenaNoVacioXL.Should().Contain("pero", Exactly.Thrice()); }
public void When_comparing_strings_for_containing_one_equivalent_it_should_ignore_culture(string subject, string expected) { // Act Action act = () => subject.Should().ContainEquivalentOf(expected, Exactly.Once()); // Assert act.Should().NotThrow <XunitException>(); }
public void When_a_string_is_matched_and_the_expected_count_is_zero_and_string_not_matches_it_passes() { // Arrange string subject = "a"; // Act Action act = () => subject.Should().MatchRegex("b", Exactly.Times(0)); // Assert act.Should().NotThrow(); }
public void When_a_string_is_matched_and_the_expected_count_is_zero_and_string_matches_it_fails() { // Arrange string subject = "a"; // Act Action act = () => subject.Should().MatchRegex("a", Exactly.Times(0)); // Assert act.Should().Throw <XunitException>() .WithMessage($"Expected subject*a*to match regex*\"a\" exactly 0 times, but found it 1 time*"); }
public void When_regex_is_invalid_it_fails_and_ignores_occurrences() { // Arrange string subject = "a"; // Act Action act = () => subject.Should().MatchRegex(".**", Exactly.Times(0)); // Assert act.Should().ThrowExactly <XunitException>() .WithMessage("Cannot match subject against \".**\" because it is not a valid regular expression.*"); }
public void ShouldEachBoardRowContainTenMappedPositionStatesSeparatedBySpace(int rowNumber) { const string state = "state"; const int headerOffset = 1; var boardDouble = CreateDummyBoard(); A.CallTo(() => _positionStateMapperDouble.Map(A <PositionState> ._)).Returns(state); _subject.Print(boardDouble).Split(Environment.NewLine)[rowNumber + headerOffset] .Should().Contain(' ' + state, Exactly.Times(Board.Size)); }
public void When_string_containment_exactly_is_asserted_and_actual_value_contains_the_expected_string_exactly_expected_times_it_should_not_throw() { // Arrange string actual = "ABCDEBCDF"; string expectedSubstring = "BCD"; // Act Action act = () => actual.Should().Contain(expectedSubstring, Exactly.Times(2)); // Assert act.Should().NotThrow(); }
public void When_string_containment_once_is_asserted_and_actual_value_is_null_then_it_should_throw() { // Arrange string actual = null; string expectedSubstring = "XYZ"; // Act Action act = () => actual.Should().Contain(expectedSubstring, Exactly.Once()); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected * <null> to contain \"XYZ\" exactly 1 time, but found it 0 times."); }
public void When_string_containment_exactly_is_asserted_and_actual_value_contains_the_expected_string_but_not_exactly_expected_times_it_should_throw() { // Arrange string actual = "ABCDEBCDF"; string expectedSubstring = "BCD"; // Act Action act = () => actual.Should().Contain(expectedSubstring, Exactly.Times(3)); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected * \"ABCDEBCDF\" to contain \"BCD\" exactly 3 times, but found it 2 times."); }
public void When_string_containment_once_is_asserted_and_actual_value_does_not_contain_the_expected_string_it_should_throw() { // Arrange string actual = "ABCDEF"; string expectedSubstring = "XYS"; // Act Action act = () => actual.Should().Contain(expectedSubstring, Exactly.Once(), "that is {0}", "required"); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected * \"ABCDEF\" to contain \"XYS\" exactly 1 time because that is required, but found it 0 times."); }
public void When_regex_is_empty_it_fails_and_ignores_occurrences() { // Arrange string subject = "a"; // Act Action act = () => subject.Should().MatchRegex(string.Empty, Exactly.Times(0)); // Assert act.Should().ThrowExactly <ArgumentException>() .WithMessage("Cannot match string against an empty string. Provide a regex pattern or use the BeEmpty method.*") .WithParameterName("regularExpression"); }
public void When_string_containment_exactly_is_asserted_and_expected_value_is_negative_it_should_throw() { // Arrange string actual = "ABCDEBCDF"; string expectedSubstring = "BCD"; // Act Action act = () => actual.Should().Contain(expectedSubstring, Exactly.Times(-1)); // Assert act.Should().Throw <ArgumentOutOfRangeException>() .WithMessage("Expected count cannot be negative.*"); }
public void When_a_string_is_matched_and_the_count_of_matches_do_not_fit_the_expected_it_fails() { // Arrange string subject = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt " + "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et " + "ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; // Act Action act = () => subject.Should().MatchRegex("Lorem.*", Exactly.Twice()); // Assert act.Should().Throw <XunitException>() .WithMessage($"Expected subject*Lorem*to match regex*\"Lorem.*\" exactly 2 times, but found it 1 time*"); }
public void When_containment_once_is_asserted_against_null_it_should_throw_earlier() { // Arrange string actual = "a"; string expectedSubstring = null; // Act Action act = () => actual.Should().Contain(expectedSubstring, Exactly.Once()); // Assert act .Should().Throw <ArgumentNullException>() .WithMessage("Cannot assert string containment against <null>.*"); }
public void When_the_subject_is_empty_and_expected_count_is_zero_it_passes() { // Arrange string subject = string.Empty; // Act Action act = () => { using var _ = new AssertionScope(); subject.Should().MatchRegex("a", Exactly.Times(0)); }; // Assert act.Should().NotThrow(); }
public void Statement_Rented_movie_should_be_listed_once() { // Arrange const string expectedTitle = "Matrix"; var rental = new RentalBuilder().WithTitle(expectedTitle).Build(); var customer = new Customer(null); customer.AddRental(rental); // Act var outcome = customer.Statement(); // Assert outcome.Should().Contain(expectedTitle, Exactly.Once()); }
public async Task AddCogitation_ShouldReplaceHostAndPortByPlaceholdere() { var context = CreateContext(); var svc = GetRecordsService(context); var recId = Create_Record(context); var hpSvc = new HostAndPortStub(); var text = $@"New text with link {hpSvc.GetHostAndPort()}/index and another link {hpSvc.GetHostAndPort()}/images/12345678"; var cogId = await svc.AddCogitation(recId, text); var cog = await context.Cogitations.FindAsync(cogId); cog.Text.Should().NotContain(hpSvc.GetHostAndPort()); cog.Text.Should().Contain(hpSvc.GetHostAndPortPlaceholder(), Exactly.Twice()); }
public async Task AddDiaryRecord_ShouldReplaceHostAndPortByPlaceholder() { var context = CreateContext(); var svc = GetRecordsService(context); var hpSvc = new HostAndPortStub(); var text = $@"New text with link {hpSvc.GetHostAndPort()}/index and another link {hpSvc.GetHostAndPort()}/images/12345678"; var id = await svc.AddRecord(DateOnly.FromDateTime(DateTime.UtcNow), text, text); var rec = await context.Records.SingleOrDefaultAsync(r => r.Id == id); rec.Name.Should().NotContain(hpSvc.GetHostAndPort()); rec.Text.Should().NotContain(hpSvc.GetHostAndPort()); rec.Name.Should().Contain(hpSvc.GetHostAndPortPlaceholder(), Exactly.Twice()); rec.Text.Should().Contain(hpSvc.GetHostAndPortPlaceholder(), Exactly.Twice()); }
public void When_the_subject_is_null_it_fails() { // Arrange string subject = null; // Act Action act = () => { using var _ = new AssertionScope(); subject.Should().MatchRegex(".*", Exactly.Times(0), "because it should be a string"); }; // Assert act.Should().ThrowExactly <XunitException>() .WithMessage("Expected subject to match regex*\".*\" because it should be a string, but it was <null>."); }
public void Scan_ShouldProduceThreeLinesBill_WhenSameProductScanned() { // Arrange var service = new CheckoutService(); service.Start(); // Act service.Scan(ValidCode); service.Scan(ValidCode); service.Scan(ValidCode); // Assert var currentBill = service.GetCurrentBill(); Console.WriteLine(currentBill); currentBill.Should().Contain(Environment.NewLine, Exactly.Twice()); }
public void OrderByConcatModifier([DataSources(TestProvName.AllSybase)] string context) { using (var db = GetDataContext(context)) { var persons = db.Person .OrderBy(c => c.LastName).Take(1); var concat = persons .Concat(persons); var sql = concat.ToString(); sql.Should().Contain("ORDER", Exactly.Twice()); Assert.DoesNotThrow(() => { concat.ToList(); }); } }
public async Task FetchRecordById_ShouldReplacePlaceholderByHostAndPort() { var context = CreateContext(); var svc = GetRecordsService(context); var rec = GetTestRecord(); var hpSvc = new HostAndPortStub(); var text = $@"New text with link {hpSvc.GetHostAndPortPlaceholder()}/index and another link {hpSvc.GetHostAndPortPlaceholder()}/images/12345678"; rec.Name = text; rec.Text = text; context.Records.Add(rec); await context.SaveChangesAsync(); var savedRec = await svc.FetchRecordById(rec.Id); savedRec.Name.Should().NotContain(hpSvc.GetHostAndPortPlaceholder()); savedRec.Text.Should().NotContain(hpSvc.GetHostAndPortPlaceholder()); savedRec.Name.Should().Contain(hpSvc.GetHostAndPort(), Exactly.Twice()); savedRec.Text.Should().Contain(hpSvc.GetHostAndPort(), Exactly.Twice()); }
public void When_the_same_failure_is_handled_twice_or_more_it_should_still_report_it_once() { // Arrange var scope = new AssertionScope(); AssertionScope.Current.FailWith("Failure"); AssertionScope.Current.FailWith("Failure"); using (var nestedScope = new AssertionScope()) { nestedScope.FailWith("Failure"); nestedScope.FailWith("Failure"); } // Act Action act = scope.Dispose; // Assert act.Should().Throw <XunitException>() .Which.Message.Should().Contain("Failure", Exactly.Times(4)); }
public async Task Marking_due_item_as_done() { using var client = _factory.CreateAuthenticatedClient(); var response = await client.GetAsync("/"); response.StatusCode.Should().Be(HttpStatusCode.OK); var responseContent = await response.Content.ReadAsStringAsync(); responseContent.Should().Contain("Logout") .And.Contain("1 overdue and 1 due today (2)") .And.Contain("All (3)") .And.Contain("All upcoming (2)") .And.Contain("Due yesterday", Exactly.Once()) .And.Contain("Due today", Exactly.Once()); var item = await GetUserItemWithDescriptionAsync("Test item 2"); item.NextDueDate.Should().Be(DateTime.Today); item.LastUpdateDateTime.Should().BeNull(); var doneAction = $"/items/done/{item.UserItemId}"; var validationToken = IntegrationTestWebApplicationFactory.GetFormValidationToken(responseContent, doneAction); var beforeEdit = DateTime.UtcNow; response = await client.PostAsync(doneAction, new FormUrlEncodedContent(new[] { KeyValuePair.Create("__RequestVerificationToken", validationToken) })); response.StatusCode.Should().Be(HttpStatusCode.OK); responseContent = await response.Content.ReadAsStringAsync(); responseContent.Should().Contain("Logout") .And.Contain("1 overdue (1)") .And.Contain("All (2)") .And.Contain("All upcoming (1)") .And.Contain("Due yesterday", Exactly.Once()); item = await GetUserItemWithDescriptionAsync("Test item 2"); item.NextDueDate.Should().Be(DateTime.Today); item.CompletedDateTime.Should().BeAfter(beforeEdit); item.LastUpdateDateTime.Should().BeAfter(beforeEdit); }
public async Task FetchRecordById_ShouldReplacePlaceholderByHostAndPort_InCogitations() { var context = CreateContext(); var svc = GetRecordsService(context); var recId = Create_Record(context); var hpSvc = new HostAndPortStub(); var text = $@"New text with link {hpSvc.GetHostAndPortPlaceholder()}/index and another link {hpSvc.GetHostAndPortPlaceholder()}/images/12345678"; var cogitationsList = Enumerable.Range(1, 3) .Select(i => new Cogitation { Id = Guid.NewGuid(), RecordId = recId, Date = DateTime.UtcNow, Text = text }).ToList(); context.Cogitations.AddRange(cogitationsList); await context.SaveChangesAsync(); var savedRec = await svc.FetchRecordById(recId); foreach (var c in savedRec.Cogitations) { c.Text.Should().NotContain(hpSvc.GetHostAndPortPlaceholder()); c.Text.Should().Contain(hpSvc.GetHostAndPort(), Exactly.Twice()); } }
public async Task UpdateCogitationText_ShouldReplaceHostAndPortByPlaceholdere() { var context = CreateContext(); var svc = GetRecordsService(context); var recId = Create_Record(context); var cId = Guid.NewGuid(); var cDate = DateTime.UtcNow; var cText = "Some Text 81237912y0r9182ny"; var hpSvc = new HostAndPortStub(); var newText = $@"New text with link {hpSvc.GetHostAndPort()}/index and another link {hpSvc.GetHostAndPort()}/images/12345678"; context.Cogitations.Add(new Cogitation { Id = cId, Date = cDate, RecordId = recId, Text = cText }); await context.SaveChangesAsync(); await svc.UpdateCogitationText(cId, newText); var cog = await context.Cogitations.FindAsync(cId); cog.Text.Should().NotContain(hpSvc.GetHostAndPort()); cog.Text.Should().Contain(hpSvc.GetHostAndPortPlaceholder(), Exactly.Twice()); }
public void When_string_containment_equivalent_of_exactly_once_is_asserted_and_actual_value_is_null_then_it_should_throw_earlier() { // Arrange string actual = null; string expectedSubstring = "XyZ"; // Act Action act = () => actual.Should().ContainEquivalentOf(expectedSubstring, Exactly.Once(), "that is {0}", "required"); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected * <null> to contain equivalent of \"XyZ\" exactly 1 time because that is required, but found it 0 times."); }