Exemple #1
0
        public async Task Process_WhenFedWithMultipleEvents_ThenShouldInsertInBatches()
        {
            var persistenceMock = new Mock <IPersistEventDetails>();
            var configuration   = new Configuration {
                InsertBatchSize = 3
            };
            var sut = StreamProcessorBuilder.New()
                      .With(persistenceMock.Object)
                      .With(configuration)
                      .Build();
            var streamBuilder = new StreamBuilder();
            var logEvents     = CreateEventBatch().ToArray();

            foreach (var item in logEvents)
            {
                streamBuilder.AppendEvent(item);
            }
            var input = streamBuilder.Build();

            await sut.Process(input);

            persistenceMock.Verify(x => x.Persist(It.Is <LogEventDetails[]>(
                                                      x => x.Length == configuration.InsertBatchSize
                                                      )), Times.Exactly(logEvents.Count(x => x.state == EventStatus.FINISHED) / configuration.InsertBatchSize));


            persistenceMock.Verify(x => x.Persist(It.Is <LogEventDetails[]>(
                                                      x => x.Length == logEvents.Count(x => x.state == EventStatus.FINISHED) % configuration.InsertBatchSize
                                                      )), Times.Once);
        }
Exemple #2
0
        public async Task Process_WhenFedWithInvalidJson_WhenShouldNotInsert()
        {
            var persistenceMock = new Mock <IPersistEventDetails>();
            var sut             = StreamProcessorBuilder.New().With(persistenceMock.Object).Build();
            var input           = new StreamBuilder().AppendText("invalid").Build();

            await sut.Process(input);

            persistenceMock.Verify(x => x.Persist(It.IsAny <LogEventDetails[]>()), Times.Never);
        }
Exemple #3
0
        public async Task Process_WhenFedWithMatchingEvents_ThenShouldInsert(LogEvent one, LogEvent two)
        {
            var persistenceMock = new Mock <IPersistEventDetails>();
            var sut             = StreamProcessorBuilder.New().With(persistenceMock.Object).Build();
            var input           = new StreamBuilder().AppendEvent(one).AppendEvent(two).Build();

            await sut.Process(input);

            persistenceMock.Verify(x => x.Persist(It.Is <LogEventDetails[]>(
                                                      x => x.Single().Id == one.id &&
                                                      Math.Abs(x.Single().Duration) == Math.Abs(one.timestamp - two.timestamp)
                                                      )));
        }