public async Task PublishToQueueLogsShouldHaveContext() { var services = GivenJustSaying(levelOverride: LogLevel.Information) .ConfigureJustSaying( (builder) => builder.WithLoopbackQueue <SimpleMessage>(UniqueName)); var sp = services.BuildServiceProvider(); var cts = new CancellationTokenSource(); var publisher = sp.GetRequiredService <IMessagePublisher>(); await publisher.StartAsync(cts.Token); var message = new SimpleMessage(); await publisher.PublishAsync(message, cts.Token); var testLogger = sp.GetRequiredService <ITestLoggerSink>(); var handleMessage = testLogger.LogEntries .Single(le => le.OriginalFormat == "Published message {MessageId} of type {MessageType} to {DestinationType} '{MessageDestination}'."); var propertyMap = new Dictionary <string, object>(handleMessage.Properties); propertyMap.ShouldContainKeyAndValue("MessageId", message.Id); propertyMap.ShouldContainKeyAndValue("MessageType", message.GetType().FullName); propertyMap.ShouldContainKeyAndValue("DestinationType", "Queue"); propertyMap.ShouldContainKey("MessageDestination"); cts.Cancel(); }
public void SaveIconToReporting_Should_ExecuteQuery() { // Arrange var actualQueryExecute = string.Empty; IDictionary <string, object> actualParameters = new Dictionary <string, object>(); var list = new ShimSPList() { IDGet = () => DummyGuid, ParentWebGet = () => new ShimSPWeb() }; ShimGridGanttSettings.ConstructorSPList = (sender, listParam) => sender.ListIcon = DummyIcon; ShimQueryExecutor.ConstructorSPWeb = (sender, web) => new ShimQueryExecutor(); ShimQueryExecutor.AllInstances.ExecuteReportingDBNonQueryStringIDictionaryOfStringObject = (sender, query, parameters) => { actualQueryExecute = query; actualParameters = parameters; }; // Act ListCommands.SaveIconToReporting(list); // Assert this.ShouldSatisfyAllConditions( () => actualQueryExecute.ShouldBe(@"INSERT INTO ReportListIds (Id, ListIcon) VALUES (@Id, @Icon)"), () => actualParameters.Count.ShouldBe(2), () => actualParameters.ShouldContainKeyAndValue("@Id", DummyGuid), () => actualParameters.ShouldContainKeyAndValue("@Icon", DummyIcon)); }
private static void ValidateToggle(Dictionary <string, object> toggle, string name, string expectedID) { toggle.ShouldSatisfyAllConditions( () => toggle.ShouldContainKeyAndValue("id", expectedID), () => toggle.ShouldContainKeyAndValue("name", name), () => toggle.ShouldContainKeyAndValue("description", ToggleDescription) ); }
public async Task HandleMessageFromQueueLogs_ShouldHaveContext(bool handlerShouldSucceed, LogLevel level, string status, string exceptionMessage) { var handler = new InspectableHandler <SimpleMessage>() { ShouldSucceed = handlerShouldSucceed, }; if (exceptionMessage != null) { handler.OnHandle = msg => throw new Exception(exceptionMessage); } var services = GivenJustSaying(levelOverride: LogLevel.Information) .ConfigureJustSaying( (builder) => builder.WithLoopbackQueue <SimpleMessage>(UniqueName) .Subscriptions(sub => sub.WithDefaults(sgb => sgb.WithDefaultConcurrencyLimit(10)))) .AddSingleton <IHandlerAsync <SimpleMessage> >(handler); var sp = services.BuildServiceProvider(); var cts = new CancellationTokenSource(); var publisher = sp.GetRequiredService <IMessagePublisher>(); await publisher.StartAsync(cts.Token); await sp.GetRequiredService <IMessagingBus>().StartAsync(cts.Token); var message = new SimpleMessage(); await publisher.PublishAsync(message, cts.Token); await Patiently.AssertThatAsync(() => handler.ReceivedMessages .ShouldHaveSingleItem() .Id.ShouldBe(message.Id)); var testLogger = sp.GetRequiredService <ITestLoggerSink>(); await Patiently.AssertThatAsync(() => { var handleMessage = testLogger.LogEntries .SingleOrDefault(le => le.OriginalFormat == "{Status} handling message with Id '{MessageId}' of type {MessageType} in {TimeToHandle}ms."); handleMessage.ShouldNotBeNull(); handleMessage.LogLevel.ShouldBe(level); handleMessage.Exception?.Message.ShouldBe(exceptionMessage); var propertyMap = new Dictionary <string, object>(handleMessage.Properties); propertyMap.ShouldContainKeyAndValue("Status", status); propertyMap.ShouldContainKeyAndValue("MessageId", message.Id); propertyMap.ShouldContainKeyAndValue("MessageType", message.GetType().FullName); propertyMap.ShouldContainKey("TimeToHandle"); }); cts.Cancel(); }
public void DictionaryTest() { var source = new Dictionary <string, string>() { { "en-GB", "british description" }, { "da-DK", "dansk beskrivelse" } }; var destination = new Dictionary <string, string>(); _mapper.Map(source, destination); destination.Count.ShouldBe(2); destination.ShouldContainKeyAndValue("en-GB", "british description"); destination.ShouldContainKeyAndValue("da-DK", "dansk beskrivelse"); }
public void ShouldContainKeyAndValue_WorkWithGuids() { var guiddy = Guid.NewGuid(); var dictionary = new Dictionary<string, Guid>(); dictionary.Add("key", guiddy); dictionary.ShouldContainKeyAndValue("key", guiddy); }
public void ValueIsNullShouldFail() { var dictionaryWithNullValue = new Dictionary <MyThing, MyThing> { { ThingKey, null } }; Verify.ShouldFail(() => dictionaryWithNullValue.ShouldContainKeyAndValue(ThingKey, new MyThing(), "Some additional context"), errorWithSource: @"dictionaryWithNullValue should contain key Shouldly.Tests.TestHelpers.MyThing (000000) with value Shouldly.Tests.TestHelpers.MyThing (000000) but value was null Additional Info: Some additional context", errorWithoutSource: @"[[Shouldly.Tests.TestHelpers.MyThing (000000) => null]] should contain key Shouldly.Tests.TestHelpers.MyThing (000000) with value Shouldly.Tests.TestHelpers.MyThing (000000) but value was null Additional Info: Some additional context"); }
public void Should_implicit_cast_property_set_to_dictionary() { var propertySet = new PropertySet { new Property("P1", 1), new Property("P2", "2"), new Property("P3", null), }; Dictionary <string, object> dictionary = propertySet; dictionary.Count.ShouldBe(3); dictionary.ShouldContainKeyAndValue("P1", 1); dictionary.ShouldContainKeyAndValue("P2", "2"); dictionary.ShouldContainKeyAndValue("P3", null); }
public void ShouldContainKeyAndValue_ShouldWorkWithObjects() { var guid = Guid.NewGuid(); var dictionary2 = new Dictionary<string, Guid> {{"key", guid}}; dictionary2.ShouldContainKeyAndValue("key", guid); }
public void ShouldContainKeyAndValue_WhenTrue_ShouldNotThrow() { var dictionary = new Dictionary <string, string> { { "key", "value" } }; dictionary.ShouldContainKeyAndValue("key", "value"); }
public void ShouldContainKeyAndValue_WorkWithGuids() { var guiddy = Guid.NewGuid(); var dictionary = new Dictionary <string, Guid> { { "key", guiddy } }; dictionary.ShouldContainKeyAndValue("key", guiddy); }
public void IterationShouldWalkThroughAllKnownAndExtraKeyValuePairs() { var requestContext = new RequestContext(); var custom = new Object(); _env["System.Web.Routing.RequestContext"] = requestContext; _env["Custom"] = custom; var dict = new Dictionary <string, object>(); foreach (var kv in _env) { dict.Add(kv.Key, kv.Value); } dict.ShouldContainKeyAndValue("System.Web.Routing.RequestContext", requestContext); dict.ShouldContainKeyAndValue("Custom", custom); }
public void ShouldCallAnObjectCreatedCallbackInAMemberCollectionConditionally() { using (var mapper = Mapper.CreateNew()) { var sourceAddressesByIndex = new Dictionary <int, Address>(); mapper.WhenMapping .From <Person>() .Over <Customer>() .After .CreatingInstancesOf <Address>() .If((p, c, o, i) => i >= 1) .Call((p, c, o, i) => sourceAddressesByIndex[i.GetValueOrDefault()] = o); var source = new PublicField <Collection <Person> > { Value = new Collection <Person> { new Person { Id = Guid.NewGuid(), Name = "Person 0" }, new Person { Id = Guid.NewGuid(), Name = "Person 1", Address = new Address { Line1 = "My house" } }, new Person { Id = Guid.NewGuid(), Name = "Person 1", Address = new Address { Line1 = "Your house" } } } }; var target = new PublicProperty <IEnumerable> { Value = new[] { new Person { Id = source.Value.First().Id }, new Customer { Id = source.Value.Second().Id }, new Person { Id = source.Value.Third().Id } } }; var result = mapper.Map(source).Over(target); var resultItems = result.Value.Cast <Person>().ToArray(); resultItems.Length.ShouldBe(3); sourceAddressesByIndex.Count.ShouldBe(1); sourceAddressesByIndex.ShouldContainKeyAndValue(1, resultItems.Second().Address); } }
public void ShouldContainKeyAndValue() { DocExampleWriter.Document(() => { var websters = new Dictionary<string, string>(); websters.Add("Cromulent", "I never heard the word before moving to Springfield."); websters.ShouldContainKeyAndValue("Cromulent", "Fine, acceptable."); }, _testOutputHelper); }
public void ShouldContainKeyAndValue() { DocExampleWriter.Document(() => { var websters = new Dictionary <string, string>(); websters.Add("Cromulent", "I never heard the word before moving to Springfield."); websters.ShouldContainKeyAndValue("Cromulent", "Fine, acceptable."); }, _testOutputHelper); }
public void WorksAsDictionaryKey() { // arrange var dictionary = new Dictionary <NamespacedName, string>(); var name1 = new NamespacedName("ns", "n1"); var name2 = new NamespacedName("ns", "n2"); var name3 = new NamespacedName("ns", "n3"); // act dictionary[name1] = "one"; dictionary[name1] = "one again"; dictionary[name2] = "two"; // assert dictionary.ShouldSatisfyAllConditions( () => dictionary.ShouldContainKeyAndValue(name1, "one again"), () => dictionary.ShouldContainKeyAndValue(name2, "two"), () => dictionary.ShouldNotContainKey(name3)); }
public void ShouldCallAnObjectCreatingCallbackInAMemberEnumerable() { using (var mapper = Mapper.CreateNew()) { var sourceObjectTypesByIndex = new Dictionary <int, Type>(); mapper.WhenMapping .From <Person>() .ToANew <PersonViewModel>() .Before .CreatingInstances .Call((p, pvm, i) => sourceObjectTypesByIndex[i.GetValueOrDefault()] = p.GetType()); var source = new[] { new Person(), new Customer() }; var result = mapper.Map(source).ToANew <ICollection <PersonViewModel> >(); result.Count.ShouldBe(2); sourceObjectTypesByIndex.ShouldContainKeyAndValue(0, typeof(Person)); sourceObjectTypesByIndex.ShouldContainKeyAndValue(1, typeof(Customer)); } }
public void ShouldReturnEmptyWhenValidCurrencyAndNumeral() { // arrange var textToTest = "test is V"; var currencies = new Dictionary <string, string>(); var rule = new CurrencyAssignmentParsingRule(); // act var result = rule.Process(textToTest, currencies, null); // assert result.ShouldBe(string.Empty); currencies.ShouldContainKeyAndValue("test", "V"); }
public void ShouldCallAnObjectCreatingCallbackInARootEnumerableConditionally() { using (var mapper = Mapper.CreateNew()) { var createdAddressesByIndex = new Dictionary <int, string>(); mapper.WhenMapping .From <PersonViewModel>() .ToANew <Person>() .Before .CreatingInstancesOf <Address>() .If((s, t, i) => (i == 1) || (i == 2)) .Call(ctx => createdAddressesByIndex[ctx.EnumerableIndex.GetValueOrDefault()] = ctx.Source.AddressLine1); var source = new[] { new PersonViewModel { AddressLine1 = "Zero!" }, new PersonViewModel { AddressLine1 = "One!" }, new PersonViewModel { AddressLine1 = "Two!" } }; var result = mapper.Map(source).ToANew <Person[]>(); result.Select(p => p.Address.Line1).ShouldBe("Zero!", "One!", "Two!"); createdAddressesByIndex.ShouldNotContainKey(0); createdAddressesByIndex.ShouldContainKeyAndValue(1, "One!"); createdAddressesByIndex.ShouldContainKeyAndValue(2, "Two!"); } }
public void ShouldReturnEmptyStringAndHaveMaterialsUpdated() { // arrange var textToTest = "curr material is 500 credits"; var materials = new Dictionary <string, float>(); var currencies = new Dictionary <string, string> { { "curr", "X" } }; var rule = new MaterialAssignmentParsingRule(); // act var result = rule.Process(textToTest, currencies, materials); // assert result.ShouldBe(string.Empty); materials.ShouldContainKeyAndValue("material", 50f); }
public void SaveSettings_UpdateJob_DaoUpdateLabelErrorVisibleFalse() { // Arrange var actualParam = new Dictionary <string, object>(); var actualLogStatusCalled = false; DefaultPageInit(); _shimDao.ExecuteNonQuerySqlConnection = sqlConnection => true; _shimDao.AddParamStringObject = (nameParam, valueParam) => actualParam.Add(nameParam, valueParam); _shimDao.SqlErrorOccurredGet = () => true; _shimDao.LogStatusStringStringStringStringInt32Int32String = ( rptListId, listName, shortMsg, longMsg, level, typeParam, timerJobGuid) => { actualLogStatusCalled = true; return(true); }; var currentWeb = new ShimSPWeb() { IDGet = () => DummyGuid, SiteGet = () => new ShimSPSite() { IDGet = () => DummyGuid2 } }; // Act _privateObject.Invoke(SaveSettingsMethodName, currentWeb.Instance); // Assert LoadFields(); this.ShouldSatisfyAllConditions( () => _actualCommand.ShouldBe(UpdateTimerJobs), () => actualParam.ShouldContainKeyAndValue($"@{JobNameField}", DummyJobName), () => actualParam.ShouldContainKeyAndValue($"@{EnabledField}", true), () => actualParam.ShouldContainKeyAndValue($"@{RunTimeField}", 1), () => actualParam.ShouldContainKeyAndValue($"@{ScheduleTypeField}", 2), () => actualParam.ShouldContainKeyAndValue($"@{DaysField}", "3"), () => actualParam.ShouldContainKeyAndValue($"@{JobDataField}", DummyListName), () => _labelErrorSite.Visible.ShouldBeFalse(), () => actualLogStatusCalled.ShouldBeTrue()); }
public void ValueIsNullShouldFail() { var dictionaryWithNullValue = new Dictionary<MyThing, MyThing> { {ThingKey, null} }; Verify.ShouldFail(() => dictionaryWithNullValue.ShouldContainKeyAndValue(ThingKey, new MyThing(), "Some additional context"), errorWithSource: @"dictionaryWithNullValue should contain key Shouldly.Tests.TestHelpers.MyThing (000000) with value Shouldly.Tests.TestHelpers.MyThing (000000) but value was null Additional Info: Some additional context", errorWithoutSource: @"[[Shouldly.Tests.TestHelpers.MyThing (000000) => null]] should contain key Shouldly.Tests.TestHelpers.MyThing (000000) with value Shouldly.Tests.TestHelpers.MyThing (000000) but value was null Additional Info: Some additional context"); }
protected override void ShouldThrowAWobbly() { _dictionary.ShouldContainKeyAndValue("bar", "baz"); }
protected override void ShouldThrowAWobbly() { _dictionary.ShouldContainKeyAndValue("Foo", "baz", "Some additional context"); }
protected override void ShouldThrowAWobbly() { _dictionary.ShouldContainKeyAndValue(ThingKey, new MyThing(), "Some additional context"); }
public void ShouldContainKeyAndValue_WhenTrue_ShouldNotThrow() { var dictionary = new Dictionary<string, string>(); dictionary.Add("key", "value"); dictionary.ShouldContainKeyAndValue("key","value"); }
public void SaveSettings_AddNewJob_DaoInsertLabelErrorVisibleFalse() { // Arrange var actualParam = new Dictionary <string, object>(); DefaultPageInit(); ShimPage.AllInstances.RequestGet = sender => new ShimHttpRequest() { QueryStringGet = () => new NameValueCollection() { { UidField, null } } }; _shimDao.ExecuteNonQuerySqlConnection = sqlConnection => true; _shimDao.AddParamStringObject = (nameParam, valueParam) => actualParam.Add(nameParam, valueParam); var currentWeb = new ShimSPWeb() { IDGet = () => DummyGuid, SiteGet = () => new ShimSPSite() { IDGet = () => DummyGuid2 } }; // Act _privateObject.Invoke(SaveSettingsMethodName, currentWeb.Instance); // Assert LoadFields(); this.ShouldSatisfyAllConditions( () => _actualCommand.ShouldBe(InsertTimerJobs), () => actualParam.ShouldContainKey($"@{TimeJobUidField}"), () => actualParam[$"@{TimeJobUidField}"].ShouldBeOfType <Guid>(), () => actualParam.ShouldContainKeyAndValue($"@{JobNameField}", DummyJobName), () => actualParam.ShouldContainKeyAndValue($"@{SiteGuidField}", DummyGuid2), () => actualParam.ShouldContainKeyAndValue($"@{WebGuidField}", DummyGuid), () => actualParam.ShouldContainKeyAndValue($"@{ListGuidField}", DBNull.Value), () => actualParam.ShouldContainKeyAndValue($"@{JobTypeField}", 7), () => actualParam.ShouldContainKeyAndValue($"@{EnabledField}", true), () => actualParam.ShouldContainKeyAndValue($"@{RunTimeField}", 1), () => actualParam.ShouldContainKeyAndValue($"@{ScheduleTypeField}", 2), () => actualParam.ShouldContainKeyAndValue($"@{DaysField}", "3"), () => actualParam.ShouldContainKeyAndValue($"@{JobDataField}", DummyListName), () => actualParam.ShouldContainKeyAndValue($"@{LastQueueCheckField}", DBNull.Value), () => actualParam.ShouldContainKeyAndValue($"@{ParentJobUidField}", DBNull.Value), () => _labelErrorSite.Visible.ShouldBeFalse()); }
protected override void ShouldThrowAWobbly() { _dictionary.ShouldContainKeyAndValue(_missingGuidKey, _missingGuidValue); }
protected override void ShouldThrowAWobbly() { _dictionary.ShouldContainKeyAndValue(ThingKey, new MyThing()); }
public void IterationShouldWalkThroughAllKnownAndExtraKeyValuePairs() { var requestContext = new RequestContext(); var custom = new Object(); _env["System.Web.Routing.RequestContext"] = requestContext; _env["Custom"] = custom; var dict = new Dictionary<string, object>(); foreach (var kv in _env) { dict.Add(kv.Key, kv.Value); } dict.ShouldContainKeyAndValue("System.Web.Routing.RequestContext", requestContext); dict.ShouldContainKeyAndValue("Custom", custom); }
public void ShouldContainKey() { var websters = new Dictionary<string, string>(); websters.Add("Chazzwazzers", "What Australians would have called a bull frog."); websters.ShouldContainKeyAndValue("Chazzwazzers", "What Australians would have called a bull frog."); }
protected override void ShouldThrowAWobbly() { _dictionary.ShouldContainKeyAndValue(_missingGuidKey, _missingGuidValue, "Some additional context"); }