Example #1
0
        public void should_authenticate_user()
        {
            // Arrange
            var userModel = new UserModel { Email = "*****@*****.**", Password = "******" };
            var userRepository = new Mock<IRepository<User>>();

            // Act
            var userService = new UserService(userRepository.Object);
            var userId = userService.Create(userModel);

            // Assert
            userRepository.Verify(x => x.Create(It.IsAny<User>()), Times.Once);
            userRepository.Verify(x => x.SaveChanges(), Times.AtLeastOnce);

            Assert.NotNull(userId);
        }
Example #2
0
        public async void should_get_user_by_email()
        {
            // Arrange
            const string email = "*****@*****.**";

            var userRepository = new Mock<IRepository<User>>();
            userRepository.Setup(x => x.FindOne(y => y.Email == email)).Returns(new User { Email = email });

            // Act
            var userService = new UserService(userRepository.Object);
            var user = await userService.GetByEmail(email);

            // Assert
            Assert.NotNull(user);
            Assert.AreEqual(user.Email, email);
            userRepository.Verify(x => x.FindOne(y => y.Email == email), Times.Once);
        }
Example #3
0
        public async void should_get_user_by_email()
        {
            //arrange
            const string email = "*****@*****.**";

            var userRepository = new Mock<IRepository<User>>();
            userRepository.Setup(x => x.FindOne(It.IsAny<Expression<Func<User, bool>>>())).Returns(new User { Email = email });

            var appRepository = new Mock<IRepository<App>>();
            appRepository.Setup(x => x.Create(It.IsAny<App>())).Returns(It.IsAny<App>());
            appRepository.Setup(x => x.SaveChanges()).Returns(true);

            //act
            var userService = new UserService(userRepository.Object, appRepository.Object);
            var user = await userService.GetByEmail(email);

            //assert
            Assert.NotNull(user);
            Assert.AreEqual(email, user.Email);

            userRepository.Verify(x => x.FindOne(It.IsAny<Expression<Func<User, bool>>>()), Times.Once);
        }
Example #4
0
        public void should_create_a_user()
        {
            //arrange
            var userModel = new UserModel { Email = "*****@*****.**", Password = "******" };

            var userRepository = new Mock<IRepository<User>>();
            userRepository.Setup(x => x.Create(It.IsAny<User>())).Returns(It.IsAny<User>());
            userRepository.Setup(x => x.SaveChanges()).Returns(true);

            var appRepository = new Mock<IRepository<App>>();
            appRepository.Setup(x => x.Create(It.IsAny<App>())).Returns(It.IsAny<App>());
            appRepository.Setup(x => x.SaveChanges()).Returns(true);

            //act
            var userService = new UserService(userRepository.Object, appRepository.Object);
            var userId = userService.Create(userModel);

            //assert
            Assert.NotNull(userId);

            userRepository.Verify(x => x.Create(It.IsAny<User>()), Times.Once);
            userRepository.Verify(x => x.SaveChanges(), Times.AtLeastOnce);
        }