コード例 #1
0
ファイル: UserTest.cs プロジェクト: Tomkaa/ASP.NET-Identity
        public void UserWithRolesCreationTest()
        {
            using (var db = new IdentityDbContext())
            {
                var role = new Role
                {
                    Name = "TestRole"
                };

                db.Roles.Add(role);
                db.SaveChanges();

                var user = new User
                {
                    Email = "asd",
                    FirstName = "el",
                    IsActive = true,
                    LastName = "asd",
                    LastVisitDate = DateTime.Now,
                    Password = "******",
                    RegistrationDate = DateTime.Now,
                    Salt = "asd",
                    Roles = new List<Role>
                    {
                        role
                    }
                };

                db.Users.Add(user);

                var count = db.SaveChanges();

                Assert.AreEqual(2, count);
                Assert.IsTrue(db.Users.FirstOrDefault(u => u.Id == user.Id).Roles.Contains(role));
            }
        }
コード例 #2
0
	    public AuthorizationService()
	    {
			_db = new IdentityDbContext();		    
	    }