Exemplo n.º 1
0
        public given_event_store_with_events_after_it_is_started()
        {
            version = "0001";
            rowKey  = "Unpublished_" + version;

            partitionKeys = Enumerable.Range(0, 200).Select(i => "Key" + i).ToArray();
            queue         = new Mock <IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(It.IsAny <string>(), It.IsAny <Action <IEnumerable <IEventRecord>, bool> >(), It.IsAny <Action <Exception> >()))
            .Callback <string, Action <IEnumerable <IEventRecord>, bool>, Action <Exception> >(
                (key, success, error) =>
                success(new[] {
                Mock.Of <IEventRecord>(
                    x => x.PartitionKey == key &&
                    x.RowKey == rowKey &&
                    x.TypeName == "TestEventType" &&
                    x.SourceId == "TestId" &&
                    x.SourceType == "TestSourceType" &&
                    x.Payload == "serialized event")
            },
                        false));

            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(Enumerable.Empty <string>());
            queue
            .Setup(x =>
                   x.DeletePendingAsync(
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <Action <bool> >(),
                       It.IsAny <Action <Exception> >()))
            .Callback <string, string, Action <bool>, Action <Exception> >((p, r, s, e) => s(true));
            sender = new MessageSenderMock();
            sut    = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            cancellationTokenSource = new CancellationTokenSource();
            sut.Start(cancellationTokenSource.Token);
        }
Exemplo n.º 2
0
        public when_calling_publish()
        {
            partitionKey = Guid.NewGuid().ToString();
            version      = "0001";
            var rowKey = "Unpublished_" + version;

            testEvent = Mock.Of <IEventRecord>(x =>
                                               x.PartitionKey == partitionKey &&
                                               x.RowKey == rowKey &&
                                               x.TypeName == "TestEventType" &&
                                               x.SourceId == "TestId" &&
                                               x.SourceType == "TestSourceType" &&
                                               x.Payload == "serialized event" &&
                                               x.CorrelationId == "correlation" &&
                                               x.AssemblyName == "Assembly" &&
                                               x.Namespace == "Namespace" &&
                                               x.FullName == "Namespace.TestEventType");
            queue = new Mock <IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(partitionKey, It.IsAny <Action <IEnumerable <IEventRecord>, bool> >(), It.IsAny <Action <Exception> >()))
            .Callback <string, Action <IEnumerable <IEventRecord>, bool>, Action <Exception> >((key, success, error) => success(new[] { testEvent }, false));
            sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            var cancellationTokenSource = new CancellationTokenSource();

            sut.Start(cancellationTokenSource.Token);

            sut.SendAsync(partitionKey, 0);

            Assert.True(sender.SendSignal.WaitOne(3000));
            cancellationTokenSource.Cancel();
        }
Exemplo n.º 3
0
        public when_starting_with_pending_events()
        {
            version = "0001";
            rowKey  = "Unpublished_" + version;

            pendingKeys = new[] { "Key1", "Key2", "Key3" };
            queue       = new Mock <IPendingEventsQueue>();
            queue.Setup(x => x.GetPendingAsync(It.IsAny <string>(), It.IsAny <Action <IEnumerable <IEventRecord>, bool> >(), It.IsAny <Action <Exception> >()))
            .Callback <string, Action <IEnumerable <IEventRecord>, bool>, Action <Exception> >(
                (key, success, error) =>
                success(new[] {
                Mock.Of <IEventRecord>(
                    x => x.PartitionKey == key &&
                    x.RowKey == rowKey &&
                    x.TypeName == "TestEventType" &&
                    x.SourceId == "TestId" &&
                    x.SourceType == "TestSourceType" &&
                    x.Payload == "serialized event")
            },
                        false));

            queue.Setup(x => x.GetPartitionsWithPendingEvents()).Returns(pendingKeys);
            sender = new MessageSenderMock();
            var sut = new EventStoreBusPublisher(sender, queue.Object, new MockEventStoreBusPublisherInstrumentation());
            var cancellationTokenSource = new CancellationTokenSource();

            sut.Start(cancellationTokenSource.Token);

            for (var i = 0; i < pendingKeys.Length; i++)
            {
                Assert.True(sender.SendSignal.WaitOne(5000));
            }
            cancellationTokenSource.Cancel();
        }
Exemplo n.º 4
0
        public static IEventSourcedRepository <SeatsAvailability> GetSeatsAvailabilityRepository()
        {
            var serializer = new JsonTextSerializer();

#if LOCAL
            Func <EventStoreDbContext> ctxFactory = () => new EventStoreDbContext("EventStore");
            return(new SqlEventSourcedRepository <SeatsAvailability>(ConferenceHelper.BuildEventBus(), serializer, ctxFactory));
#else
            var settings             = InfrastructureSettings.Read("Settings.xml");
            var eventSourcingAccount = CloudStorageAccount.Parse(settings.EventSourcing.ConnectionString);
            var eventStore           = new EventStore(eventSourcingAccount, settings.EventSourcing.SeatsAvailabilityTableName);
            var publisher            = new EventStoreBusPublisher(ConferenceHelper.GetTopicSender("eventsAvailability"), eventStore, new EventStoreBusPublisherInstrumentation("worker", false));
            var metadata             = new StandardMetadataProvider();
            return(new AzureEventSourcedRepository <SeatsAvailability>(eventStore, publisher, serializer, metadata, new MemoryCache("RepositoryCache")));
#endif
        }