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 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 QueryAsync_WhenQueryIsNull_ThrowsArgumentNullException()
        {
            QueryHandler sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.QueryAsync(null));

            Assert.That(result.ParamName, Is.EqualTo("query"));
        }
        public async Task QueryAsync_WhenCalled_AssertSearchOptionsWasCalledOnGetMatchingContactCollectionQuery()
        {
            QueryHandler sut = CreateSut();

            Mock <IGetMatchingContactCollectionQuery> queryMock = CreateGetMatchingContactCollectionQueryMock();
            await sut.QueryAsync(queryMock.Object);

            queryMock.Verify(m => m.SearchOptions, Times.Once);
        }
        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 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);
        }