public async Task UpcomingBirthdays_WhenNoTokenWasReturnedFromTokenHelperFactory_ReturnsUnauthorizedResult()
        {
            Controller sut = CreateSut(false);

            IActionResult result = await sut.UpcomingBirthdays(_fixture.Create <int>());

            Assert.That(result, Is.TypeOf <UnauthorizedResult>());
        }
        public async Task UpcomingBirthdays_WhenNoTokenWasReturnedFromTokenHelperFactory_AssertQueryAsyncWasNotCalledOnQueryBus()
        {
            Controller sut = CreateSut(false);

            await sut.UpcomingBirthdays(_fixture.Create <int>());

            _queryBusMock.Verify(m => m.QueryAsync <IGetContactWithBirthdayCollectionQuery, IEnumerable <IContact> >(It.IsAny <IGetContactWithBirthdayCollectionQuery>()), Times.Never);
        }
        public async Task UpcomingBirthdays_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsPartialViewResultWhereViewNameIsEqualToUpcomingBirthdayCollectionPartial()
        {
            Controller sut = CreateSut();

            PartialViewResult result = (PartialViewResult)await sut.UpcomingBirthdays(_fixture.Create <int>());

            Assert.That(result.ViewName, Is.EqualTo("_UpcomingBirthdayCollectionPartial"));
        }
        public async Task UpcomingBirthdays_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsPartialViewResult()
        {
            Controller sut = CreateSut();

            IActionResult result = await sut.UpcomingBirthdays(_fixture.Create <int>());

            Assert.That(result, Is.TypeOf <PartialViewResult>());
        }
        public async Task UpcomingBirthdays_WhenCalled_AssertGetTokenAsyncWasCalledOnTokenHelperFactory()
        {
            Controller sut = CreateSut();

            await sut.UpcomingBirthdays(_fixture.Create <int>());

            _tokenHelperFactoryMock.Verify(m => m.GetTokenAsync <IRefreshableToken>(
                                               It.Is <TokenType>(value => value == TokenType.MicrosoftGraphToken),
                                               It.IsAny <HttpContext>()),
                                           Times.Once);
        }
        public async Task UpcomingBirthdays_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsPartialViewResultWhereModelIsCollectionOfContactWithUpcomingBirthdayViewModel()
        {
            IEnumerable <IContact> contactCollection = _fixture.CreateMany <IContact>(_random.Next(10, 15)).ToList();
            Controller             sut = CreateSut(contactCollection: contactCollection);

            PartialViewResult result = (PartialViewResult)await sut.UpcomingBirthdays(_fixture.Create <int>());

            Assert.That(result.Model, Is.TypeOf <List <ContactWithUpcomingBirthdayViewModel> >());

            List <ContactWithUpcomingBirthdayViewModel> contactViewModelCollection = (List <ContactWithUpcomingBirthdayViewModel>)result.Model;

            Assert.That(contactViewModelCollection, Is.Not.Null);
            Assert.That(contactViewModelCollection, Is.Not.Empty);
            Assert.That(contactViewModelCollection.Count, Is.EqualTo(contactCollection.Count()));
            Assert.That(contactViewModelCollection.All(contactViewModel => contactCollection.Any(contact => string.CompareOrdinal(contact.ExternalIdentifier, contactViewModel.ExternalIdentifier) == 0)), Is.True);
        }
        public async Task UpcomingBirthdays_WhenTokenWasReturnedFromTokenHelperFactory_AssertQueryAsyncWasCalledOnQueryBus()
        {
            string            tokenType        = _fixture.Create <string>();
            string            accessToken      = _fixture.Create <string>();
            string            refreshToken     = _fixture.Create <string>();
            DateTime          expires          = DateTime.Now.AddSeconds(_random.Next(60, 300));
            IRefreshableToken refreshableToken = _fixture.BuildRefreshableTokenMock(tokenType, accessToken, refreshToken, expires).Object;
            Controller        sut = CreateSut(refreshableToken: refreshableToken);

            int withinDays = _fixture.Create <int>();
            await sut.UpcomingBirthdays(withinDays);

            _queryBusMock.Verify(m => m.QueryAsync <IGetContactWithBirthdayCollectionQuery, IEnumerable <IContact> >(It.Is <IGetContactWithBirthdayCollectionQuery>(query =>
                                                                                                                                                                    query != null &&
                                                                                                                                                                    query.BirthdayWithinDays == withinDays &&
                                                                                                                                                                    string.CompareOrdinal(query.TokenType, tokenType) == 0 &&
                                                                                                                                                                    string.CompareOrdinal(query.AccessToken, accessToken) == 0 &&
                                                                                                                                                                    string.CompareOrdinal(query.RefreshToken, refreshToken) == 0 &&
                                                                                                                                                                    query.Expires == expires)),
                                 Times.Once);
        }