Exemplo 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 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);
        }
        // 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);
        }
Exemplo n.º 4
0
        public void CreateTransfer_test(string senderUsername, string receiverUsername, int transferType, double amount)
        {
            //todo this should be in the TransferController test. If we knew how to test controllers that is...
            //arrange
            AccountSqlDAO  accountDao        = new AccountSqlDAO(connectionString);
            UserSqlDAO     userDao           = new UserSqlDAO(connectionString);
            int            senderAccountId   = (int)accountDao.GetDefaultAccountIdForUserId(userDao.GetApiUser(senderUsername).UserId);
            int            receiverAccountId = (int)accountDao.GetDefaultAccountIdForUserId(userDao.GetApiUser(receiverUsername).UserId);
            TransferStatus transferStatus    = transferType == (int)TransferType.Send ? TransferStatus.Approved : TransferStatus.Pending;
            Transfer       transferToCreate  = new Transfer()
            {
                AccountFromId  = senderAccountId,
                AccountToId    = receiverAccountId,
                TransferType   = (TransferType)transferType,
                TransferStatus = transferStatus,
                Amount         = (decimal)amount
            };


            //act
            Transfer actualTransfer = dao.CreateTransfer(transferToCreate);

            //assert
            Assert.IsNotNull(actualTransfer);
            Assert.AreEqual(transferToCreate.AccountFromId, actualTransfer.AccountFromId);
            Assert.AreEqual(senderUsername, actualTransfer.UsernameFrom);
            Assert.AreEqual(transferToCreate.AccountToId, actualTransfer.AccountToId);
            Assert.AreEqual(receiverUsername, actualTransfer.UsernameTo);
            Assert.AreEqual(transferToCreate.TransferType, actualTransfer.TransferType);
            Assert.AreEqual(transferToCreate.TransferStatus, actualTransfer.TransferStatus);
            Assert.AreEqual(transferToCreate.Amount, actualTransfer.Amount);
        }
Exemplo n.º 5
0
        public void TestInitializer()
        {
            this.transaction = new TransactionScope();

            connectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=DemoDB;Integrated Security=True";
            dao = new UserSqlDAO(connectionString);
        }
Exemplo n.º 6
0
        public void Test_DeleteUser()
        {
            UserSqlDAO testDAO = new UserSqlDAO(connectionString);

            AddTestUser();
            User testUser = testDAO.GetUser("usernameTest");

            Assert.AreEqual(true, testDAO.DeleteUser(testUser));
        }
        public void GetUserTest()
        {
            UserSqlDAO access = new UserSqlDAO(connectionString);

            User user = access.GetUser("notauser");

            Assert.IsNotNull(user);

            Assert.AreEqual("user", user.Role);
        }
Exemplo n.º 8
0
        public void Test_GetUser()
        {
            UserSqlDAO testDAO   = new UserSqlDAO(connectionString);
            int        newUserId = AddTestUser();

            Assert.AreEqual("usernameTest", testDAO.GetUser("usernameTest").Username);
            Assert.AreEqual("passwordTest", testDAO.GetUser("usernameTest").Password);
            Assert.AreEqual("roleTest", testDAO.GetUser("usernameTest").Role);
            Assert.AreEqual("saltTest", testDAO.GetUser("usernameTest").Salt);
        }
Exemplo n.º 9
0
        public void Test_CreateUser()
        {
            UserSqlDAO testDAO  = new UserSqlDAO(connectionString);
            User       testUser = new User();

            testUser.Password = "******";
            testUser.Username = "******";
            testUser.Role     = "role";
            testUser.Salt     = "salt";

            Assert.AreEqual(true, testDAO.CreateUser(testUser));
        }
        public void AddUserTest()
        {
            UserSqlDAO access = new UserSqlDAO(connectionString);

            User user = access.AddUser("anotheruser", "password", "admin");

            Assert.IsNotNull(user);

            Assert.AreEqual("admin", user.Role);

            user = access.GetUser("anotheruser");

            Assert.IsNotNull(user);

            Assert.AreEqual("admin", user.Role);
        }
Exemplo n.º 11
0
        // This unit test is designed to verify the CreateUser method is adding a new row on the user db table
        public void CreateUser_ShouldAddNewRowItem()
        {
            //ARRANGE
            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);
            int actual = this.GetRowCount("users");

            //ASSERT
            Assert.AreEqual(2, actual);
        }
Exemplo n.º 12
0
 public MyHangmanController(UserSqlDAO userDAO)
 {
     this.userDAO = userDAO;
 }
Exemplo n.º 13
0
        public void ArrangeForEachTest()
        {
            this.dao = new UserSqlDAO(connectionString);

            SetupDB();
        }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            IUserDAO userDAO = new UserSqlDAO(@"Data Source =.\SQLEXPRESS;Initial Catalog = tenmo; Integrated Security = True");

            CreateWebHostBuilder(args).Build().Run();
        }
Exemplo n.º 15
0
 public override void Setup()
 {
     base.Setup();
     dao = new UserSqlDAO(connectionString);
 }