Esempio n. 1
0
        public async Task User_Should_Subscribe()
        {
            var unitOfWork = new UnitOfWorkBuilder().Build();

            var passwordService = A.Fake <IPasswordService>();

            A.CallTo(() => passwordService.GenerateRandomPassword()).Returns(("hash", "salt"));

            var dateTime    = DateTime.UtcNow;
            var userService = new UserServiceBuilder().WithUnitOfWork(unitOfWork)
                              .WithDateTime(dateTime)
                              .WithPasswordService(passwordService)
                              .Build();

            var user = GetUser();

            await userService.RegisterMembers(new List <User> {
                user
            });

            var savedUser = await unitOfWork.Users.GetFirst(x => x.Email == user.Email);

            savedUser.Should().NotBeNull();
            savedUser.FirstName.Should().Be(user.FirstName);
            savedUser.LastName.Should().Be(user.LastName);
            savedUser.Password.Should().Be("hash");
            savedUser.PasswordSalt.Should().Be("salt");
            savedUser.CreationDate.Should().Be(dateTime);
        }
Esempio n. 2
0
        public async Task User_Should_Not_Subscribe_With_Same_Email()
        {
            var unitOfWork = new UnitOfWorkBuilder().Build();

            var passwordService = A.Fake <IPasswordService>();

            A.CallTo(() => passwordService.GenerateRandomPassword()).Returns(("hash", "salt"));

            var userService = new UserServiceBuilder().WithUnitOfWork(unitOfWork)
                              .WithPasswordService(passwordService)
                              .Build();

            var user = new User {
                Email = "*****@*****.**", FirstName = "John", LastName = "Doe"
            };
            var user2 = new User {
                Email = "*****@*****.**", FirstName = "Jane", LastName = "Doe"
            };
            var users = await unitOfWork.Users.GetAll();

            users.Count().Should().Be(0);
            await userService.RegisterMembers(new List <User> {
                user
            });

            users = await unitOfWork.Users.GetAll();

            users.Count().Should().Be(1);
            await userService.RegisterMembers(new List <User> {
                user2
            });

            users = await unitOfWork.Users.GetAll();

            users.Count().Should().Be(1);
        }