public void CreateUserUsingDependencyInjectionTest() { TestHelper.SetUpCleanTestQueue(); var queueProvider = new MsmqStoreProvider<User>() as IStoreProvider<User>; var PubSubChannel = new PublishSubscribeChannel<User>(queueProvider) as IPublishSubscribeChannel<User>; PubSubChannel.AddSubscriberType(typeof(TestSubscriberZZZ<User>)); UserManagerServiceAdaptor target = new UserManagerServiceAdaptor(queueProvider, PubSubChannel); User umToUpdate = new User(); umToUpdate.FirstName = "X"; umToUpdate.LastName = "LastName"; umToUpdate.UserName = "******"; target.Create(umToUpdate); //need to assert something }
public void HandleMessageForFirstTime_ExceptionThrownMessageTest_WithFakeStoreProvider() { TestUtils.TestHelper.Subscriber1Ran = new AutoResetEvent(false); TestUtils.TestHelper.Subscriber2Ran = new AutoResetEvent(false); TestUtils.TestHelper.Subscriber3Ran = new AutoResetEvent(false); TestUtils.TestHelper.UpdateMessageStoreEvent = new AutoResetEvent(false); TestUtils.TestHelper.SubscriberGroupCompletedEvent = new AutoResetEvent(false); var m = new Message { Name = "MyMessage" }; var messagePacket = TestUtils.TestHelper.BuildAMessage<Message>(m) .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriber<Message>), false, false) .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>), false, false).GetMessage(); List<MessagePacket<Message>> outputPostProcessMP = new List<MessagePacket<Message>>(); string outputMessageId = string.Empty; DateTime timelastupdateCalled = default(DateTime); DateTime timeGroupCompletedCalled = default(DateTime); var MessagePubSubChannel = new PublishSubscribeChannel<Message>(); var stubStoreProvider = new StubIStoreProvider<Message> { UpdateMessageStoreMessagePacketOfT0 = UpdatedMessagepacket => { outputPostProcessMP.Add(UpdatedMessagepacket); timelastupdateCalled = DateTime.Now; TestUtils.TestHelper.UpdateMessageStoreEvent.Set(); return; }, SubscriberGroupCompletedForMessageString = messageId => { Assert.IsTrue(messagePacket.MessageId.ToString() == messageId); timeGroupCompletedCalled = DateTime.Now; TestUtils.TestHelper.SubscriberGroupCompletedEvent.Set(); return true; }, }; MessagePubSubChannel.StorageProvider = stubStoreProvider; MessagePubSubChannel.AddSubscriberType(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1)) .AddSubscriberType(typeof(TestUtils.SpeedySubscriber<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1)); MessagePubSubChannel.HandleMessageForFirstTime(messagePacket, messagePacket.MessageId.ToString()); TestUtils.TestHelper.Subscriber1Ran.WaitOne(); TestUtils.TestHelper.Subscriber3Ran.WaitOne(); TestUtils.TestHelper.UpdateMessageStoreEvent.WaitOne(); TestUtils.TestHelper.SubscriberGroupCompletedEvent.WaitOne(); foreach (var item in outputPostProcessMP) { Assert.IsTrue(item.MessageId == messagePacket.MessageId); Assert.IsTrue(item.SubscriberMetadataList.Count == 1); if (item.SubscriberMetadataList[0].Name.Contains("SpeedySubscriberGuaranteedExceptions")) { Assert.IsTrue(item.SubscriberMetadataList[0].FailedOrTimedOut == true); } else { Assert.IsTrue(item.SubscriberMetadataList[0].FailedOrTimedOut == false); } } Trace.WriteLine("timelastupdateCalled: " + timelastupdateCalled.TimeOfDay); Trace.WriteLine("timeGroupCompletedCa: " + timeGroupCompletedCalled.TimeOfDay); Assert.IsTrue(DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) < 0 || DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) == 0); }
public void ProcessBatch_Subscriberfails_WithFakeStoreProvider() { TestUtils.TestHelper.autoEvent = new AutoResetEvent(false); var m = new Message(); var messagePacket = TestUtils.TestHelper.BuildAMessage<Message>(m) .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>), false, false).GetMessage(); var beforeRetryCount = messagePacket.SubscriberMetadataList[0].RetryCount; MessagePacket<Message> outputPostProcessMP = default(MessagePacket<Message>); string outputMessageId = string.Empty; var MessagePubSubChannel = new PublishSubscribeChannel<Message>(); var stubStoreProvider = new StubIStoreProvider<Message> { ProcessStoreAsBatchFuncOfMessagePacketOfT0StringBoolean = funct => MessagePubSubChannel.HandleMessageForBatchProcessing(messagePacket, messagePacket.MessageId.ToString()), UpdateMessageStoreMessagePacketOfT0 = UpdatedMessagepacket => { outputPostProcessMP = UpdatedMessagepacket; TestUtils.TestHelper.autoEvent.Set(); return; }, SubscriberGroupCompletedForMessageString = messageId => { Assert.IsTrue(messagePacket.MessageId.ToString() == messageId); return true; } }; MessagePubSubChannel.StorageProvider = stubStoreProvider; MessagePubSubChannel.AddSubscriberType(typeof(TestUtils.SpeedySubscriberGuaranteedExceptions<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 0, 1)); MessagePubSubChannel.ProcessBatch(); TestUtils.TestHelper.autoEvent.WaitOne(); //new TimeSpan(0, 0, 0, 5, 0) Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList[0].RetryCount == messagePacket.SubscriberMetadataList[0].RetryCount + 1); Assert.IsTrue(outputPostProcessMP.MessageId == messagePacket.MessageId); Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList.Count == 1); Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList[0].FailedOrTimedOut == true); }
public void HandleMessageForFirstTime_MessageTest_WithFakeStoreProvider() { TestUtils.TestHelper.Subscriber1Ran = new AutoResetEvent(false); TestUtils.TestHelper.Subscriber2Ran = new AutoResetEvent(false); TestUtils.TestHelper.Subscriber3Ran = new AutoResetEvent(false); TestUtils.TestHelper.UpdateMessageStoreEvent = new AutoResetEvent(false); TestUtils.TestHelper.SubscriberGroupCompletedEvent = new AutoResetEvent(false); var m = new Message { Name = "MyMessage"}; var messagePacket = TestUtils.TestHelper.BuildAMessage<Message>(m) .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriber<Message>), false, false) .WithSubscriberMetadataFor(typeof(TestUtils.SpeedySubscriber2<Message>), false, false).GetMessage(); MessagePacket<Message> outputPostProcessMP = default(MessagePacket<Message>); string outputMessageId = string.Empty; DateTime timelastupdateCalled = default(DateTime); DateTime timeGroupCompletedCalled = default(DateTime); var MessagePubSubChannel = new PublishSubscribeChannel<Message>(); var stubStoreProvider = new StubIStoreProvider<Message> { UpdateMessageStoreMessagePacketOfT0 = UpdatedMessagepacket => { outputPostProcessMP = UpdatedMessagepacket; timelastupdateCalled = DateTime.Now; TestUtils.TestHelper.UpdateMessageStoreEvent.Set(); return; }, SubscriberGroupCompletedForMessageString = messageId => { Assert.IsTrue(messagePacket.MessageId.ToString() == messageId); timeGroupCompletedCalled = DateTime.Now; TestUtils.TestHelper.SubscriberGroupCompletedEvent.Set(); return true; } }; MessagePubSubChannel.StorageProvider = stubStoreProvider; MessagePubSubChannel.AddSubscriberType(typeof(TestUtils.SpeedySubscriber2<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1)) .AddSubscriberType(typeof(TestUtils.SpeedySubscriber<Message>)).WithTimeToExpire(new TimeSpan(0, 0, 1, 1)); MessagePubSubChannel.HandleMessageForFirstTime(messagePacket, messagePacket.MessageId.ToString()); TestUtils.TestHelper.Subscriber1Ran.WaitOne(); TestUtils.TestHelper.Subscriber2Ran.WaitOne(); TestUtils.TestHelper.UpdateMessageStoreEvent.WaitOne(); TestUtils.TestHelper.SubscriberGroupCompletedEvent.WaitOne(); Assert.IsTrue(outputPostProcessMP.MessageId == messagePacket.MessageId); Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList.Count == 1); Assert.IsTrue(outputPostProcessMP.SubscriberMetadataList[0].FailedOrTimedOut == false); Assert.IsTrue(DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) < 0 || DateTime.Compare(timelastupdateCalled, timeGroupCompletedCalled) == 0); }