public GenericCommandResult Delete( [FromBody] DeleteContactCommand command, [FromServices] ContactHandler handler ) { return((GenericCommandResult)handler.Handle(command)); }
public async Task GetAllContacts_Should_not_return_soft_deleted_contacts() { // Arrange await ContactHelpers.SeedContacts(dbAccess, mapper); var deleteClient = new DeleteContactCommand() { ContactId = 2 }; var deleteHandler = new DeleteContactHandler(dbAccess, mapper); await deleteHandler.Handle(deleteClient, CancellationToken.None); var query = new GetAllContactsQuery(); var handler = new GetAllContactsHandler(dbAccess, mapper); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert Assert.Single(result); Assert.Collection(result, a => { Assert.Equal(1, a.ContactId); Assert.Equal("Joe Bloggs", a.FullName); } ); }
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 async Task <ContactDetailsDto> DeleteContact(int id) { var command = new DeleteContactCommand(id); var result = await _mediator.Send(command); return(result); }
public ContactControllerTest() { _saveContactCommand = A.Fake <SaveContactCommand>(); _contactsQuery = A.Fake <ContactsQuery>(); _deleteContactCommand = A.Fake <DeleteContactCommand>(); _contactController = new ContactController(_contactsQuery, _saveContactCommand, _deleteContactCommand); }
public ContactController(ContactsQuery contactsQuery, SaveContactCommand saveContactCommand, DeleteContactCommand deleteContactCommand) { _contactsQuery = contactsQuery; _saveContactCommand = saveContactCommand; _deleteContactCommand = deleteContactCommand; }
public DeleteContactCommandShould() { _deleteContantMessage = new DeleteContactCommand { Contact = Context.Contacts.Single(c => c.ContactId == 1) }; _sut = new DeleteContactCommandHandlerWrapper(Context); }
public void ShouldRequireValidTodoListId() { var command = new DeleteContactCommand { Id = 99 }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task <APIResult> Delete([FromBody] DeleteContactCommand command) { var id = await mediator.Send(command); return(new APIResult() { Data = new { id = (id > 0) ? id : (int?)null }, Result = (id > 0) ? 0 : -1, }); }
public bool Delete(int id) { QueriesOrCommands.Add(nameof(DeleteContactCommand)); var command = new DeleteContactCommand { Id = id }; return(DeleteContact(command)); }
public IActionResult Delete([FromQuery] DeleteContactCommand command) { var commandResult = _mediator.Send(command); if (commandResult.IsFaulted) { return(BadRequest(commandResult.Exception.InnerException.Message)); } return(Ok(new { message = "Contact deleted" })); }
public async void DeleteContact_ContactNull_False() { //arrange var contact = ContactFaker.GetContactOk(); var deleteContactCommand = new DeleteContactCommand(contact.Id); _dependencyResolverMock .Setup(x => x.Resolve <IMediatorHandler>()) .Returns(_mediatorHandler.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactRepository>()) .Returns(_contactRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactTypeRepository>()) .Returns(_contactTypeRepositoryMock.Object); _contactRepositoryMock .Setup(x => x.GetByIdAsync(deleteContactCommand.ContactId)) .Returns(Task.FromResult((Contact)null)); _contactRepositoryMock .Setup(x => x.CommitAsync()) .Returns(Task.FromResult(CommitResponse.Ok())); var handler = new ContactCommandHandler(_dependencyResolverMock.Object); //act var result = await handler.Handle(deleteContactCommand, new CancellationToken()); //Assert Assert.False(result.Success); _contactRepositoryMock.Verify(x => x.GetByIdAsync(deleteContactCommand.ContactId), Times.Once); _contactRepositoryMock.Verify(x => x.Update(contact), Times.Never); _contactRepositoryMock.Verify(x => x.CommitAsync(), Times.Never); _mediatorHandler.Verify(x => x.NotifyDomainNotification(It.IsAny <DomainNotification>()), Times.Once); }
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 Task <int> Delete(int id, [FromBody] string clubName) { if (ModelState.IsValid) { DeleteContactCommand deleteContactCommand = new DeleteContactCommand(id); var result = await _mediator.Send(deleteContactCommand); return(result); } return(0); }
public async Task <ActionResult> DeleteContact(Guid id) { var contactDetailsQuery = new ContactDetailsQuery(id); var contact = await Mediator.Send(contactDetailsQuery); if (contact == null) { return(NotFound("Contact not found")); } var deleteContactCommand = new DeleteContactCommand(contact); await Mediator.Send(deleteContactCommand); return(NoContent()); }
private void InvalidateCommands() { EditFeeScheuleCommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged(); PrintCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); DeleteCommand.RaiseCanExecuteChanged(); EditAttributeCommand.RaiseCanExecuteChanged(); DeleteAttributeCommand.RaiseCanExecuteChanged(); DeleteFeeScheuleCommand.RaiseCanExecuteChanged(); NewOrderCommand.RaiseCanExecuteChanged(); EditContactCommand.RaiseCanExecuteChanged(); DeleteContactCommand.RaiseCanExecuteChanged(); EditEmployeeCommand.RaiseCanExecuteChanged(); DeleteEmployeeCommand.RaiseCanExecuteChanged(); }
public Task <bool> Handle(DeleteContactCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { return(Task.FromResult(false)); } _contactUnitOfWork.ContactsRepository.DeleteContact(request.UserId, request.Id); //Storing the deletion event if (_contactUnitOfWork.Commit()) { _eventHandler.RaiseEvent(new ContactDeletedEvent(request.Id)); } return(Task.FromResult(true)); }
public ICommandResult Handle(DeleteContactCommand command) { command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Ops, parece que os dados do contato estão errados!", command.Notifications)); } // Recupera var Contact = _repository.GetById(command.Id); // apaga no banco _repository.Delete(Contact); // Retorna o resultado return(new GenericCommandResult(true, "Contato apagado com sucesso!", Contact)); }
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 Task <CommandResponse> Handle(DeleteContactCommand request, CancellationToken cancellationToken) { var contact = await _contactRepository.GetByIdAsync(request.ContactId); if (contact == null) { await MediatorHandler.NotifyDomainNotification(DomainNotification.Fail("The Contact is invalid !")); return(CommandResponse.Fail()); } //the system does not exclude, just mark the Valid as false; contact.Remove(); _contactRepository.Update(contact); var result = await _contactRepository.CommitAsync(); return(result.Success ? CommandResponse.Ok() : CommandResponse.Fail("Fail recording the register in database !")); }
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(); }
public async Task <IActionResult> DeleteContact(string externalIdentifier) { NullGuard.NotNullOrWhiteSpace(externalIdentifier, nameof(externalIdentifier)); IRefreshableToken token = await _tokenHelperFactory.GetTokenAsync <IRefreshableToken>(TokenType.MicrosoftGraphToken, HttpContext); if (token == null) { return(Unauthorized()); } IDeleteContactCommand command = new DeleteContactCommand { ExternalIdentifier = externalIdentifier, TokenType = token.TokenType, AccessToken = token.AccessToken, RefreshToken = token.RefreshToken, Expires = token.Expires }; await _commandBus.PublishAsync(command); return(RedirectToAction("Contacts", "Contact")); }
/// <summary> /// ViewModel for main window. /// </summary> public MainWindowVM() { ContactService = new ContactService(); ContactVMs = ContactService.GetContactVMs(); GroupNames = new ObservableCollection <string>(ContactService.Groups.Select(it => it.Name)) { SystemGroupNames.ALL_CONTACTS }; SelectedGroup = SystemGroupNames.ALL_CONTACTS; AddGroupCommand = new AddGroupCommand(); AddContactToGroupCommand = new AddContactToGroupCommand(); RemoveContactFromGroupCommand = new RemoveContactFromGroupCommand(); EditContactCommand = new EditContactCommand(); AddContactCommand = new AddContactCommand(); DeleteContactCommand = new DeleteContactCommand(); DeleteGroupCommand = new DeleteGroupCommand(); }
public void DeleteContact(Guid userId, Guid contactId) { var deleteCommand = new DeleteContactCommand(userId, contactId); _bus.SendCommand(deleteCommand); }
public async Task ExposedHandle(DeleteContactCommand message) { await base.Handle(message, default(CancellationToken)); }
public void DeleteContact(DeleteContactCommand command) { _contactService.DeleteContact(command.PhoneNumber); _viewService.PrintSuccessNotification(); }