コード例 #1
0
        public bool Update(AdminUserModelDAL adminUser)
        {
            try
            {
                using (var DBConnection = new DB(false))
                {
                    var adminUserFound = DBConnection.AdminUsers.Find(adminUser.Username);

                    if (adminUserFound == null)
                    {
                        Loggings.GeneralLog("Could not find Admin User: "******"Updated credentials for Admin User: "******"Exception",
                    Created_By   = "System",
                    LogMessage   = ex.ToString(),
                    Created_date = DateTime.Now
                };
                Loggings.LogToBoth(logg);
                return(false);
            }
        }
コード例 #2
0
        public void GetAll_WhenTwoExistingUsers_ExpectedResultAreEqual()
        {
            //Arrange
            var DALStub          = new AdminUserDALStub();
            var defaultAdminUser = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234")
            };
            var newAdminUser = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("newadmin")
            };
            bool successfullCreate = DALStub.Create(newAdminUser);
            var  expectedResult    = new List <AdminUserModelDAL>();

            expectedResult.Add(defaultAdminUser);
            expectedResult.Add(newAdminUser);

            //Act
            var result = DALStub.GetAll();

            //Assert
            Assert.IsTrue(expectedResult.Count == result.Count);
            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(expectedResult[i].Username, result[i].Username);
            }
        }
コード例 #3
0
        public void Delete_WhenTwoExistingUsers_ExpectedResultCount1()
        {
            //Arrange
            var DALStub          = new AdminUserDALStub();
            var defaultAdminUser = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234")
            };
            var adminUserToDelete = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("torspassword")
            };
            bool successfullCreate = DALStub.Create(adminUserToDelete);
            var  expectedResult    = new List <AdminUserModelDAL>();

            expectedResult.Add(defaultAdminUser);

            //Act
            bool successfullDelete = DALStub.Delete("tor");
            var  result            = DALStub.GetAll();

            //Assert
            Assert.IsTrue(successfullCreate);       // Here to make sure the test doesnt pass from it's target not existing
            Assert.IsTrue(successfullDelete);       // Test to se if Delete() is executed
            Assert.IsTrue(result.Count == 1);       // Test to se if Count is back to one
            for (int i = 0; i < result.Count; i++)  // Test to se if correct user has been deleted by comparing to expectations
            {
                Assert.AreEqual(expectedResult[i].Username, result[i].Username);
            }
        }
コード例 #4
0
        public bool Create(AdminUserModelDAL adminuser)
        {
            try
            {
                using (var DBConnection = new DB())
                {
                    DBConnection.AdminUsers.Add(adminuser);
                    DBConnection.SaveChanges();

                    Loggings.GeneralLog("Created Admin User: "******"Exception",
                    Created_By   = "System",
                    LogMessage   = ex.ToString(),
                    Created_date = DateTime.Now
                };
                Loggings.LogToBoth(logg);
                return(false);
            }
        }
コード例 #5
0
        public bool CheckLoginCredentials(AdminUserModelDAL userInput)
        {
            using (var db = new DB(false))
            {
                var allAdminUsers = db.AdminUsers.ToList();

                var foundAdminUser = db.AdminUsers.FirstOrDefault(b => b.Username.Equals(userInput.Username));

                if (foundAdminUser == null)
                {
                    Loggings.GeneralLog("No Admin User was found using the Username: "******"Admin User: "******" Used the correct login credecials");
                    return(true);
                }
                else
                {
                    Loggings.GeneralLog("Admin User: "******" Used the incorrect login credecials");
                    return(false);
                }
            }
        }
コード例 #6
0
        public static AdminUserModelBLL MapFromAdminUsersDALToAdminUsersBLL(AdminUserModelDAL adminUserModelDAL)
        {
            var adminUserModelBLL = new AdminUserModelBLL()
            {
                UserName = adminUserModelDAL.Username
            };

            return(adminUserModelBLL);
        }
コード例 #7
0
        public bool Create(AdminUserModelDAL adminuser)
        {
            if (adminuser.Username == "" || !adminuser.HashedPassword.Any())
            {
                return(false);
            }

            _AdminUserDB.Add(adminuser);
            return(true);
        }
コード例 #8
0
        public bool CheckLoginCredentials(AdminUserModelBLL userInput)
        {
            var adminUserModelDAL = new AdminUserModelDAL()
            {
                Username       = userInput.UserName,
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher(userInput.Password)
            };

            return(_adminUserDAL.CheckLoginCredentials(adminUserModelDAL));
        }
コード例 #9
0
        public bool RegisterAdminUser(AdminUserModelBLL userInput)
        {
            var adminUserModelDAL = new AdminUserModelDAL()
            {
                Username       = userInput.UserName,
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher(userInput.Password)
            };

            return(_adminUserDAL.Create(adminUserModelDAL));
        }
コード例 #10
0
        //Summary: Update a customer
        public bool Update(AdminUserModelBLL adminModelBLL)
        {
            var adminModelDAL = new AdminUserModelDAL()
            {
                Username       = adminModelBLL.UserName,
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher(adminModelBLL.Password)
            };

            var result = _adminUserDAL.Update(adminModelDAL);

            return(result);
        }
コード例 #11
0
        public bool Update(AdminUserModelDAL adminUser)
        {
            var adminUserFound = _AdminUserDB.FirstOrDefault(b => b.Username.Equals(adminUser.Username));

            if (adminUserFound == null)
            {
                return(false);
            }

            _AdminUserDB.Remove(adminUserFound);
            _AdminUserDB.Add(adminUser);
            return(true);
        }
コード例 #12
0
        public AdminUserDALStub()
        {
            _AdminUserDB = new List <AdminUserModelDAL>();

            //Seed an admin user in "artificial" database
            var seed = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234")
            };

            _AdminUserDB.Add(seed);
        }
