Beispiel #1
0
        public async void DeleteHandler_Should_Work(string id, bool expected)
        {
            // Given
            IMediator mediator = ServiceProvider.GetService <IMediator>();

            MockEventPublisher   publisher  = new MockEventPublisher(mediator);
            MockSampleRepository repository = new MockSampleRepository(
                new Dictionary <string, Domain.Sample.Sample>
            {
                { "1", new Domain.Sample.Sample("1", "1") }
            });
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();
            Mock <ILogger <DeleteRequest> > logger = new Mock <ILogger <DeleteRequest> >();

            DeleteHandler handler =
                new DeleteHandler(publisher, repository, uow.Object, logger.Object);

            DeleteRequest command = new DeleteRequest(id);

            // When
            Result result = await handler.Handle(command, new CancellationToken());

            // Then
            List <ValidationResult> notValidNotifications =
                result.Notifications.Where(notification => !notification.IsValid).ToList();

            if (expected)
            {
                Assert.Empty(notValidNotifications);
            }
            else
            {
                Assert.NotEmpty(notValidNotifications);
            }
        }
Beispiel #2
0
        public async void FindHandler_Should_Work(string id,
                                                  string description,
                                                  int expected,
                                                  int count)
        {
            // Given
            IMediator mediator = ServiceProvider.GetService <IMediator>();

            MockEventPublisher   publisher  = new MockEventPublisher(mediator);
            MockSampleRepository repository = new MockSampleRepository(
                new Dictionary <string, Domain.Sample.Sample>
            {
                { "1", new Domain.Sample.Sample("1", "1") },
                { "2", new Domain.Sample.Sample("2", "2") },
                { "3", new Domain.Sample.Sample("3", "3") },
                { "4", new Domain.Sample.Sample("4", "4") }
            });
            Mock <ILogger <FindRequest> > logger = new Mock <ILogger <FindRequest> >();

            FindHandler handler = new FindHandler(repository, publisher, logger.Object);

            FindRequest command = new FindRequest(id, description, 1, 3);

            // When
            QueryResult <SampleDto> result = await handler.Handle(command, new CancellationToken());

            // Then
            List <ValidationResult> notValidNotifications =
                result.Notifications.Where(notification => !notification.IsValid).ToList();

            Assert.Empty(notValidNotifications);
            Assert.Equal(expected, result.Items.Count());
            Assert.Equal(count, result.Count);
        }
Beispiel #3
0
        public async void InsertHandler_Should_Work(string id, string description, bool expected)
        {
            // Given
            IMediator mediator = ServiceProvider.GetService <IMediator>();

            MockEventPublisher   publisher  = new MockEventPublisher(mediator);
            MockSampleRepository repository =
                new MockSampleRepository(new Dictionary <string, Domain.Sample.Sample>());
            Mock <IUnitOfWork> uow                 = new Mock <IUnitOfWork>();
            MockSampleService  service             = new MockSampleService();
            Mock <ILogger <InsertRequest> > logger = new Mock <ILogger <InsertRequest> >();

            InsertHandler handler =
                new InsertHandler(publisher, repository, uow.Object, service, logger.Object);

            SampleDto item = new SampleDto {
                Id = id, Description = description
            };
            InsertRequest command = new InsertRequest(item);

            // When
            EntityResult <SampleDto> result = await handler.Handle(command, new CancellationToken());

            // Then
            List <ValidationResult> notValidNotifications =
                result.Notifications.Where(notification => !notification.IsValid).ToList();

            if (expected)
            {
                Assert.Empty(notValidNotifications);
                Assert.True(ContainsType(publisher.Notifications,
                                         typeof(DomainEvent <InsertRequest>)));
            }
            else
            {
                Assert.NotEmpty(notValidNotifications);
                Assert.False(ContainsType(publisher.Notifications,
                                          typeof(DomainEvent <InsertRequest>)));
            }
        }