Ejemplo n.º 1
0
        public async Task Test_Create_Add_Delete_ClientClaims_ByClientIdAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(insert[0].ClientName, result.ClientName);

            var original = result.Claims;

            var newClaims = new List <Claim> {
                new Claim(Constants.ClaimTypes.Subject, Guid.NewGuid().ToString()),
                new Claim(Constants.ClaimTypes.PreferredUserName, Guid.NewGuid().ToString()),
            };

            var finalList = new List <Claim>();

            finalList.AddRange(original);
            finalList.AddRange(newClaims);


            await adminStore.AddClaimsToClientAsync(insert[0].ClientId, newClaims);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Claims.Count(), finalList.Count);

            var ff = result.Claims.Except(finalList, ClaimComparer.DeepComparer);

            Assert.IsFalse(ff.Any());

            await adminStore.DeleteClaimsFromClientAsync(insert[0].ClientId, result.Claims);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);

            Assert.IsFalse(result.Claims.Any());
        }