예제 #1
0
        public async Task Test_Create_Add_ScopesSecretsAsync()
        {
            var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1);

            var queryNames = from item in insertResult
                             select item.Record.Name;
            var nameList = queryNames.ToList();

            var adminStore = new IdentityServer3AdminStore();
            var stored     = await adminStore.FindScopesAsync(nameList);

            Assert.AreEqual(stored.Count(), insertResult.Count);
            var secretComparer = SecretComparer.OrdinalIgnoreCase;
            var scopeComparer  = ScopeComparer.OrdinalIgnoreCase;

            var scope       = await insertResult[0].Record.MakeIdentityServerScopeAsync();
            var storedScope = stored.FirstOrDefault();

            Assert.IsTrue(scopeComparer.Equals(scope, storedScope));

            List <Secret> secrets = new List <Secret>();

            for (int i = 0; i < 2; ++i)
            {
                secrets.Add(new Secret()
                {
                    Value       = Guid.NewGuid().ToString(),
                    Description = Guid.NewGuid().ToString(),
                    Expiration  = DateTimeOffset.UtcNow.AddHours(1),
                    Type        = Guid.NewGuid().ToString()
                });
            }
            List <Secret> expected = storedScope.ScopeSecrets.Union(secrets, SecretComparer.OrdinalIgnoreCase).ToList();
            await adminStore.AddScopeSecretsAsync(insertResult[0].Record.Name, secrets);

            stored = await adminStore.FindScopesAsync(nameList);

            storedScope = stored.FirstOrDefault();
            Assert.IsTrue(scopeComparer.Equals(scope, storedScope));

            var query = from item in storedScope.ScopeSecrets
                        where !expected.Contains(item, secretComparer)
                        select item;
            var finalList = query.ToList();

            Assert.IsTrue(finalList.Count == 0);
        }