Exemplo n.º 1
0
        public async Task Throws_RequestException_Id()
        {
            using var factory = new AppDbContextFactory();
            using var context = factory.CreateContext();

            // Arrange
            var sut = new RemoveContactHandler(_logger, context, _mediator.Object);
            var cmd = new RemoveContactCommand {
                Id = int.MaxValue
            };

            // Act & Assert
            var ex = await Assert.ThrowsAsync <RequestException>(() => sut.Handle(cmd));

            Assert.True(ex.Key == nameof(cmd.Id));
            _mediator.Verify(m => m.Publish(It.IsAny <ContactRemovedNotification>(), default), Times.Never());
        }
Exemplo n.º 2
0
        public async Task OK()
        {
            using var factory = new AppDbContextFactory();
            using var context = factory.CreateContext(true);

            // Arrange
            var sut      = new RemoveContactHandler(_logger, context, _mediator.Object);
            var contacts = context.Contacts.ToList();
            var cmd      = new RemoveContactCommand {
                Id = contacts[0].Id
            };

            // Act
            await sut.Handle(cmd);

            // Assert
            Assert.True(contacts.Count > context.Contacts.Count());
            _mediator.Verify(m => m.Publish(It.IsAny <ContactRemovedNotification>(), default), Times.Once());
        }