public async Task <IActionResult> CreateContact(ContactViewModel contactViewModel) { NullGuard.NotNull(contactViewModel, nameof(contactViewModel)); IRefreshableToken token = await _tokenHelperFactory.GetTokenAsync <IRefreshableToken>(TokenType.MicrosoftGraphToken, HttpContext); if (token == null) { return(Unauthorized()); } if (ModelState.IsValid == false) { return(RedirectToAction("Contacts", "Contact")); } ICreateContactCommand createContactCommand = _contactViewModelConverter.Convert <ContactViewModel, CreateContactCommand>(contactViewModel); createContactCommand.TokenType = token.TokenType; createContactCommand.AccessToken = token.AccessToken; createContactCommand.RefreshToken = token.RefreshToken; createContactCommand.Expires = token.Expires; await _commandBus.PublishAsync(createContactCommand); return(RedirectToAction("Contacts", "Contact")); }
public void ToDomain_WhenCalled_ReturnsContactWithoutExternalIdentifier() { ICreateContactCommand sut = CreateSut(); string result = sut.ToDomain(_contactRepositoryMock.Object, _accountingRepositoryMock.Object).ExternalIdentifier; Assert.That(result, Is.Null); }
public void ToDomain_WhenCalled_ReturnsContact() { ICreateContactCommand sut = CreateSut(); IContact result = sut.ToDomain(_contactRepositoryMock.Object, _accountingRepositoryMock.Object); Assert.That(result, Is.TypeOf <Contact>()); }
public void ToDomain_WhenAccountingRepositoryIsNull_ThrowsArgumentNullException() { ICreateContactCommand sut = CreateSut(); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.ToDomain(_contactRepositoryMock.Object, null)); Assert.That(result.ParamName, Is.EqualTo("accountingRepository")); }
public async Task ExecuteAsync_WhenCalledAndNoCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertCreateOrUpdateContactSupplementAsyncWasNotCalledOnContactRepository() { CommandHandler sut = CreateSut(false); ICreateContactCommand command = CreateCreateContactCommandMock().Object; await sut.ExecuteAsync(command); _contactRepositoryMock.Verify(m => m.CreateOrUpdateContactSupplementAsync(It.IsAny <IContact>(), It.IsAny <string>()), Times.Never); }
public async Task ExecuteAsync_WhenCalledAndNoCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertExternalIdentifierSetterWasNotCalledOnContactFromToDomainOnCommand() { CommandHandler sut = CreateSut(false); Mock <IContact> contactMock = _fixture.BuildContactMock(); ICreateContactCommand command = CreateCreateContactCommandMock(contact: contactMock.Object).Object; await sut.ExecuteAsync(command); contactMock.VerifySet(m => m.ExternalIdentifier = It.IsAny <string>(), Times.Never); }
public async Task ExecuteAsync_WhenCalledAndNoCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertExternalIdentifierWasNotCalledOnCreatedContactFromMicrosoftGraphRepository() { Mock <IContact> createdMicrosoftGraphContactMock = _fixture.BuildContactMock(); CommandHandler sut = CreateSut(false, createdMicrosoftGraphContactMock.Object); ICreateContactCommand command = CreateCreateContactCommandMock().Object; await sut.ExecuteAsync(command); createdMicrosoftGraphContactMock.Verify(m => m.ExternalIdentifier, Times.Never); }
public async Task ExecuteAsync_WhenCalledAndCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertCreateOrUpdateContactSupplementAsyncWasCalledOnContactRepositoryWithContactFromToDomainOnCommand() { CommandHandler sut = CreateSut(); IContact contact = _fixture.BuildContactMock().Object; ICreateContactCommand command = CreateCreateContactCommandMock(contact: contact).Object; await sut.ExecuteAsync(command); _contactRepositoryMock.Verify(m => m.CreateOrUpdateContactSupplementAsync(It.Is <IContact>(value => value == contact), It.Is <string>(value => value == null)), Times.Once); }
public async Task ExecuteAsync_WhenCalledAndCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertExternalIdentifierSetterWasCalledOnContactFromToDomainOnCommandExternalIdentifierFromCreatedContactFromMicrosoftGraphRepository() { string externalIdentifier = _fixture.Create <string>(); IContact createdMicrosoftGraphContact = _fixture.BuildContactMock(externalIdentifier: externalIdentifier).Object; CommandHandler sut = CreateSut(createdMicrosoftGraphContact: createdMicrosoftGraphContact); Mock <IContact> contactMock = _fixture.BuildContactMock(); ICreateContactCommand command = CreateCreateContactCommandMock(contact: contactMock.Object).Object; await sut.ExecuteAsync(command); contactMock.VerifySet(m => m.ExternalIdentifier = It.Is <string>(value => string.CompareOrdinal(value, externalIdentifier) == 0), Times.Once); }
public async Task ExecuteAsync_WhenCalled_AssertCreateContactAsyncWasCalledOnMicrosoftGraphRepository() { CommandHandler sut = CreateSut(); IRefreshableToken refreshableToken = _fixture.BuildRefreshableTokenMock().Object; IContact contact = _fixture.BuildContactMock().Object; ICreateContactCommand command = CreateCreateContactCommandMock(refreshableToken, contact).Object; await sut.ExecuteAsync(command); _microsoftGraphRepositoryMock.Verify(m => m.CreateContactAsync( It.Is <IRefreshableToken>(value => value == refreshableToken), It.Is <IContact>(value => value == contact)), Times.Once); }
public ContactsController( IGetAllContactsCommand getAllContactsCommand, IGetContactByIdCommand getContactByIdCommand, ICreateContactCommand createContactCommand, IDeleteContactCommand deleteContactCommand, IUpdateContactCommand updateContactCommand ) { _getAllContactsCommand = getAllContactsCommand; _getContactByIdCommand = getContactByIdCommand; _createContactCommand = createContactCommand; _deleteContactCommand = deleteContactCommand; _updateContactCommand = updateContactCommand; }
public ContactsController(ICreateContactCommand createContactCommand, IUpdateContactCommand updateContactCommand, IDeleteContactCommand deleteContactCommand, IGetAllContactsByCityQuery getAllContactsByCity, IGetAllContactsByStateQuery getAllContactsByStateQuery, IGetContactByEmailQuery getContactByEmailQuery, IGetContactByPhoneNumberQuery getContactByPhoneNumberQuery, IGetContactDetailQuery getContactDetailQuery) { _createContactCommand = createContactCommand; _updateContactCommand = updateContactCommand; _deleteContactCommand = deleteContactCommand; _getAllContactsByCity = getAllContactsByCity; _getAllContactsByStateQuery = getAllContactsByStateQuery; _getContactByEmailQuery = getContactByEmailQuery; _getContactByPhoneNumberQuery = getContactByPhoneNumberQuery; _getContactDetailQuery = getContactDetailQuery; }
public void Post([FromBody] ContactDto dto, [FromServices] ICreateContactCommand command, [FromServices] CreateContactValidator validator) { _executor.ExecuteCommand(command, dto); }