public void FileTokenStorageIntegrationTest_RequestTokenForUnrecognizedEmail_GetAccessToken_ReturnsFalse()
        {
            // arrange
            var fileIOProvider = new FileIOProvider();
            var tokenSerializer = new TokenCollectionSerializer();
            var tokenStorage = new FileTokenStorageService(fileIOProvider, tokenSerializer, GetRandomPath());
            var email = "*****@*****.**";

            // act
            tokenStorage.StoreAccessToken(email, new TokenInfo { AccessToken = "accessToken" });
            TokenInfo token;
            var result = tokenStorage.GetAccessToken(TU.RandomAlphaNumString(), out token);
            // assert
            Assert.IsFalse(result);
            Assert.IsNull(token);
        }
Ejemplo n.º 2
0
        public void FileTokenStorageTest_CannotPersistAccessToken_NullToken_ThrowsException()
        {
            //arrange
            var fileIOProvider = A.Fake<IFileIOProvider>();
            var tokenSerializer = A.Fake<ITokenCollectionSerializer>();
            var tokenStorage = new FileTokenStorageService(fileIOProvider, tokenSerializer, "fileName");
            try
            {
                tokenStorage.StoreAccessToken("email", null);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
                return;
            }

            //assert
            Assert.Fail("Exception Expected.");
        }
        public void FileTokenStorageIntegrationTest_CanPersistAccessTokenAndRetrieveIt()
        {
            // arrange
            var fileIOProvider = new FileIOProvider();
            var tokenSerializer = new TokenCollectionSerializer();
            var tokenStorage = new FileTokenStorageService(fileIOProvider, tokenSerializer, GetRandomPath());
            var email = "*****@*****.**";
            var tokenInfo = new TokenInfo
            {
                AccessToken = TU.RandomAlphaNumString(),
                AccessTokenSecret = TU.RandomAlphaNumString()
            };

            // act
            tokenStorage.StoreAccessToken(email, tokenInfo);
            TokenInfo actualTokenInfo;
            var result = tokenStorage.GetAccessToken(email, out actualTokenInfo);
            // assert
            Assert.IsTrue(result);
            Assert.AreEqual(tokenInfo.AccessToken, actualTokenInfo.AccessToken);
            Assert.AreEqual(tokenInfo.AccessTokenSecret, actualTokenInfo.AccessTokenSecret);
        }
Ejemplo n.º 4
0
        public void FileTokenStorageTest_CanPersistAccessToken()
        {
            //arrange
            var fileIOProvider = A.Fake<IFileIOProvider>();
            var tokenSerializer = A.Fake<ITokenCollectionSerializer>();
            var fileContents = RandomString();
            var fileName = RandomString();
            var serializedTokenStrings = RandomString();

            A.CallTo(() => fileIOProvider.ReadFile(A<string>._))
                .Returns(fileContents);
            A.CallTo(() => tokenSerializer.DeserializeTokenEmailPairs(A<string>.Ignored))
                .Returns(new Dictionary<string, TokenInfo>
                {
                    { "*****@*****.**", new TokenInfo { AccessToken = "token1", AccessTokenSecret = "tokenSecret1" } },
                    { "*****@*****.**", new TokenInfo { AccessToken = "token2", AccessTokenSecret = "tokenSecret2" } },
                });
            A.CallTo(() => tokenSerializer.SerializeTokenEmailPairs(A<IDictionary<string, TokenInfo>>._))
                .Returns(serializedTokenStrings);

            var tokenStorage = new FileTokenStorageService(fileIOProvider,tokenSerializer, fileName);
            var email = "*****@*****.**";

            //act
            tokenStorage.StoreAccessToken(email, new TokenInfo { AccessToken = "accessToken", AccessTokenSecret = "tokenSecret" });

            //assert
            TU.MustHaveHappend(() => fileIOProvider.ReadFile(TU.Matches(fileName)));
            TU.MustHaveHappend(() => tokenSerializer.DeserializeTokenEmailPairs(TU.Matches(fileContents)));
            TU.MustHaveHappend(() => tokenSerializer.SerializeTokenEmailPairs(TU.Any<IDictionary<string, TokenInfo>>()));
            TU.MustHaveHappend(() => fileIOProvider.WriteFile(TU.Matches(fileName), TU.Matches(serializedTokenStrings)));
        }