public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_AssertIsMatchWasNotCalledOnAnyContact()
        {
            IEnumerable <Mock <IContact> > microsoftGraphContactMockCollection = new List <Mock <IContact> >
            {
                _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock()
            };
            QueryHandler sut = CreateSut(false, microsoftGraphContactMockCollection.Select(m => m.Object).ToArray());

            IGetMatchingContactCollectionQuery query = CreateGetMatchingContactCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            foreach (Mock <IContact> contactMock in microsoftGraphContactMockCollection)
            {
                contactMock.Verify(m => m.IsMatch(
                                       It.IsAny <string>(),
                                       It.IsAny <SearchOptions>()),
                                   Times.Never);
            }
        }
        public void Validate_WhenCalled_AssertShouldBeGreaterThanZeroWasCalledOnIntegerValidatorForSearchOptions()
        {
            bool searchWithinName                  = _fixture.Create <bool>();
            bool searchWithinMailAddress           = _fixture.Create <bool>();
            bool searchWithinPrimaryPhone          = _fixture.Create <bool>();
            bool searchWithinSecondaryPhone        = _fixture.Create <bool>();
            bool searchWithinHomePhone             = _fixture.Create <bool>();
            bool searchWithinMobilePhone           = _fixture.Create <bool>();
            IGetMatchingContactCollectionQuery sut = CreateSut(searchWithinName: searchWithinName, searchWithinMailAddress: searchWithinMailAddress, searchWithinPrimaryPhone: searchWithinPrimaryPhone, searchWithinSecondaryPhone: searchWithinSecondaryPhone, searchWithinHomePhone: searchWithinHomePhone, searchWithinMobilePhone: searchWithinMobilePhone);

            sut.Validate(_validatorMockContext.ValidatorMock.Object);

            int searchOptions = (searchWithinName ? (int)SearchOptions.Name : 0) +
                                (searchWithinMailAddress ? (int)SearchOptions.MailAddress : 0) +
                                (searchWithinPrimaryPhone ? (int)SearchOptions.PrimaryPhone : 0) +
                                (searchWithinSecondaryPhone ? (int)SearchOptions.SecondaryPhone : 0) +
                                (searchWithinHomePhone ? (int)SearchOptions.HomePhone : 0) +
                                (searchWithinMobilePhone ? (int)SearchOptions.MobilePhone : 0);

            _validatorMockContext.IntegerValidatorMock.Verify(m => m.ShouldBeGreaterThanZero(
                                                                  It.Is <int>(value => value == searchOptions),
                                                                  It.Is <Type>(value => value == sut.GetType()),
                                                                  It.Is <string>(value => string.CompareOrdinal(value, "SearchOptions") == 0)),
                                                              Times.Once);
        }
        public async Task QueryAsync_WhenCalledAndContactCollectionWasReturnedFromMicrosoftGraphRepository_AssertIsMatchWasCalledOnEachContactWithinContactCollectionFromMicrosoftGraphRepository()
        {
            IEnumerable <Mock <IContact> > microsoftGraphContactMockCollection = new List <Mock <IContact> >
            {
                _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock(),
                                           _fixture.BuildContactMock()
            };
            QueryHandler sut = CreateSut(microsoftGraphContactCollection: microsoftGraphContactMockCollection.Select(m => m.Object).ToArray());

            string        searchFor     = _fixture.Create <string>();
            SearchOptions searchOptions = _fixture.Create <SearchOptions>();
            IGetMatchingContactCollectionQuery query = CreateGetMatchingContactCollectionQueryMock(searchFor, searchOptions).Object;
            await sut.QueryAsync(query);

            foreach (Mock <IContact> contactMock in microsoftGraphContactMockCollection)
            {
                contactMock.Verify(m => m.IsMatch(
                                       It.Is <string>(value => string.CompareOrdinal(value, searchFor) == 0),
                                       It.Is <SearchOptions>(value => value == searchOptions)),
                                   Times.Once);
            }
        }
        public void Validate_WhenCalled_ReturnsValidator()
        {
            IGetMatchingContactCollectionQuery sut = CreateSut();

            IValidator result = sut.Validate(_validatorMockContext.ValidatorMock.Object);

            Assert.That(result, Is.EqualTo(_validatorMockContext.ValidatorMock.Object));
        }
        public void Validate_WhenValidatorIsNull_ThrowsArgumentNullException()
        {
            IGetMatchingContactCollectionQuery sut = CreateSut();

            ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.Validate(null));

            Assert.That(result.ParamName, Is.EqualTo("validator"));
        }
