コード例 #1
0
        public async Task StoresCredentialForKeyAndGitKey()
        {
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");

                    await credentialCache.InsertObject(nameof(StoresCredentialForKeyAndGitKey), credential);

                    var retrieved = await credentialCache.GetObject<Tuple<string, string>>(nameof(StoresCredentialForKeyAndGitKey));
                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);
                    var retrieved2 = await credentialCache.GetObject<Tuple<string, string>>("git:" + nameof(StoresCredentialForKeyAndGitKey));
                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);
                }
                finally
                {
                    try
                    {
                        await credentialCache.Invalidate(nameof(StoresCredentialForKeyAndGitKey));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
コード例 #2
0
        public async Task RetrievesValueWithAlternateKeys()
        {
            const string key = nameof(RetrievesValueWithAlternateKeys);
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");
                    await credentialCache.InsertObject(key, credential);

                    var retrieved = await credentialCache.GetObject<Tuple<string, string>>(key);

                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);

                    var retrieved2 = await credentialCache.GetObject<Tuple<string, string>>("git:" + key + "/");

                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);

                    var retrieved3 = await credentialCache.GetObject<Tuple<string, string>>("login:"******"/");

                    Assert.Equal("somebody", retrieved3.Item1);
                    Assert.Equal("somebody's secret", retrieved3.Item2);
                }
                finally
                {
                    await credentialCache.Invalidate(key);
                }
            }
        }
コード例 #3
0
        public async Task StoresCredentialForKeyAndGitKey()
        {
            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");

                    await credentialCache.InsertObject(nameof(StoresCredentialForKeyAndGitKey), credential);

                    var retrieved = await credentialCache.GetObject <Tuple <string, string> >(nameof(StoresCredentialForKeyAndGitKey));

                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);
                    var retrieved2 = await credentialCache.GetObject <Tuple <string, string> >("git:" + nameof(StoresCredentialForKeyAndGitKey));

                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);
                }
                finally
                {
                    try
                    {
                        await credentialCache.Invalidate(nameof(StoresCredentialForKeyAndGitKey));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
コード例 #4
0
        public async Task RetrievesValueWithAlternateKeys()
        {
            const string key = nameof(RetrievesValueWithAlternateKeys);

            using (var credentialCache = new CredentialCache())
            {
                try
                {
                    var credential = Tuple.Create("somebody", "somebody's secret");
                    await credentialCache.InsertObject(key, credential);

                    var retrieved = await credentialCache.GetObject <Tuple <string, string> >(key);

                    Assert.Equal("somebody", retrieved.Item1);
                    Assert.Equal("somebody's secret", retrieved.Item2);

                    var retrieved2 = await credentialCache.GetObject <Tuple <string, string> >("git:" + key + "/");

                    Assert.Equal("somebody", retrieved2.Item1);
                    Assert.Equal("somebody's secret", retrieved2.Item2);

                    var retrieved3 = await credentialCache.GetObject <Tuple <string, string> >("login:"******"/");

                    Assert.Equal("somebody", retrieved3.Item1);
                    Assert.Equal("somebody's secret", retrieved3.Item2);
                }
                finally
                {
                    await credentialCache.Invalidate(key);
                }
            }
        }
コード例 #5
0
 public async Task ThrowsObservableInvalidOperationExceptionWhenRetrievingSomethingNotATuple()
 {
     using (var credentialCache = new CredentialCache())
     {
         await Assert.ThrowsAsync<InvalidOperationException>(
             async () => await credentialCache.GetObject<string>("_"));
     }
 }
コード例 #6
0
 public async Task ThrowsObservableInvalidOperationExceptionWhenRetrievingSomethingNotATuple()
 {
     using (var credentialCache = new CredentialCache())
     {
         await Assert.ThrowsAsync <InvalidOperationException>(
             async() => await credentialCache.GetObject <string>("_"));
     }
 }
コード例 #7
0
 public async Task ThrowsObjectDisposedExceptionWhenDisposed()
 {
     using (var credentialCache = new CredentialCache())
     {
         credentialCache.Dispose();
         await Assert.ThrowsAsync<ObjectDisposedException>(
             async () => await credentialCache.GetObject<Tuple<string, string>>("_"));
     }
 }
コード例 #8
0
 public async Task ThrowsObjectDisposedExceptionWhenDisposed()
 {
     using (var credentialCache = new CredentialCache())
     {
         credentialCache.Dispose();
         await Assert.ThrowsAsync <ObjectDisposedException>(
             async() => await credentialCache.GetObject <Tuple <string, string> >("_"));
     }
 }