Ejemplo n.º 1
0
        public void GetUserById_CallsRepository_ReturnsUser()
        {
            //Arrange
            var id = Guid.NewGuid();

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

            userRepository.GetById(Arg.Is(id)).Returns(user);

            GetUserByIdRequest request = new GetUserByIdRequest(id.ToString());

            CancellationToken token = new CancellationToken();

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

            task.Wait();

            User result = task.Result;

            //Assert
            userRepository.Received(1).GetById(Arg.Is(id));

            result.Should().NotBeNull();
            result.Should().BeEquivalentTo(user);
        }
        public void Handle_SendsUserToReadModelRepository()
        {
            //Arrange
            UserSubscribed @event = new UserSubscribed(
                Guid.NewGuid(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>(),
                fixture.Create <string>()
                );

            ProcessEventCommand <UserSubscribed> command = new ProcessEventCommand <UserSubscribed>(
                @event
                );

            CancellationToken token = tokenSource.Token;

            //Act
            Task handling = eventProcessor.Handle(command, token);

            handling.Wait();

            //Assert
            unitOfWork.Received(1).BeginTransaction();
            unitOfWork.Received(1).Commit();

            repository.Received(1).Save(Arg.Is <User>(
                                            u => u.UserName == @event.UserName &&
                                            u.FirstName == @event.FirstName &&
                                            u.LastName == @event.LastName &&
                                            u.Email == @event.Email
                                            ));
        }
Ejemplo n.º 3
0
        public void Handle_FindsUserId_FromUserName()
        {
            //Arrange
            var command           = fixture.Create <AuthenticateWithCredentialsCommand>();
            var cancellationToken = new CancellationToken();

            //Act
            try
            {
                var task = handler.Handle(command, cancellationToken);
                task.Wait();
            }
            catch {}

            //Assert
            readModelUserRepository.Received(1).GetByUserName(Arg.Is(command.UserName));
        }