public void CanPublishWithinTransactionScopeWhenProvidingDefaultConnectionHolder() { // arrange var subscriptionStorage = new SqlServerSubscriptionStorage(ConnectionString, SubscriptionsTableName); subscriptionStorage.EnsureTableIsCreated(); var publisher = CreateBus(PublisherInputQueueName, subscriptionStorage); var subReceivedEvents = new List<int>(); var sub = CreateBus(SubscriberInputQueueName, subscriptionStorage) .Handle<SomeEvent>(e => subReceivedEvents.Add(e.EventNumber)); sub.Bus.Subscribe<SomeEvent>(); // act Thread.Sleep(1.Seconds()); using (var scope = new TransactionScope()) { publisher.Bus.Publish(new SomeEvent { EventNumber = 1 }); scope.Complete(); } Thread.Sleep(1.Seconds()); // assert subReceivedEvents.ShouldBe(new[] { 1 }.ToList()); }
public void given_zero_test_data_rows_should_return_same_scenarios() { scenarios.ForEach(s => (s as Scenario).TestDataRows = new List<TestData>()); built = builder.Build(scenarios); built.ShouldBe(scenarios); }
public void WhenFoo() { var foo = new Foo(); IList<IFoo> a = new List<IFoo>(); a.Add(foo); a.ShouldBe(new IFoo[] { foo }); }
public void ShouldBeSameAs_WhenEqualListsButDifferentReferences_ShouldChuckAWobbly() { var list = new List<int>(); var equalListWithDifferentRef = new List<int>(); list.ShouldBe(equalListWithDifferentRef); ShouldChuck(() => list.ShouldBeSameAs(equalListWithDifferentRef)); list.ShouldNotBeSameAs(equalListWithDifferentRef); }
public void ShouldCopyItems() { var list1 = new List<int> {2, 3, 4}; var list2 = new List<int> {1, 3, 5}; list1.CopyItemsFrom(list2); list1.ShouldBe(new List<int> {3, 1, 5}); }
public void ShouldBeSameAs_WhenEqualListsButDifferentReferences_ShouldThrow() { var list = new List<int> { 1, 2, 3 }; var equalListWithDifferentRef = new List<int> { 1, 2, 3 }; list.ShouldBe(equalListWithDifferentRef); Should.Error( () => list.ShouldBeSameAs(equalListWithDifferentRef), "() => list should be same as [1, 2, 3] but was [1, 2, 3] difference [1, 2, 3]" ); list.ShouldNotBeSameAs(equalListWithDifferentRef); }
public void ShouldBeSameAs_WhenEqualListsButDifferentReferences_ShouldFail() { var list = new List<int> { 1, 2, 3 }; var equalListWithDifferentRef = new List<int> { 1, 2, 3 }; list.ShouldBe(equalListWithDifferentRef); TestHelper.ShouldFailWithError( () => list.ShouldBeSameAs(equalListWithDifferentRef), "list should be same as {1, 2, 3} but was {1, 2, 3} difference {1, 2, 3}" ); list.ShouldNotBeSameAs(equalListWithDifferentRef); }
public void Docs() { var apu = new Person { Name = "Apu" }; var homer = new Person { Name = "Homer" }; var skinner = new Person { Name = "Skinner" }; var barney = new Person { Name = "Barney" }; var theBeSharps = new List<Person> { homer, skinner, barney }; TestHelpers.Should.Error(() => theBeSharps.ShouldBe(new[] {apu, homer, skinner, barney}), @"theBeSharps should be [Apu, Homer, Skinner, Barney] but was [Homer, Skinner, Barney] difference [*Homer *, *Skinner *, *Barney *, *]"); }
public void ordering_follows_specification() { var expected = new List<SemanticVersion> { v("1.0.0-alpha"), v("1.0.0-alpha.1"), v("1.0.0-beta.2"), v("1.0.0-beta.11"), v("1.0.0-rc.1"), v("1.0.0-rc.1+build.1"), v("1.0.0"), v("1.0.0+0.3.7"), v("1.3.7+build"), v("1.3.7+build.2.b8f12d7"), v("1.3.7+build.11.e0f985a") }; var actual = new List<SemanticVersion>(expected); actual.Sort(); actual.ShouldBe(expected); }
public void SeeIfItWorks(int workers, int iterations) { var receivedStrings = new List<string>(); using (var adapter1 = new BuiltinContainerAdapter()) using (var adapter2 = new BuiltinContainerAdapter()) { adapter1.Handle<ThisIsJustSomeRandomTestMessage>(msg => receivedStrings.Add(msg.WithSomethingInside)); var bus1 = (RebusBus) Configure.With(adapter1) .Transport(x => x.UseRabbitMq(ConnectionString, InputQueueName1, ErrorQueueName) .ManageSubscriptions()) .CreateBus(); bus1.Start(workers); bus1.Subscribe<ThisIsJustSomeRandomTestMessage>(); var bus2 = (RebusBus) Configure.With(adapter2) .Transport(x => x.UseRabbitMq(ConnectionString, InputQueueName2, ErrorQueueName) .ManageSubscriptions()) .CreateBus(); bus2.Start(1); var messageCounter = 1; iterations.Times(() => { Thread.Sleep(TimeSpan.FromSeconds(2)); bus2.Publish(new ThisIsJustSomeRandomTestMessage{WithSomethingInside=string.Format("Message number {0}", messageCounter++)}); }); Thread.Sleep(TimeSpan.FromSeconds(5)); } receivedStrings.ShouldBe(Enumerable.Range(1, iterations) .Select(i => string.Format("Message number {0}", i)) .ToList()); }
public void CanSubscribeAndUnsubscribeWithAdvancedApi() { // arrange var publisher = CreateBus(PublisherInputQueueName, new HandlerActivatorForTesting()).Start(1); var sub1ReceivedEvents = new List<int>(); var sub2ReceivedEvents = new List<int>(); var sub1 = CreateBus(Subscriber1InputQueueName, new HandlerActivatorForTesting() .Handle<SomeEvent>(e => sub1ReceivedEvents.Add(e.EventNumber))).Start(1); var sub2 = CreateBus(Subscriber2InputQueueName, new HandlerActivatorForTesting() .Handle<SomeEvent>(e => sub2ReceivedEvents.Add(e.EventNumber))).Start(1); // act sub1.Advanced.Routing.Subscribe(typeof(SomeEvent)); sub2.Advanced.Routing.Subscribe(typeof(SomeEvent)); Thread.Sleep(1.Seconds()); publisher.Publish(new SomeEvent{EventNumber=1}); publisher.Batch.Publish(new[] { new SomeEvent { EventNumber = 2 }, new SomeEvent { EventNumber = 3 } }); Thread.Sleep(1.Seconds()); sub1.Advanced.Routing.Unsubscribe(typeof(SomeEvent)); Thread.Sleep(1.Seconds()); publisher.Publish(new SomeEvent { EventNumber = 4 }); publisher.Batch.Publish(new[] { new SomeEvent { EventNumber = 5 }, new SomeEvent { EventNumber = 6 } }); Thread.Sleep(200); // assert sub1ReceivedEvents.ShouldBe(new[] {1, 2, 3}.ToList()); sub2ReceivedEvents.ShouldBe(new[] {1, 2, 3, 4, 5, 6}.ToList()); }
public void ShouldBeAbleToInterceptWithMultipleInterceptors() { var list = new List<int>(); var proxy = new ProxyBase { backingObject = new InterceptedFace(list), interceptors = new IInterceptor[] { new TailInterceptor(list), new FaceInterceptor(list) } }; var invocation = new Invocation(proxy.interceptors); invocation.Start(typeof(IFace).GetMethods()[0], new object[0], args => (proxy.backingObject as IFace).Foo()); invocation.ReturnValue.ShouldBe(10); list.ShouldBe(new List<int>{0,1,2,3,4}); }
public void List() { var result = new List<string> { "hello", "world" }.ToJson(); result.ShouldBe("[\"hello\", \"world\"]"); }
public void ShouldPutItAllTogetherWhenPassedAType() { var list = new List<int>(); var blah = (IFace)generator.GenerateProxy(typeof(IFace), new InterceptedFace(list), new IInterceptor[] { new TailInterceptor(list), new FaceInterceptor(list) }); blah.Foo().ShouldBe(10); list.ShouldBe(new List<int> { 0, 1, 2, 3, 4 }); }
public void ShouldPutItAllTogether() { var list = new List<int>(); var blah = generator.GenerateProxy<IFace>(new InterceptedFace(list), new IInterceptor[] {new TailInterceptor(list), new FaceInterceptor(list)}); blah.Foo().ShouldBe(10); list.ShouldBe(new List<int>{0,1,2,3,4}); }
public void ShouldBeAbleToInterceptProperties() { var list = new List<int>(); var blah = generator.GenerateProxy<IFoo>(new Blah(), new TailInterceptor(list)); blah.Name = "Braindead"; blah.Name.ShouldBe("Braindead"); list.ShouldBe(new List<int>{0,4,0,4}); }