public async Task UpdateAsync_WithNewId()
        {
            var updatedClientId = "updatedClientId";

            //Arrange
            var sut          = new ConsentStore(NhibernateSession);
            var testConsent1 = ObjectCreator.GetConsent();
            var testConsent2 = ObjectCreator.GetConsent();
            var testConsent3 = ObjectCreator.GetConsent();

            ExecuteInTransaction(session =>
            {
                session.Save(testConsent1);
                session.Save(testConsent2);
                session.Save(testConsent3);
            });

            var modelToUpdate = await sut.LoadAsync(testConsent1.Subject, testConsent1.ClientId);

            //Act
            modelToUpdate.ClientId = updatedClientId;
            await sut.UpdateAsync(modelToUpdate);

            ExecuteInTransaction(session =>
            {
                //Assert
                var updatedEntity = session.Query <IdentityServer3.Contrib.Nhibernate.Entities.Consent>()
                                    .SingleOrDefault(c => c.ClientId == modelToUpdate.ClientId && c.Subject == modelToUpdate.Subject);

                Assert.NotNull(updatedEntity);

                //CleanUp
                session.Delete(testConsent1);
                session.Delete(testConsent2);
                session.Delete(testConsent3);
                session.Delete(updatedEntity);
            });
        }
Exemple #2
0
        public async Task TestUpdateAsync()
        {
            var store         = new ConsentStore();
            var insertClients = await CassandraTestHelper.InsertTestData_Clients(1);

            var     client  = insertClients[0];
            Consent consent = new Consent()
            {
                ClientId = client.ClientId,
                Scopes   = new List <string>()
                {
                    "Scope 0:",
                    "Scope 1:"
                },
                Subject = Guid.NewGuid().ToString()
            };
            await store.UpdateAsync(consent);

            var result = await store.LoadAsync(consent.Subject, consent.ClientId);

            Assert.AreEqual(consent.ClientId, result.ClientId);
            Assert.AreEqual(consent.Subject, result.Subject);
        }
        public void TestUpdateAsync()
        {
            Consent consent = new Consent()
            {
                ClientId = "CLIENTID", Scopes = new List <string>()
                {
                    "a", "b"
                }, Subject = "SUBJECT"
            };
            ConsentRecord consentRecord = new ConsentRecord(new ConsentHandle(consent));

            _consentStore.CreateAsync(consentRecord.Record);

            var           result = _consentStore.LoadAsync(consentRecord.Record.Subject, consentRecord.Record.ClientId);
            ConsentRecord consentRecordStored = new ConsentRecord(new ConsentHandle(result.Result));


            Assert.AreEqual(consentRecord.Id, consentRecordStored.Id);

            consentRecord.Record.Scopes = new List <string>()
            {
                "c", "d"
            };
            _consentStore.UpdateAsync(consentRecord.Record);
            result = _consentStore.LoadAsync(consentRecord.Record.Subject, consentRecord.Record.ClientId);
            consentRecordStored = new ConsentRecord(new ConsentHandle(result.Result));


            Assert.AreEqual(consentRecord.Id, consentRecordStored.Id);

            var query = from item in consentRecordStored.Record.Scopes
                        where item == "c"
                        select item;

            Assert.IsTrue(query.Any());
        }
        public async Task UpdateAsync_WithUpdatedScopes()
        {
            //Arrange
            var sut          = new ConsentStore(NhibernateSession);
            var testConsent1 = ObjectCreator.GetConsent();
            var testConsent2 = ObjectCreator.GetConsent();
            var testConsent3 = ObjectCreator.GetConsent();

            ExecuteInTransaction(session =>
            {
                session.Save(testConsent1);
                session.Save(testConsent2);
                session.Save(testConsent3);
            });

            var modelToUpdate = await sut.LoadAsync(testConsent1.Subject, testConsent1.ClientId);

            modelToUpdate.Scopes = ObjectCreator.GetScopes(5).Select(s => s.Name);

            //Act
            await sut.UpdateAsync(modelToUpdate);

            //Assert
            var updatedModel = await sut.LoadAsync(modelToUpdate.Subject, modelToUpdate.ClientId);

            Assert.NotNull(updatedModel);
            Assert.True(updatedModel.Scopes.Count() == 5);

            //CleanUp
            ExecuteInTransaction(session =>
            {
                session.Delete(testConsent1);
                session.Delete(testConsent2);
                session.Delete(testConsent3);
            });
        }