Example #1
0
        public async Task QueryAsync_WhenCalledAndNoContactWasReturnedFromMicrosoftGraphRepository_ReturnsNull()
        {
            QueryHandler sut = CreateSut(hasMicrosoftGraphContact: false);

            IGetContactQuery query  = CreateGetContactQueryMock().Object;
            IContact         result = await sut.QueryAsync(query);

            Assert.That(result, Is.Null);
        }
Example #2
0
        public async Task QueryAsync_WhenCalledAndNoContactWasReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasNotCalledOnContactRepository()
        {
            QueryHandler sut = CreateSut(hasMicrosoftGraphContact: false);

            IGetContactQuery query = CreateGetContactQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.IsAny <IContact>()), Times.Never);
        }
Example #3
0
        public async Task QueryAsync_WhenCalledAndContactWasReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasCalledOnContactRepositoryWithContactFromMicrosoftGraphRepository()
        {
            IContact     microsoftGraphContact = _fixture.BuildContactMock().Object;
            QueryHandler sut = CreateSut(microsoftGraphContact: microsoftGraphContact);

            IGetContactQuery query = CreateGetContactQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.Is <IContact>(value => value == microsoftGraphContact)), Times.Once);
        }
Example #4
0
        public async Task QueryAsync_WhenCalledAndContactWasReturnedFromMicrosoftGraphRepository_ReturnsAppliedContactSupplementFromContactRepository()
        {
            IContact     appliedContactSupplement = _fixture.BuildContactMock().Object;
            QueryHandler sut = CreateSut(appliedContactSupplement: appliedContactSupplement);

            IGetContactQuery query  = CreateGetContactQueryMock().Object;
            IContact         result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(appliedContactSupplement));
        }
Example #5
0
        public async Task QueryAsync_WhenCalled_AssertGetContactAsyncWasCalledOnMicrosoftGraphRepository()
        {
            QueryHandler sut = CreateSut();

            string            externalIdentifier = _fixture.Create <string>();
            IRefreshableToken token = _fixture.BuildRefreshableTokenMock().Object;
            IGetContactQuery  query = CreateGetContactQueryMock(externalIdentifier, token).Object;
            await sut.QueryAsync(query);

            _microsoftGraphRepositoryMock.Verify(m => m.GetContactAsync(
                                                     It.Is <IRefreshableToken>(value => value == token),
                                                     It.Is <string>(value => string.CompareOrdinal(value, externalIdentifier) == 0)),
                                                 Times.Once);
        }
Example #6
0
        public async Task <IActionResult> LoadContact(string externalIdentifier, string countryCode)
        {
            NullGuard.NotNullOrWhiteSpace(externalIdentifier, nameof(externalIdentifier))
            .NotNullOrWhiteSpace(countryCode, nameof(countryCode));

            IRefreshableToken token = await _tokenHelperFactory.GetTokenAsync <IRefreshableToken>(TokenType.MicrosoftGraphToken, HttpContext);

            if (token == null)
            {
                return(Unauthorized());
            }

            IGetContactQuery getContactQuery = CreateContactQueryBase <GetContactQuery>(token);

            getContactQuery.ExternalIdentifier = externalIdentifier;

            List <ContactGroupViewModel> contactGroupViewModelCollection = (await GetContactGroupViewModels()).ToList();
            List <PaymentTermViewModel>  paymentTermViewModelCollection  = (await GetPaymentTermViewModels()).ToList();
            List <CountryViewModel>      countryViewModelCollection      = (await GetCountryViewModels()).ToList();
            ICountry country = await GetCountry(countryCode);

            IContact contact = await _queryBus.QueryAsync <IGetContactQuery, IContact>(getContactQuery);

            if (country == null || contact == null)
            {
                return(BadRequest());
            }

            ContactViewModel contactViewModel = _contactViewModelConverter.Convert <IContact, ContactViewModel>(contact);

            contactViewModel.Country       = _contactViewModelConverter.Convert <ICountry, CountryViewModel>(country);
            contactViewModel.Countries     = countryViewModelCollection;
            contactViewModel.ContactGroups = contactGroupViewModelCollection;
            contactViewModel.PaymentTerms  = paymentTermViewModelCollection;

            return(PartialView("_ContactPartial", contactViewModel));
        }
 public IActionResult Get([FromQuery] ContactSearch search,
                          [FromServices] IGetContactQuery query)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }