Exemplo n.º 1
0
        public void ToGetContactCollectionQuery_WhenCalled_ReturnsGetContactCollectionQuery()
        {
            IExportContactCollectionQuery sut = CreateSut();

            IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery();

            Assert.That(result, Is.TypeOf <GetContactCollectionQuery>());
        }
Exemplo n.º 2
0
        public void ToGetContactCollectionQuery_WhenCalled_ReturnsNotNull()
        {
            IExportContactCollectionQuery sut = CreateSut();

            IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery();

            Assert.That(result, Is.Not.Null);
        }
Exemplo n.º 3
0
        public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasNotCalledOnContactRepository()
        {
            QueryHandler sut = CreateSut(false);

            IGetContactCollectionQuery query = CreateGetContactCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.IsAny <IEnumerable <IContact> >()), Times.Never);
        }
Exemplo n.º 4
0
        public void ToGetContactCollectionQuery_WhenCalled_ReturnsGetContactCollectionQueryWithExpiresFromExportContactCollectionQuery()
        {
            DateTime expires = DateTime.Now.AddSeconds(_random.Next(60, 100));
            IExportContactCollectionQuery sut = CreateSut(expires: expires);

            IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery();

            Assert.That(result.Expires, Is.EqualTo(expires));
        }
Exemplo n.º 5
0
        public void ToGetContactCollectionQuery_WhenCalled_ReturnsGetContactCollectionQueryWithRefreshTokenFromExportContactCollectionQuery()
        {
            string refreshToken = _fixture.Create <string>();
            IExportContactCollectionQuery sut = CreateSut(refreshToken: refreshToken);

            IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery();

            Assert.That(result.RefreshToken, Is.EqualTo(refreshToken));
        }
Exemplo n.º 6
0
        public void ToGetContactCollectionQuery_WhenCalled_ReturnsGetContactCollectionQueryWithTokenTypeFromExportContactCollectionQuery()
        {
            string tokenType = _fixture.Create <string>();
            IExportContactCollectionQuery sut = CreateSut(tokenType);

            IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery();

            Assert.That(result.TokenType, Is.EqualTo(tokenType));
        }
Exemplo n.º 7
0
        public async Task QueryAsync_WhenCalledAndContactCollectionWasReturnedFromMicrosoftGraphRepository_AssertApplyContactSupplementAsyncWasCalledOnContactRepositoryWithContactCollectionFromMicrosoftGraphRepository()
        {
            IEnumerable <IContact> microsoftGraphContactCollection = _fixture.CreateMany <IContact>(_random.Next(5, 15)).ToList();
            QueryHandler           sut = CreateSut(microsoftGraphContactCollection: microsoftGraphContactCollection);

            IGetContactCollectionQuery query = CreateGetContactCollectionQueryMock().Object;
            await sut.QueryAsync(query);

            _contactRepositoryMock.Verify(m => m.ApplyContactSupplementAsync(It.Is <IEnumerable <IContact> >(value => value.Equals(microsoftGraphContactCollection))), Times.Once);
        }
Exemplo n.º 8
0
        public async Task QueryAsync_WhenCalledAndContactCollectionWasNotReturnedFromMicrosoftGraphRepository_ReturnsEmptyContactCollection()
        {
            QueryHandler sut = CreateSut(false);

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

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.Empty);
        }
Exemplo n.º 9
0
        public async Task QueryAsync_WhenCalled_AssertGetContactsAsyncWasCalledOnMicrosoftGraphRepository()
        {
            QueryHandler sut = CreateSut();

            IRefreshableToken          token = _fixture.BuildRefreshableTokenMock().Object;
            IGetContactCollectionQuery query = CreateGetContactCollectionQueryMock(token).Object;
            await sut.QueryAsync(query);

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

            IGetContactCollectionQuery query  = CreateGetContactCollectionQueryMock().Object;
            IEnumerable <IContact>     result = await sut.QueryAsync(query);

            Assert.That(result, Is.EqualTo(appliedContactSupplementCollection));
        }
Exemplo n.º 11
0
        public async Task QueryAsync_WhenCalled_AssertQueryAsyncWasCalledOnGetContactCollectionQueryHandler()
        {
            QueryHandler sut = CreateSut();

            IGetContactCollectionQuery    getContactCollectionQuery = CreateGetContactCollectionQuery();
            IExportContactCollectionQuery query = CreateExportContactCollectionQuery(getContactCollectionQuery);
            await sut.QueryAsync(query);

            _getContactCollectionQueryHandlerMock.Verify(m => m.QueryAsync(It.Is <IGetContactCollectionQuery>(value => value != null && value == getContactCollectionQuery)), Times.Once);
        }
Exemplo n.º 12
0
        protected override async Task <IEnumerable <IContact> > GetDataAsync(IGetContactCollectionQuery query, IRefreshableToken token)
        {
            NullGuard.NotNull(query, nameof(query))
            .NotNull(token, nameof(token));

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

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

            return(await ContactRepository.ApplyContactSupplementAsync(contacts));
        }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
0
        private Mock <IExportContactCollectionQuery> CreateExportContactCollectionQueryMock(IGetContactCollectionQuery getContactCollectionQuery = null)
        {
            Mock <IExportContactCollectionQuery> queryMock = new Mock <IExportContactCollectionQuery>();

            queryMock.Setup(m => m.ToGetContactCollectionQuery())
            .Returns(getContactCollectionQuery ?? CreateGetContactCollectionQuery());
            return(queryMock);
        }
Exemplo n.º 15
0
 private IExportContactCollectionQuery CreateExportContactCollectionQuery(IGetContactCollectionQuery getContactCollectionQuery = null)
 {
     return(CreateExportContactCollectionQueryMock(getContactCollectionQuery).Object);
 }