public void HandleSubscribe_ThrowsEmailAlreadyTakenException_WhenEmailIsAlreadyTaken()
        {
            //Arrange
            SubscribeCommand command = new SubscribeCommand(
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                "*****@*****.**",
                fixture.Create <string>()
                );

            CancellationToken token = new CancellationToken();

            userReadRepository.GetByEmail(Arg.Is(command.Email)).Returns(
                new Budget.Users.Domain.ReadModel.User(
                    Guid.NewGuid(),
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    fixture.Create <string>(),
                    fixture.Create <DateTime>()
                    )
                );

            //Act
            Assert.ThrowsAsync <UsernameAlreadyTakenException>(() => handler.Handle(command, token));

            //Assert
        }
Example #2
0
        public void GetUserByEmail_CallsRepository_ReturnsUser()
        {
            //Arrange
            var email = fixture.Create <string>();

            var user = new User(
                Guid.NewGuid(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                email,
                fixture.Create <DateTime>()
                );

            userRepository.GetByEmail(Arg.Is(email)).Returns(user);

            GetUserByEmailRequest request = new GetUserByEmailRequest(email);

            CancellationToken token = new CancellationToken();

            //Act
            Task <User> task = handler.Handle(request, token);

            task.Wait();

            User result = task.Result;

            //Assert
            userRepository.Received(1).GetByEmail(Arg.Is(email));

            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(user);
        }