Esempio n. 1
0
        private ProfileController NewController()
        {
            List <Claim> claims = new List <Claim>()
            {
                // Passing in username as parameter
                new Claim(ClaimTypes.Name, "Ted"),
            };

            ClaimsIdentity  identity        = new ClaimsIdentity(claims, "TestAuthType");
            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);

            UserSqlDAO    userDao    = new UserSqlDAO(ConnectionString);
            ProfileSqlDAO profileDao = new ProfileSqlDAO(ConnectionString);

            ProfileController controller = new ProfileController(userDao, profileDao)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = claimsPrincipal
                    }
                }
            };

            return(controller);
        }
        // This is an integration test comparing ability of adding an associated profile to a user
        public void CreateProfile_ShouldAddNewRowItem()
        {
            //ARRANGE
            ProfileSqlDAO profileDAO = new ProfileSqlDAO("Server=.\\SQLEXPRESS;Database=DemoDB;Trusted_Connection=True;");
            UserSqlDAO    userDAO    = new UserSqlDAO("Server=.\\SQLEXPRESS;Database=DemoDB;Trusted_Connection=True;");


            //ACT
            User user = new User()
            {
                Username = "******", Password = "******", Salt = "salt", Role = "role"
            };

            user.Id = (userDAO.CreateUser(user)).Id;

            Profile profile = new Profile()
            {
                UserId = user.Id, Name = "Name", CurrentWeight = 100, GoalWeight = 200, BirthDate = DateTime.Today, Feet = 6, Inches = 9, ActivityLevel = "moderate", Gender = 'F', Timeline = "Maintain", UserImage = ""
            };

            profileDAO.CreateProfile(profile);
            int actual = this.GetRowCount("user_profiles");

            //ASSERT
            Assert.AreEqual(2, actual);
        }