public async Task Throws_RequestException_Contact_Not_Found() { using var factory = new AppDbContextFactory(); using var context = factory.CreateContext(); // Arrange var sut = new UpdateContactHandler(_logger, context, _mediator.Object); var cmd = new UpdateContactCommand { Id = int.MaxValue, Name = "A", Address = "A", DateOfBirth = DateTime.Now.AddDays(-1) }; // Act & Assert var ex = await Assert.ThrowsAsync <RequestException>(() => sut.Handle(cmd)); _mediator.Verify(m => m.Publish(It.IsAny <ContactUpdatedNotification>(), default), Times.Never()); }
public async Task Throws_RequestException_Contact_Exists() { using var factory = new AppDbContextFactory(); using var context = factory.CreateContext(true); // Arrange var sut = new UpdateContactHandler(_logger, context, _mediator.Object); var contacts = context.Contacts.ToList(); var c1 = contacts.First(); var c2 = contacts.Last(); var cmd = new UpdateContactCommand { Id = c2.Id, Name = c1.Name.ToLower(), Address = c1.Address.ToUpper(), DateOfBirth = c1.DateOfBirth }; // Act & Assert var ex = await Assert.ThrowsAsync <RequestException>(() => sut.Handle(cmd)); _mediator.Verify(m => m.Publish(It.IsAny <ContactUpdatedNotification>(), default), Times.Never()); }
public async Task OK() { using var factory = new AppDbContextFactory(); using var context = factory.CreateContext(true); // Arrange var sut = new UpdateContactHandler(_logger, context, _mediator.Object); var contact = context.Contacts.First(); var cmd = new UpdateContactCommand { Id = contact.Id, Name = "C", Address = "C", DateOfBirth = DateTime.Now.AddDays(-1) }; // Act var result = await sut.Handle(cmd); // Assert Assert.True(contact.Name == "C"); Assert.True(contact.Address == "C"); _mediator.Verify(m => m.Publish(It.IsAny <ContactUpdatedNotification>(), default), Times.Once()); }