Esempio n. 1
0
        private TrackingController 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);
            FoodSqlDAO    foodDao    = new FoodSqlDAO(ConnectionString);

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

            return(controller);
        }
        // This unit test is designed to verify the AddFoodItem method is adding a new row on the user db table
        public void AddFoodItem_ShouldAddNewRowItem()
        {
            //ARRANGE
            FoodSqlDAO foodItemDAO = new FoodSqlDAO("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"
            };

            userDAO.CreateUser(user);
            Food item = new Food()
            {
                Calories = 1000,
                Name     = "Salami",
                Fat      = 20,
                Carbs    = 10,
                Protein  = 30,
                MealType = "Lunch",
                Servings = 3,
                Date     = DateTime.Now,
                ndbno    = 200
            };

            foodItemDAO.AddFoodItem(user.Id, item);
            int actual = this.GetRowCount("food_entries");

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