public void Given_PlayerAlreadyExists_When_CreatePlayer_Then_ExceptionIsThrown()
        {
            // Arrange
            var teams = new List <Domain.Player.Player>
            {
                new Domain.Player.Player
                {
                    FirstName = "John",
                    LastName  = "Doe"
                }
            };
            var contextMock = MockDbContext(teams.AsQueryable());
            var handler     = new CreatePlayerCommandHandler(contextMock.Object, Mapper.CreateMapper());

            //Act
            var command = new CreatePlayerCommand
            {
                FirstName = "John",
                LastName  = "Doe"
            };
            Func <Task> func = async() => await handler.Handle(command, CancellationToken.None);

            //Assert
            func.Should().Throw <PlayerAlreadyExistsException>();
        }
Ejemplo n.º 2
0
        private static async Task <Guid> CreatePlayer()
        {
            using var conn = EventStoreConnection.Create(new Uri("tcp://*****:*****@localhost:1113"));
            await conn.ConnectAsync();

            var service = new ServiceCollection()
                          .AddMediatR(Assembly.GetAssembly(typeof(Program)))
                          .BuildServiceProvider();
            var bus        = new MediatR.Mediator(type => service.GetService(type));
            var dispatcher = new EventDispatcher(conn, bus);

            var repo    = new AggregateRepository(conn);
            var handler = new CreatePlayerCommandHandler(repo, dispatcher);

            var id       = Guid.NewGuid();
            var streamId = $@"Player-{id}";
            var cmd      = new CreatePlayerCommand(streamId, id);
            await handler.Handle(cmd);


            var player = await repo.Fetch <PlayerAggregate>(streamId);

            await dispatcher.RaiseEvent(player,
                                        new NicknameAddedEvent { Nickname = "Chr", StreamId = player.StreamId },
                                        new AddressAddedEvent { HomeAddress = new Address {
                                                                    HomeAddress = "Sandøgade 4, 8200 Aarhus N"
                                                                }, StreamId = player.StreamId });

            return(player.Id);
        }
        public void ReturnAnErrorResultWhenCallingCreatePlayer()
        {
            this.mockPlayerRepository.Setup(x => x.CreatePlayer(It.IsAny <Player>())).Returns(Result.Fail <string>("Error"));

            var handler = new CreatePlayerCommandHandler(this.mockPlayerRepository.Object, this.mockTeamsRepository.Object, this.mockPositionsRepository.Object);

            var barcode = handler.CreatePlayer(command);

            Assert.IsTrue(barcode.IsFailure);
        }
        public void CreateAPlayer()
        {
            this.mockPlayerRepository.Setup(x => x.CreatePlayer(It.IsAny <Player>())).Returns(Result.Ok("Record saved."));

            var handler = new CreatePlayerCommandHandler(this.mockPlayerRepository.Object, this.mockTeamsRepository.Object, this.mockPositionsRepository.Object);

            var barcode = handler.CreatePlayer(command);

            Assert.IsTrue(barcode.IsSuccess);
        }
        public async void Given_PlayerDoesNotExist_When_CreatePlayer_Then_PlayerIsReturned()
        {
            // Arrange
            var teams       = new List <Domain.Player.Player>();
            var contextMock = MockDbContext(teams.AsQueryable());
            var handler     = new CreatePlayerCommandHandler(contextMock.Object, Mapper.CreateMapper());

            //Act
            var result = await handler.Handle(new CreatePlayerCommand {
                FirstName = "John", LastName = "Doe"
            }, CancellationToken.None);

            //Assert
            result.Should().BeOfType <PlayerDto>();
            contextMock.Verify(mock => mock.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
Ejemplo n.º 6
0
 public PlayersController(GetPlayersCommandHandler getCommandHanlder, CreatePlayerCommandHandler createCommandHandler)
 {
     this.getCommandHanlder    = getCommandHanlder;
     this.createCommandHandler = createCommandHandler;
 }