Ejemplo n.º 1
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);
        }
Ejemplo n.º 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(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);
        }