[TestMethod()] public void Should_Password_Equal_To_ConfirmPassword() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai", Password = "a121ww123", ConfirmPassword = "a121ww1231" }; string expected = "password is not equal to confirmPassword"; string actual = target.CreateUser(user); Assert.AreEqual(expected, actual); } [TestMethod()] public void Should_Creator_Not_Null_Or_Empty() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai", Password = "a121ww123", ConfirmPassword = "a121ww1231" }; string expected = "password is not equal to confirmPassword"; string actual = target.CreateUser(user); Assert.AreEqual(expected, actual); } [TestMethod()] public void Should_CreateDate_Assigned_Value() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai", Password = "a121ww123", ConfirmPassword = "a121ww123", Creator = "ethan.cai" }; string expected = "createdate must be assigned value"; string actual = target.CreateUser(user); Assert.AreEqual(expected, actual); } [TestMethod()] public void Should_CreatorIP_Not_Null_Or_Empty() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai", Password = "a121ww123", ConfirmPassword = "a121ww123", Creator = "ethan.cai", CreateDate = DateTime.Now }; string expected = "creatorIP is null or empty"; string actual = target.CreateUser(user); Assert.AreEqual(expected, actual); } [TestMethod()] public void Should_Trim_Username() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai ", Password = "a121ww123", ConfirmPassword = "a121ww123", Creator = "ethan.cai", CreateDate = DateTime.Now, CreatorIP = "127.0.0.1" }; string expected = "ethan.cai"; target.CreateUser(user); Assert.AreEqual(expected, user.Username); } [TestMethod()] public void Should_Save_MD5_Hash_Password() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai ", Password = "a121ww123", ConfirmPassword = "a121ww123", Creator = "ethan.cai", CreateDate = DateTime.Now, CreatorIP = "127.0.0.1" }; string actual = target.CreateUser(user); Assert.IsTrue("success" == actual && user.Password == BitConverter.ToString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes("a121ww123")))); } [TestMethod()] public void Should_Create_User_Successfully_When_User_Is_OK() { UserBusiness target = new UserBusiness(); User user = new User() { Username = "ethan.cai ", Password = "a121ww123", ConfirmPassword = "a121ww123", Creator = "ethan.cai", CreateDate = DateTime.Now, CreatorIP = "127.0.0.1" }; string expected = "success"; string actual = target.CreateUser(user); Assert.IsTrue(expected == actual); } } |