예제 #1
0
        public async Task add_read_delete_persisted_grants()
        {
            var theStore = AutofacStoreFactory.Resolve <IPersistedGrantStore>();
            var grants   = ModelTests.MakeNewPersistedGrantModels(10).ToPersistedGrants();

            var clientId  = Guid.NewGuid().ToString();
            var subjectId = Guid.NewGuid().ToString();
            var type      = Guid.NewGuid().ToString();
            int i         = 0;

            foreach (var grant in grants)
            {
                grant.SubjectId = subjectId;
                grant.ClientId  = clientId;
                if (i % 2 == 0)
                {
                    grant.Type = type;
                }
                await theStore.StoreAsync(grant);

                ++i;
            }

            var expectedGrantModels = grants.ToPersistedGrantModels();


            var result = await theStore.GetAllAsync(subjectId);

            var resultList = result.ToList();

            var readGrantModels = resultList.ToPersistedGrantModels();

            string additionalInfo = null;

            expectedGrantModels.ShouldBe(readGrantModels, additionalInfo);



            Assert.IsNotNull(result);
            Assert.AreEqual(grants.Count, resultList.Count());



            foreach (var grant in grants)
            {
                await theStore.RemoveAsync(grant.Key);
            }

            result = await theStore.GetAllAsync(subjectId);

            Assert.IsFalse(result.Any());
        }
예제 #2
0
        public async Task add_read_delete_persisted_grants_by_subjectid_and_type()
        {
            var theStore = AutofacStoreFactory.Resolve <IPersistedGrantStore>();
            var grants   = ModelTests.MakeNewPersistedGrantModels(10).ToPersistedGrants();

            var clientId  = Guid.NewGuid().ToString();
            var subjectId = Guid.NewGuid().ToString();
            var type      = Guid.NewGuid().ToString();
            int i         = 0;

            foreach (var grant in grants)
            {
                grant.SubjectId = subjectId;
                grant.ClientId  = clientId;
                if (i % 2 == 0)
                {
                    grant.Type = type;
                }
                await theStore.StoreAsync(grant);

                ++i;
            }

            var results = await theStore.GetAllAsync(subjectId);

            Assert.IsNotNull(results);
            Assert.AreEqual(grants.Count, results.Count());


            foreach (var result in results)
            {
                result.SubjectId.ShouldBe(subjectId);
            }

            await theStore.RemoveAllAsync(subjectId, clientId, type);

            results = await theStore.GetAllAsync(subjectId);

            foreach (var result in results)
            {
                result.SubjectId.ShouldBe(subjectId);
            }

            Assert.IsTrue(results.Any());
            Assert.AreEqual(results.Count(), grants.Count / 2);
        }
        public async Task add_read_delete_persisted_grants_by_subjectid()
        {
            var theStore = AutofacStoreFactory.Resolve <IPersistedGrantStore>();
            var grants   = ModelTests.MakeNewPersistedGrantModels(10).ToPersistedGrants();

            var clientId  = Guid.NewGuid().ToString();
            var subjectId = Guid.NewGuid().ToString();
            var type      = Guid.NewGuid().ToString();
            int i         = 0;

            foreach (var grant in grants)
            {
                grant.ClientId = clientId;
                if (i % 2 == 0)
                {
                    grant.SubjectId = subjectId;
                    grant.Type      = type;
                }
                await theStore.StoreAsync(grant);

                ++i;
            }

            var results = await theStore.GetAllAsync(subjectId);

            Assert.IsNotNull(results);
            Assert.AreEqual(grants.Count / 2, Enumerable.Count <PersistedGrant>(results));

            foreach (var result in results)
            {
                ShouldBeStringTestExtensions.ShouldBe(result.SubjectId, subjectId);
            }



            await theStore.RemoveAllAsync(subjectId, clientId);

            results = await theStore.GetAllAsync(subjectId);

            Assert.IsFalse(Enumerable.Any <PersistedGrant>(results));
        }