Ejemplo n.º 1
0
        public void HandleSubscribe_CreatesUser_ThenSavesItAndPublishesEvents()
        {
            //Arrange
            SubscribeCommand command = new SubscribeCommand(
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                "*****@*****.**",
                fixture.Create <string>()
                );

            CancellationToken token = new CancellationToken();

            //Act
            Task task = handler.Handle(command, token);

            task.Wait();

            //Assert
            cryptService.Received(1).Crypt(Arg.Is(command.Password)); //Called by the factory

            writeModelUnitOfWork.Received(1).BeginTransaction();
            writeModelUnitOfWork.Received(1).Commit();

            userWriteRepository.Received(1).Save(Arg.Is <User>(u =>
                                                               u.UserName == command.UserName &&
                                                               u.FirstName == command.FirstName &&
                                                               u.LastName == command.LastName &&
                                                               u.Email.Address == command.Email
                                                               ));

            eventPublisher.Received(1).PublishNewEvents(Arg.Is <User>(u => u.UserName == command.UserName));
        }
Ejemplo n.º 2
0
        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);
        }