コード例 #13
0
        public void CheckLoginCredentials_WhenWrongPassword_ExpectedResultFalse()
        {
            //Arrange
            var DALStub = new AdminUserDALStub();
            var input   = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("admin")
            };

            //Act
            bool test = DALStub.CheckLoginCredentials(input);

            //Assert
            Assert.IsFalse(test);
        }
コード例 #14
0
        public void CheckLoginCredentials_WhenCorrectCombination_ExpectedResultTrue()
        {
            //Arrange
            var DALStub = new AdminUserDALStub();
            var input   = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234")
            };

            //Act
            bool test = DALStub.CheckLoginCredentials(input);

            //Assert
            Assert.IsTrue(test);
        }
コード例 #15
0
        public void Update_WhenUserNotExists_ExpectedResultFalse()
        {
            //Arrange
            var DALStub = new AdminUserDALStub();
            var input   = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("newpassword")
            };

            //Act
            bool test = DALStub.Update(input);

            //Assert
            Assert.IsFalse(test);
        }
コード例 #16
0
        public void Get_WhenOnExistingUser_ExpectedResultAreEqual()
        {
            //Arrange
            var DALStub = new AdminUserDALStub();
            var initial = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("1234")
            };

            //Act
            var result = DALStub.Get("admin");

            //Assert
            Assert.AreEqual(initial.Username, result.Username);
        }
コード例 #17
0
        public void Create_WhenEmptyUsername_ExpectedResultFalse()
        {
            //Arrange
            var DALStub = new AdminUserDALStub();
            var input   = new AdminUserModelDAL
            {
                Username       = "",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("password")
            };

            //Act
            bool test = DALStub.Create(input);

            //Assert
            Assert.IsFalse(test);
        }
コード例 #18
0
        public bool CheckLoginCredentials(AdminUserModelDAL userInput)
        {
            var foundAdminUser = _AdminUserDB.Find(b => b.Username.Equals(userInput.Username));

            if (foundAdminUser == null)
            {
                return(false);
            }

            if (foundAdminUser.HashedPassword.SequenceEqual(userInput.HashedPassword))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #19
0
        public void Create_WhenAllOK_ExpectedResultTrueAreEqual()
        {
            //Arrange
            var DALStub = new AdminUserDALStub();
            var input   = new AdminUserModelDAL
            {
                Username       = "******",
                HashedPassword = PasswordHelperTool.PasswordSHA256Hasher("password")
            };

            //Act
            bool test   = DALStub.Create(input);
            var  result = DALStub.Get("newadmin");

            //Assert
            Assert.IsTrue(test);
            Assert.AreEqual(input, result);
        }