Beispiel #6
0
        public void SearchOptions_WhenSearchWithinSecondaryPhoneIsTrue_ReturnSearchOptionsWithFlagForSecondaryPhone()
        {
            const bool searchWithinSecondaryPhone  = true;
            IGetMatchingContactCollectionQuery sut = CreateSut(searchWithinSecondaryPhone: searchWithinSecondaryPhone);

            SearchOptions result = sut.SearchOptions;

            Assert.That(result.HasFlag(SearchOptions.SecondaryPhone), Is.True);
        }
Beispiel #7
0
        public void SearchOptions_WhenSearchWithinPrimaryPhoneIsFalse_ReturnSearchOptionsWithoutFlagForPrimaryPhone()
        {
            const bool searchWithinPrimaryPhone    = false;
            IGetMatchingContactCollectionQuery sut = CreateSut(searchWithinPrimaryPhone: searchWithinPrimaryPhone);

            SearchOptions result = sut.SearchOptions;

            Assert.That(result.HasFlag(SearchOptions.PrimaryPhone), Is.False);
        }
Beispiel #8
0
        public void SearchOptions_WhenSearchWithinMailAddressIsFalse_ReturnSearchOptionsWithoutFlagForMailAddress()
        {
            const bool searchWithinMailAddress     = false;
            IGetMatchingContactCollectionQuery sut = CreateSut(searchWithinMailAddress: searchWithinMailAddress);

            SearchOptions result = sut.SearchOptions;

            Assert.That(result.HasFlag(SearchOptions.MailAddress), Is.False);
        }
        public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasNotCalledOnContactRepository()
        {
            QueryHandler sut = CreateSut(false);

            IGetMatchingContactCollectionQuery query = CreateGetMatchingContactCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.IsAny <IEnumerable <IContact> >()), Times.Never);
        }
        public async Task QueryAsync_WhenCalled_AssertGetContactsAsyncWasCalledOnMicrosoftGraphRepository()
        {
            QueryHandler sut = CreateSut();

            IRefreshableToken token = _fixture.BuildRefreshableTokenMock().Object;
            IGetMatchingContactCollectionQuery query = CreateGetMatchingContactCollectionQueryMock(refreshableToken: token).Object;
            await sut.QueryAsync(query);

            _microsoftGraphRepositoryMock.Verify(m => m.GetContactsAsync(It.Is <IRefreshableToken>(value => value == token)), Times.Once);
        }
        public async Task QueryAsync_WhenCalledAndAppliedContactSupplementCollectionWasReturnedFromContactRepository_ReturnsAppliedContactSupplementCollectionFromContactRepository()
        {
            IEnumerable <IContact> appliedContactSupplementCollection = _fixture.CreateMany <IContact>(_random.Next(5, 15)).ToList();
            QueryHandler           sut = CreateSut(appliedContactSupplementCollection: appliedContactSupplementCollection);

            IGetMatchingContactCollectionQuery query  = CreateGetMatchingContactCollectionQueryMock().Object;
            IEnumerable <IContact>             result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(appliedContactSupplementCollection));
        }
        public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_ReturnsEmptyContactCollection()
        {
            QueryHandler sut = CreateSut(false);

            IGetMatchingContactCollectionQuery query = CreateGetMatchingContactCollectionQueryMock().Object;
            IList <IContact> result = (await sut.QueryAsync(query)).ToList();

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.Empty);
        }
        public void Validate_WhenCalled_AssertShouldNotBeNullOrWhiteSpaceWasCalledOnStringValidatorForSearchFor()
        {
            string searchFor = _fixture.Create <string>();
            IGetMatchingContactCollectionQuery sut = CreateSut(searchFor);

            sut.Validate(_validatorMockContext.ValidatorMock.Object);

            _validatorMockContext.StringValidatorMock.Verify(m => m.ShouldNotBeNullOrWhiteSpace(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, searchFor) == 0),
                                                                 It.Is <Type>(value => value == sut.GetType()),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "SearchFor") == 0)),
                                                             Times.Once);
        }
        public async Task QueryAsync_WhenCalledAndContactCollectionWasReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasCalledOnContactRepositoryWithMatchingContactCollection()
        {
            IEnumerable <IContact> microsoftGraphContactCollection = new List <IContact>
            {
                _fixture.BuildContactMock(isMatch: true).Object,
                _fixture.BuildContactMock(isMatch: false).Object,
                _fixture.BuildContactMock(isMatch: true).Object,
                _fixture.BuildContactMock(isMatch: false).Object,
                _fixture.BuildContactMock(isMatch: true).Object,
                _fixture.BuildContactMock(isMatch: false).Object,
                _fixture.BuildContactMock(isMatch: true).Object
            };
            QueryHandler sut = CreateSut(microsoftGraphContactCollection: microsoftGraphContactCollection);

            IGetMatchingContactCollectionQuery query = CreateGetMatchingContactCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.Is <IEnumerable <IContact> >(value => value.All(contact => contact.IsMatch(It.IsAny <string>(), It.IsAny <SearchOptions>())))), Times.Once);
        }
        protected override async Task <IEnumerable <IContact> > GetDataAsync(IGetMatchingContactCollectionQuery query, IRefreshableToken token)
        {
            NullGuard.NotNull(query, nameof(query))
            .NotNull(token, nameof(token));

            string        searchFor     = query.SearchFor;
            SearchOptions searchOptions = query.SearchOptions;

            IEnumerable <IContact> contacts = await MicrosoftGraphRepository.GetContactsAsync(token);

            if (contacts == null)
            {
                return(new List <IContact>(0));
            }

            IEnumerable <IContact> matchingContacts = contacts
                                                      .Where(contact => contact.IsMatch(searchFor, searchOptions))
                                                      .ToArray();

            return(await ContactRepository.ApplyContactSupplementAsync(matchingContacts));
        }
