Пример #1
0
        public void Save_AddsUserToMemory()
        {
            //Arrange
            User user = userFactory.Create(
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                "*****@*****.**",
                fixture.Create <string>()
                );

            //Act
            repository.Save(user).Wait();

            Task <User> saveTask = repository.Get(user.Id);

            saveTask.Wait();

            Task <User> getTask = repository.Get(user.Id);

            getTask.Wait();

            User userFromRepository = getTask.Result;

            //Assert
            userFromRepository.UserName.Should().Be(user.UserName);
            userFromRepository.FirstName.Should().Be(user.FirstName);
            userFromRepository.LastName.Should().Be(user.LastName);
            userFromRepository.Email.Should().Be(user.Email);
            userFromRepository.EncryptedPassword.Should().Be(user.EncryptedPassword);
        }
Пример #2
0
        public void ParameteredConstructor_sets_Values()
        {
            //Arrange
            Guid id = Guid.NewGuid();

            var cryptService = Substitute.For <ICryptService>();

            cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]);
            var userFactory = new WriteModelUserFactory(cryptService);
            var domainUser  = userFactory.Create("Kakarot", "Son", "Goku", "*****@*****.**", "chichi123");

            //Act
            var user = new User(domainUser);

            //Assert
            user.Id.Should().Be(domainUser.Id);
            user.Changes.Should().BeEquivalentTo(domainUser.Changes);
        }
        public void Save_InsertsUser_WhenIsNewUser()
        {
            //Arrange
            var domainUser = userFactory.Create(
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                "*****@*****.**",
                fixture.Create <string>()
                );

            //Act
            var saveTask = repository.Save(domainUser);

            saveTask.Wait();

            //Assert
            userCollection.Received(1).InsertOneAsync(Arg.Is <User>(
                                                          u => u.Changes.Count() == domainUser.Changes.Count()
                                                          ));
        }
        public void Create_CryptsPassword_CreatesValidUser()
        {
            //Arrange
            string userName  = fixture.Create <string>();
            string firstName = fixture.Create <string>();
            string lastName  = fixture.Create <string>();
            string email     = "*****@*****.**";
            string password  = fixture.Create <string>();

            //Act
            User user = factory.Create(userName, firstName, lastName, email, password);

            //Assert
            cryptService.Received(1).Crypt(Arg.Is(password));

            user.UserName.Should().Be(userName);
            user.FirstName.Should().Be(firstName);
            user.LastName.Should().Be(lastName);
            user.Email.Should().NotBeNull();
            user.Email.Address.Should().Be(email);
            user.EncryptedPassword.Should().Be(cryptServiceOutput);
        }