Example #1
0
        public async Task ExportContacts_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsFileContentResult()
        {
            Controller sut = CreateSut();

            IActionResult result = await sut.ExportContacts();

            Assert.That(result, Is.TypeOf <FileContentResult>());
        }
Example #2
0
        public async Task ExportContacts_WhenNoTokenWasReturnedFromTokenHelperFactory_ReturnsUnauthorizedResult()
        {
            Controller sut = CreateSut(false);

            IActionResult result = await sut.ExportContacts();

            Assert.That(result, Is.TypeOf <UnauthorizedResult>());
        }
Example #3
0
        public async Task ExportContacts_WhenNoTokenWasReturnedFromTokenHelperFactory_AssertQueryAsyncWasNotCalledOnQueryBus()
        {
            Controller sut = CreateSut(false);

            await sut.ExportContacts();

            _queryBusMock.Verify(m => m.QueryAsync <IExportContactCollectionQuery, byte[]>(It.IsAny <IExportContactCollectionQuery>()), Times.Never);
        }
Example #4
0
        public async Task ExportContacts_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsFileContentResultWhereFileDownloadNameIsEqualToContactsCsv()
        {
            Controller sut = CreateSut();

            FileContentResult result = (FileContentResult)await sut.ExportContacts();

            Assert.That(result.FileDownloadName, Is.EqualTo("Contacts.csv"));
        }
Example #5
0
        public async Task ExportContacts_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsFileContentResultWhereContentTypeIsEqualToApplicationCsv()
        {
            Controller sut = CreateSut();

            FileContentResult result = (FileContentResult)await sut.ExportContacts();

            Assert.That(result.ContentType, Is.EqualTo("application/csv"));
        }
Example #6
0
        public async Task ExportContacts_WhenTokenWasReturnedFromTokenHelperFactory_ReturnsFileContentResultWhereFileContentsIsEqualToByteArrayFromQueryBus()
        {
            byte[]     byteCollection = _fixture.CreateMany <byte>(_random.Next(1024, 4096)).ToArray();
            Controller sut            = CreateSut(byteCollection: byteCollection);

            FileContentResult result = (FileContentResult)await sut.ExportContacts();

            Assert.That(result.FileContents, Is.EqualTo(byteCollection));
        }
Example #7
0
        public async Task ExportContacts_WhenCalled_AssertGetTokenAsyncWasCalledOnTokenHelperFactory()
        {
            Controller sut = CreateSut();

            await sut.ExportContacts();

            _tokenHelperFactoryMock.Verify(m => m.GetTokenAsync <IRefreshableToken>(
                                               It.Is <TokenType>(value => value == TokenType.MicrosoftGraphToken),
                                               It.IsAny <HttpContext>()),
                                           Times.Once);
        }
Example #8
0
        public async Task ExportContacts_WhenTokenWasReturnedFromTokenHelperFactory_AssertQueryAsyncWasCalledOnQueryBus()
        {
            string            tokenType        = _fixture.Create <string>();
            string            accessToken      = _fixture.Create <string>();
            string            refreshToken     = _fixture.Create <string>();
            DateTime          expires          = DateTime.Now.AddMinutes(_random.Next(5, 60));
            IRefreshableToken refreshableToken = _fixture.BuildRefreshableTokenMock(tokenType, accessToken, refreshToken, expires).Object;
            Controller        sut = CreateSut(refreshableToken: refreshableToken);

            await sut.ExportContacts();

            _queryBusMock.Verify(m => m.QueryAsync <IExportContactCollectionQuery, byte[]>(It.Is <IExportContactCollectionQuery>(value => value != null && string.CompareOrdinal(value.TokenType, tokenType) == 0 && string.CompareOrdinal(value.AccessToken, accessToken) == 0 && string.CompareOrdinal(value.RefreshToken, refreshToken) == 0 && value.Expires == expires)), Times.Once);
        }