Beispiel #16
0
        public async Task <IActionResult> LoadContacts(string filter = null, string externalIdentifier = null)
        {
            IRefreshableToken token = await _tokenHelperFactory.GetTokenAsync <IRefreshableToken>(TokenType.MicrosoftGraphToken, HttpContext);

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

            IEnumerable <IContact> contacts;

            if (string.IsNullOrWhiteSpace(filter))
            {
                IGetContactCollectionQuery query = CreateContactQueryBase <GetContactCollectionQuery>(token);
                contacts = await _queryBus.QueryAsync <IGetContactCollectionQuery, IEnumerable <IContact> >(query);
            }
            else
            {
                IGetMatchingContactCollectionQuery query = CreateContactQueryBase <GetMatchingContactCollectionQuery>(token);
                query.SearchFor               = filter;
                query.SearchWithinName        = true;
                query.SearchWithinMailAddress = true;
                query.SearchWithinHomePhone   = true;
                query.SearchWithinMobilePhone = true;
                contacts = await _queryBus.QueryAsync <IGetMatchingContactCollectionQuery, IEnumerable <IContact> >(query);
            }

            IEnumerable <ContactInfoViewModel> contactInfoViewModels = contacts.AsParallel()
                                                                       .Select(contact => _contactViewModelConverter.Convert <IContact, ContactInfoViewModel>(contact))
                                                                       .OrderBy(contactInfoViewModel => contactInfoViewModel.DisplayName)
                                                                       .ToList();

            if (string.IsNullOrWhiteSpace(externalIdentifier) == false)
            {
                ViewData.Add("ExternalIdentifier", externalIdentifier);
            }

            return(PartialView("_ContactCollectionPartial", contactInfoViewModels));
        }