コード例 #1
0
        public async Task FindProcessManager_returns_null_if_process_manager_that_satisfies_predicate_not_found()
        {
            // Arrange
            var sut = new SqlProcessManagerDataContext <FooProcessManager>(
                new FooProcessManagerDbContext(),
                new JsonMessageSerializer(),
                Mock.Of <ICommandPublisher>());

            using (sut)
            {
                Expression <Func <FooProcessManager, bool> > predicate = x => x.Id == Guid.NewGuid();

                // Act
                FooProcessManager actual = await sut.FindProcessManager(predicate, CancellationToken.None);

                // Assert
                actual.Should().BeNull();
            }
        }
コード例 #2
0
        public async Task FindProcessManager_returns_process_manager_that_satisfies_predicate()
        {
            // Arrange
            var processManagers = Enumerable
                                  .Repeat <Func <FooProcessManager> >(() => new FooProcessManager {
                AggregateId = Guid.NewGuid()
            }, 10)
                                  .Select(f => f.Invoke())
                                  .ToList();

            FooProcessManager expected = processManagers.First();

            using (var db = new FooProcessManagerDbContext())
            {
                var random = new Random();
                foreach (FooProcessManager processManager in from p in processManagers
                         orderby random.Next()
                         select p)
                {
                    db.FooProcessManagers.Add(processManager);
                }

                await db.SaveChangesAsync();
            }

            var sut = new SqlProcessManagerDataContext <FooProcessManager>(
                new FooProcessManagerDbContext(),
                new JsonMessageSerializer(),
                Mock.Of <ICommandPublisher>());

            using (sut)
            {
                Expression <Func <FooProcessManager, bool> > predicate = x => x.AggregateId == expected.AggregateId;

                // Act
                FooProcessManager actual = await sut.FindProcessManager(predicate, CancellationToken.None);

                // Assert
                actual.Should().NotBeNull();
                actual.Id.Should().Be(expected.Id);
            }
        }
コード例 #3
0
        public async Task FindProcessManager_flushes_pending_commands()
        {
            // Arrange
            ICommandPublisher publisher = Mock.Of <ICommandPublisher>();
            var processManager          = new FooProcessManager();
            var sut = new SqlProcessManagerDataContext <FooProcessManager>(
                new FooProcessManagerDbContext(),
                new JsonMessageSerializer(),
                publisher);

            using (var db = new FooProcessManagerDbContext())
            {
                db.FooProcessManagers.Add(processManager);
                await db.SaveChangesAsync();
            }

            // Act
            await sut.FindProcessManager(p => p.Id == processManager.Id, CancellationToken.None);

            // Assert
            Mock.Get(publisher).Verify(x => x.FlushCommands(processManager.Id, CancellationToken.None), Times.Once());
        }
コード例 #4
0
        public async Task SaveProcessManagerAndPublishCommands_updates_existing_process_manager()
        {
            // Arrange
            var fixture = new Fixture();
            FooProcessManager processManager = fixture.Create <FooProcessManager>();

            using (var db = new FooProcessManagerDbContext())
            {
                db.FooProcessManagers.Add(processManager);
                await db.SaveChangesAsync();
            }

            string statusValue = fixture.Create <string>();

            var sut = new SqlProcessManagerDataContext <FooProcessManager>(
                new FooProcessManagerDbContext(),
                new JsonMessageSerializer(),
                Mock.Of <ICommandPublisher>());

            using (sut)
            {
                processManager = await sut.FindProcessManager(x => x.Id == processManager.Id);

                processManager.StatusValue = statusValue;

                // Act
                await sut.SaveProcessManagerAndPublishCommands(processManager);
            }

            // Assert
            using (var db = new FooProcessManagerDbContext())
            {
                FooProcessManager actual = await
                                           db.FooProcessManagers.SingleOrDefaultAsync(x => x.Id == processManager.Id);

                actual.StatusValue.Should().Be(statusValue);
            }
        }