public void DeleteContactCallsCollaborators() { var contact = ContactEntityObjectMother.Random(); repo.Setup(x => x.GetById(contact.Id)).Returns(contact); repo.Setup(x => x.Delete(It.Is <IdValueObject>(p => p == contact.Id))); uow.Setup(x => x.StartChanges()); uow.Setup(x => x.CommitChanges()); eventBus.Setup( x => x.Record(It.Is <ContactDeletedDomainEvent>( p => p.FirstName == contact.Name.FirstName && p.LastName == contact.Name.LastName && p.AggregateRootId == contact.Id.Value))); eventBus.Setup(x => x.PublishAsync()).Returns(Task.Delay(500)); var cmd = new DeleteContactCommand(contact.Id.Value); var handler = new DeleteContactCommandHandler(uow.Object, eventBus.Object, repo.Object); var x = handler.Handle(cmd, new System.Threading.CancellationToken()).Result; repo.VerifyAll(); uow.VerifyAll(); eventBus.VerifyAll(); }
public void DeleteWithInvalidIdThrowException() { var handler = new DeleteContactCommandHandler(uow.Object, eventBus.Object, repo.Object); Assert.Throws <InvalidEntityException>(() => handler.Handle(new DeleteContactCommand(null), new System.Threading.CancellationToken())); Assert.Throws <InvalidEntityException>(() => handler.Handle(new DeleteContactCommand(string.Empty), new System.Threading.CancellationToken())); Assert.Throws <DomainException>(() => handler.Handle(new DeleteContactCommand("abc"), new System.Threading.CancellationToken())); }
public void DeleteWithInvalidContactThrowException() { var id = new IdValueObject(); repo.Setup(x => x.GetById(It.Is <IdValueObject>(p => p == id))).Returns <ContactEntity>(null); var cmd = new DeleteContactCommand(id.Value); var handler = new DeleteContactCommandHandler(uow.Object, eventBus.Object, repo.Object); Assert.Throws <EntityNotFound>(() => handler.Handle(cmd, new System.Threading.CancellationToken())); repo.VerifyAll(); }
public async void Deletes_Contact_Successfully() { //Arrange var contact = Context.Contacts.First(); Mediator.Setup(x => x.Send(It.IsAny <DeleteContactCommand>(), new CancellationToken())) .ReturnsAsync(Unit.Value); //Act var deleteContactCommand = new DeleteContactCommand(contact); var handler = new DeleteContactCommandHandler(Context); var result = await handler.Handle(deleteContactCommand, new CancellationToken()); //Assert result.Should() .BeOfType <Unit>() .Equals(Unit.Value); DbContextFactory.Destroy(Context); }
public async void DeleteContactCommandTest() { //Arange var testHelper = new TestHelper(); var contact = Contact.Create("someone", "*****@*****.**", "156464654", null, testHelper.contactsContext); await testHelper.contactsContext.AddAsync(contact); await testHelper.contactsContext.SaveChangesAsync(); DeleteContactCommand deleteCommand = new DeleteContactCommand(contact.Id); DeleteContactCommandHandler deleteContactCommandHandler = new DeleteContactCommandHandler(testHelper.GetInMemoryContactRepository(), testHelper.GetInMemoryUnitOfWork()); //Act await deleteContactCommandHandler.Handle(deleteCommand, default); var deletedContact = await testHelper.GetInMemoryContactRepository().GetByIdAsync(contact.Id); //Assert deletedContact.Should().BeNull(); }