public void Add_Any_AddToDB() { //Arrange IList <User> users = new List <User>() { new User(), new User { Id = 1, Email = null, IsEmailVerified = false, Name = "" }, new User { Email = "asd", ActivationCode = new Guid("229c7b1b-309e-4d83-95b7-2f3e800403da"), IsEmailVerified = false } }; Mock <IUserRepository> MockUserRepository = new Mock <IUserRepository>(); UserRepositorySetupMoq.Add(MockUserRepository, users); UserRepositorySetupMoq.FindAll(MockUserRepository, users); IUserService userService = new UserService(MockUserRepository.Object); //Act userService.Add(new User()); IList <User> findedUsers = userService.FindAll(); //Assert Assert.AreEqual(findedUsers.Count, users.Count); Assert.AreEqual(findedUsers.Count, 4); }
public void Registration_RegisterUserWithAnEmailAlreadyUsed_StatusFalse() { IList <User> users = new List <User>() { new User("", "*****@*****.**", "") }; Mock <IUserRepository> MockUserRepository = new Mock <IUserRepository>(); UserRepositorySetupMoq.Add(MockUserRepository, users); UserRepositorySetupMoq.FindByEmail(MockUserRepository, users); IUserRepository userRepository = MockUserRepository.Object; IUserService userService = new UserService(userRepository); var controller = new UserController(userService); Mock <IRegistrationViewModel> MockRegistrationViewModel = new Mock <IRegistrationViewModel>(); MailMessage message = new MailMessage(); UserControllerSetupMoq.CheckUser(MockRegistrationViewModel); IRegistrationViewModel registrationViewModel = MockRegistrationViewModel.Object; //Act User dummyUser = new User("", "*****@*****.**", ""); bool result = registrationViewModel.CheckUser(userService, dummyUser); //Assert Assert.IsFalse(result); }
public void Registration_RegisterUserWithValidData_StatusTrue() { //Arrange IList <User> users = new List <User>() { new User("", "*****@*****.**", "") }; Mock <IUserRepository> MockUserRepository = new Mock <IUserRepository>(); UserRepositorySetupMoq.Add(MockUserRepository, users); UserRepositorySetupMoq.FindByEmail(MockUserRepository, users); IUserRepository userRepository = MockUserRepository.Object; IUserService userService = new UserService(userRepository); var controller = new UserController(userService); Mock <IRegistrationViewModel> MockRegistrationViewModel = new Mock <IRegistrationViewModel>(); MailMessage message = new MailMessage(); UserControllerSetupMoq.CheckUser(MockRegistrationViewModel); IRegistrationViewModel registrationViewModel = MockRegistrationViewModel.Object; //Act var dummyUser = new User("Andrew", "*****@*****.**", ""); bool result = registrationViewModel.CheckUser(userService, dummyUser); //Assert Assert.IsTrue(result); }
public void Login_LoginUserWithValidData_StatusTrue() { //Arrange IList <User> users = new List <User>() { new User("", "*****@*****.**", "test") }; Mock <IUserRepository> MockUserRepository = new Mock <IUserRepository>(); UserRepositorySetupMoq.Add(MockUserRepository, users); UserRepositorySetupMoq.FindByEmail(MockUserRepository, users); IUserRepository userRepository = MockUserRepository.Object; IUserService userService = new UserService(userRepository); Mock <IRegistrationViewModel> MockRegistrationViewModel = new Mock <IRegistrationViewModel>(); MailMessage message = new MailMessage(); UserControllerSetupMoq.CheckUser(MockRegistrationViewModel); Mock <ILogInViewModel> MockLogInViewModel = new Mock <ILogInViewModel>(); UserControllerSetupMoq.CheckUser(MockLogInViewModel); ILogInViewModel loginViewModel = MockLogInViewModel.Object; //Act User dummyUser = new User("", "*****@*****.**", "test"); bool result = loginViewModel.CheckUser(userService, dummyUser); //Assert Assert.IsTrue(result); }