using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using PersonalFinance; namespace PersonalFinanceTest { [TestClass] public class UserTest { [TestMethod] [ExpectedException(typeof(ArgumentNullException), "Login cannot be null!")] public void User_NullLogin() { User test = new User() { Login = null }; } [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException), "Login must be at least 3 character length!")] public void User_ShortLogin() { User test = new User() { Login = "Lg" }; } [TestMethod] public void User_SexIsNotEnum() { User item = new User() { Sex = (Sex)10, }; bool defined = Sex.IsDefined(typeof(Sex), item.Sex); Assert.IsFalse(defined, "Value is not defined enum from Sex!"); } [TestMethod] [ExpectedException(typeof(ArgumentNullException), "Password cannot be null!")] public void User_NullEncryptPassword() { User test = new User(); test.SetPassword(null); } [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException), "Password must be at least 6 character length!")] public void User_ShortEncryptPassword() { User test = new User(); test.SetPassword("12345"); } [TestMethod] public void User_RightEncryptPassword() { User test = new User(); try { test.SetPassword("123456"); } catch (Exception e) { Assert.Fail("Expected no exception, but got: " + e.Message); } } [TestMethod] public void User_CompareDifferentPasswords() { User test = new User(); test.SetPassword("123456"); Assert.IsFalse(test.ComparePassword("123456789"), "Passwords are equals but should not be!"); } [TestMethod] public void User_CompareEqualsPasswords() { User test = new User(); test.SetPassword("123456"); bool cmp = test.ComparePassword("123456"); Assert.IsTrue(cmp, "Passwords are not equals!"); } [TestMethod] public void User_PassedUser() { User test; try { test = new User("testPassword") { Login = "User", Sex = Sex.Male, Name = "Jan", Lastname = "Novák" }; test = new User() { Login = "User", Sex = Sex.Male, Name = "Jan", Lastname = "Novák" }; test = new User() { Sex = Sex.Male }; } catch (Exception e) { Assert.Fail("Expected no exception, but got: " + e.Message); } } } }