public void ToGetContactCollectionQuery_WhenCalled_ReturnsGetContactCollectionQuery() { IExportContactCollectionQuery sut = CreateSut(); IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery(); Assert.That(result, Is.TypeOf <GetContactCollectionQuery>()); }
public void ToGetContactCollectionQuery_WhenCalled_ReturnsNotNull() { IExportContactCollectionQuery sut = CreateSut(); IGetContactCollectionQuery result = sut.ToGetContactCollectionQuery(); Assert.That(result, Is.Not.Null); }
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); }
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)); }
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)); }
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)); }
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); }
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); }
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); }
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)); }
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); }
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)); }
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)); }
private Mock <IExportContactCollectionQuery> CreateExportContactCollectionQueryMock(IGetContactCollectionQuery getContactCollectionQuery = null) { Mock <IExportContactCollectionQuery> queryMock = new Mock <IExportContactCollectionQuery>(); queryMock.Setup(m => m.ToGetContactCollectionQuery()) .Returns(getContactCollectionQuery ?? CreateGetContactCollectionQuery()); return(queryMock); }
private IExportContactCollectionQuery CreateExportContactCollectionQuery(IGetContactCollectionQuery getContactCollectionQuery = null) { return(CreateExportContactCollectionQueryMock(getContactCollectionQuery).Object); }