public void for_each_property_invokes_action_on_each_property() { var props = new List<string>(); _cache.ForEachProperty(typeof(Item), p=>props.Add(p.Name)); props.ShouldHaveCount(2); props.ShouldContain("Property1"); props.ShouldContain("Property2"); props.ShouldNotContain("NonWriteProp"); }
public void RegisterService_can_be_called_multiple_times_to_store_multiple_implementations() { var graph = new BehaviorGraph(null); graph.Services.AddService<IRequestData, RequestData>(); graph.Services.AddService<IRequestData, InMemoryRequestData>(); var implementations = new List<Type>(); graph.EachService((t, def) => { if (t == typeof (IRequestData)) implementations.Add(def.Type); }); implementations.ShouldContain(typeof (RequestData)); implementations.ShouldContain(typeof (InMemoryRequestData)); }
public void ShouldActAsAnEvenFilter() { var source = new ObservableCollection<int>(); var dest = new List<int>(); source.PushChangesTo(dest).If(NumberIsEven); source.Add(1); dest.ShouldNotContain(1); source.Add(2); dest.ShouldContain(2); source.Remove(2); dest.ShouldNotContain(2); dest.Add(1); source.Remove(1); dest.ShouldContain(1); }
public void ShouldOnlyAddEvenNumbers() { var source = new ObservableCollection<int>(); var dest = new List<int>(); source.PushChangesTo(dest).AddOnlyIf(NumberIsEven); source.Add(1); dest.ShouldNotContain(1); source.Add(2); dest.ShouldContain(2); }
public void should_resend_existing_bindings_when_making_a_new_subscription_to_a_type() { AddInvoker<FakeRoutableCommand>(shouldBeSubscribedOnStartup: false); _bus.Subscribe(Subscription.ByExample(x => new FakeRoutableCommand(1, "firstRoutingValue"))); var subscriptions = new List<SubscriptionsForType>(); _directoryMock.CaptureEnumerable((IBus)_bus, (x, bus, items) => x.UpdateSubscriptions(bus, items), subscriptions); _bus.Start(); _bus.Subscribe(Subscription.ByExample(x => new FakeRoutableCommand(1, "secondRoutingValue"))); subscriptions.Count.ShouldEqual(1); subscriptions.ShouldContain(new SubscriptionsForType(MessageUtil.TypeId<FakeRoutableCommand>(), new BindingKey("1", "firstRoutingValue", "*"), new BindingKey("1", "secondRoutingValue", "*"))); }
public void should_subscribe_to_message_but_not_resend_existing_subscriptions() { AddInvoker<FakeCommand>(shouldBeSubscribedOnStartup: true); AddInvoker<FakeRoutableCommand>(shouldBeSubscribedOnStartup: false); var subscriptions = new List<SubscriptionsForType>(); _directoryMock.CaptureEnumerable((IBus)_bus, (x, bus, items) => x.UpdateSubscriptions(bus, items), subscriptions); _bus.Start(); _bus.Subscribe(Subscription.ByExample(x => new FakeRoutableCommand(1, "name"))); subscriptions.ExpectedSingle(); subscriptions.ShouldContain(new SubscriptionsForType(MessageUtil.TypeId<FakeRoutableCommand>(), new BindingKey("1", "name", "*"))); }
public void should_subscribe_to_message_for_all_binding_keys() { AddInvoker<FakeCommand>(shouldBeSubscribedOnStartup: false); AddInvoker<FakeRoutableCommand>(shouldBeSubscribedOnStartup: false); var subscriptions = new List<SubscriptionsForType>(); _directoryMock.CaptureEnumerable((IBus)_bus, (x, bus, items) => x.UpdateSubscriptions(bus, items), subscriptions); _bus.Start(); _bus.Subscribe(Subscription.Any<FakeCommand>()); subscriptions.ExpectedSingle(); subscriptions.ShouldContain(new SubscriptionsForType(MessageUtil.TypeId<FakeCommand>(), BindingKey.Empty)); }
public void ListKeysFromIndexReturnsAllKeys() { var bucket = TestBucket + "_" + Guid.NewGuid().ToString(); var originalKeyList = new List<string>(); for (var i = 0; i < 10; i++) { var o = new RiakObject(bucket, i.ToString(), "{ value: \"this is an object\" }"); originalKeyList.Add(i.ToString()); Client.Put(o); } var result = ((RiakClient)Client).ListKeysFromIndex(bucket); var keys = result.Value; keys.Count.ShouldEqual(10); foreach (var key in keys) { originalKeyList.ShouldContain(key); } Client.DeleteBucket(bucket); }
public void HandlesExceptionsAsUsual() { var log = new List<string>(); var tries = 0; adapter.HandleAsync<SomeMessage>(async message => { tries++; Console.WriteLine("Handling"); await Task.Yield(); throw new Exception("failed"); }); var bus = StartBus(1, log, numberOfRetries: 5); bus.SendLocal(new SomeMessage()); Thread.Sleep(1000); Console.WriteLine("---------------------------------------------------------------------------"); Console.WriteLine(string.Join(Environment.NewLine, log)); Console.WriteLine("---------------------------------------------------------------------------"); log.ShouldContain(x => x.StartsWith("Rebus.Bus.RebusBus|WARN: User exception in Rebus")); tries.ShouldBe(5); }
public void ShouldContainTest() { IList<string> strings = new List<string> {"test"}; strings.ShouldContain("test"); }
public void ShouldPushChangesTo() { var source = new ObservableCollection<int>(); var dest = new List<int>(); source.PushChangesTo(dest); source.Add(1); dest.ShouldContain(1); source.Remove(1); dest.ShouldNotContain(1); }
public void ShouldPushChangesToAListGivenAMapping() { var source = new ObservableCollection<int>(); var dest = new List<float>(); source.PushChangesTo(dest).WithMapping(i => i); source.Add(1); dest.ShouldContain(1.00f); source.Remove(1); dest.ShouldNotContain(1.00f); }
public void ListKeysFromIndexReturnsAllKeys() { const int keyCount = 10; const string listKeysBucket = "listKeysBucket"; var originalKeyList = new List<string>(); for (var i = 0; i < keyCount; i++) { string idx = i.ToString(); var id = new RiakObjectId(TestBucketType, listKeysBucket, idx); var o = new RiakObject(id, "{ value: \"this is an object\" }"); originalKeyList.Add(idx); Client.Put(o); } var result = Client.ListKeysFromIndex(TestBucketType, listKeysBucket); var keys = result.Value; keys.Count.ShouldEqual(keyCount); foreach (var key in keys) { originalKeyList.ShouldContain(key); } Client.DeleteBucket(TestBucketType, listKeysBucket); }
public void StatsGetPhotostreamStatsAsyncTest() { Flickr f = TestData.GetAuthInstance(); var range = Enumerable.Range(7, 5); var list = new List<Stats>(); foreach(var i in range) { var d = DateTime.Today.AddDays(-i); var w = new AsyncSubject<FlickrResult<Stats>>(); f.StatsGetPhotostreamStatsAsync(d, r => { w.OnNext(r); w.OnCompleted(); }); var result = w.Next().First(); result.HasError.ShouldBe(false); result.Result.ShouldNotBe(null); list.Add(result.Result); } list.Count.ShouldBe(5); list.ShouldContain(s => s.Views > 0); }
public void should_not_resend_other_message_subscriptions_when_unsubscribing_from_a_message() { AddInvoker<FakeCommand>(shouldBeSubscribedOnStartup: false); AddInvoker<FakeRoutableCommand>(shouldBeSubscribedOnStartup: false); _bus.Start(); var firstSubscription = _bus.Subscribe<FakeCommand>(cmd => {}); var secondSubscription = _bus.Subscribe(Subscription.ByExample(x => new FakeRoutableCommand(1, "plop"))); var subscriptions = new List<SubscriptionsForType>(); _directoryMock.CaptureEnumerable((IBus)_bus, (x, bus, items) => x.UpdateSubscriptions(bus, items), subscriptions); firstSubscription.Dispose(); subscriptions.ExpectedSingle(); subscriptions.ShouldContain(new SubscriptionsForType(MessageUtil.TypeId<FakeCommand>())); }
public void should_unsubscribe_from_message() { AddInvoker<FakeRoutableCommand>(shouldBeSubscribedOnStartup: false); _bus.Start(); var subscription = _bus.Subscribe(Subscription.ByExample(x => new FakeRoutableCommand(1, "name"))); var subscriptions = new List<SubscriptionsForType>(); _directoryMock.CaptureEnumerable((IBus)_bus, (x, bus, items) => x.UpdateSubscriptions(bus, items), subscriptions); subscription.Dispose(); subscriptions.ShouldContain(new SubscriptionsForType(MessageUtil.TypeId<FakeRoutableCommand>())); }