Ejemplo n.º 1
0
        public void VerifyEmail_EmailInDB_ReturnsTrue()
        {
            //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.FindByEmail(MockUserRepository, users);
            IUserService userService = new UserService(MockUserRepository.Object);

            //Act
            bool isFinded = userService.EmailExists("asd");

            //Assert
            Assert.IsTrue(isFinded);
        }
        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);
        }
        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 AddTrip_Add()
        {
            //Arrange
            IList <Area> areas = new List <Area>()
            {
                new Area()
                {
                    Id = 1, Name = "ASD"
                },
                new Area()
                {
                    Id = 2, Name = "as"
                }
            };

            Mock <IAreaRepository> MockAreaRepository = new Mock <IAreaRepository>();

            AreaRepositorySetupMoq.FindAll(MockAreaRepository, areas);
            IAreaService areaService = new AreaService(MockAreaRepository.Object);

            IList <Trip> trips = new List <Trip>()
            {
                new Trip()
            };

            Mock <ITripRepository> MockTripRepository = new Mock <ITripRepository>();

            TripRepositorySetupMoq.Add(MockTripRepository, trips);
            ITripService tripService = new TripService(MockTripRepository.Object);

            IList <User> users = new List <User>()
            {
                new User(),
                new User {
                    Id = 1, Email = "giani"
                }
            };

            Mock <IUserRepository> MockUserRepository = new Mock <IUserRepository>();

            UserRepositorySetupMoq.FindByEmail(MockUserRepository, users);
            IUserService userService = new UserService(MockUserRepository.Object);

            Mock <ITripRequestViewModel> MockRequestModel = new Mock <ITripRequestViewModel>();

            TripRequestViewModelSetupMoq.AddTrip(MockRequestModel);

            //Act
            Trip trip = new Trip()
            {
                Id = 2, User = new User()
                {
                    Email = "giani"
                }, Area = new Area()
                {
                    Id = 2
                }
            };

            MockRequestModel.Object.AddTrip(trip, tripService, areaService, userService);

            //Assert
            Assert.AreEqual(trips.Count, 2);
            Assert.AreEqual(trips[1].User.Id, 1);
            Assert.AreEqual(trips[1].Area.Name, "as");
        }