Beispiel #1
0
        public void UserData_withreference_Create_Retrive_Delete_Verify()
        {
            int preUsers = 0;
            int preIds = 0;
            using (var session = RavenDocumentStore.OpenSession())
            {
                session.Advanced.AllowNonAuthoritiveInformation = false;
                var identities = session.Query<Identity>();
                preIds = identities.Count();
                var users = session.Query<UserData>();
                preUsers = users.Count();
            }

            UserRepo repo = new UserRepo();
            string savedId;

            var id = repo.GetUserByIdentity(Id);
            Assert.IsNull(id);

            var user1 = repo.CreateUser(Id);
            savedId = user1.Id;
            user1.Claims.Add(new SimpleClaim { Subject = Id, ClaimType = "test", Issuer = "noone", Value = "dummy" });
            repo.SaveUser(user1);

            var user2 = repo.GetUserByIdentity(Id);
            Assert.IsNotNull(user2);
            Assert.AreEqual(savedId, user2.Id);
            Assert.IsTrue(user2.IdentityIds.First().Contains(Id));
            Assert.IsTrue(user2.Claims[0].Issuer == "noone");

            var user3 = repo.GetUserByIdentity(Id);
            Assert.IsNotNull(user3);
            Assert.AreEqual(savedId, user3.Id);
            repo.DeleteUser(user3);

            var user4 = repo.GetUserByIdentity(Id);
            Assert.IsNull(user4);

            using (var session = RavenDocumentStore.OpenSession())
            {
                session.Advanced.AllowNonAuthoritiveInformation = false;
                var identities = session.Query<Identity>();
                Assert.AreEqual(preIds, identities.Count());
                var users = session.Query<UserData>();
                Assert.AreEqual(preUsers, users.Count());
            }
        }