public void AddGameValidator_MaxPlayersCountValid_ValidationPassed(int maxPlayers, int minPlayers)
        {
            var model = new EditGameCommand(Guid.Empty, string.Empty, maxPlayers, minPlayers, false);

            var result = _sut.TestValidate(model);

            result.ShouldNotHaveValidationErrorFor(g => g.MaxPlayers);
        }
        public void EditGameCommandValidator_TitleValid_ValidationPassed(string title)
        {
            var model = new EditGameCommand(Guid.Empty, title, 0, 0, false);

            var result = _sut.TestValidate(model);

            result.ShouldNotHaveValidationErrorFor(g => g.Title);
        }
        public void EditGameCommandValidator_IdValid_ValidationPassed()
        {
            var model = new EditGameCommand(Guid.NewGuid(), "", 0, 0, false);

            var result = _sut.TestValidate(model);

            result.ShouldNotHaveValidationErrorFor(g => g.Id);
        }
        public void EditGameCommandValidator_TitleInvalid_ValidationErrorThrown(string title, string errorMessage)
        {
            var model = new EditGameCommand(Guid.Empty, title, 0, 0, false);

            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(g => g.Title)
            .WithErrorMessage(errorMessage);
        }
        public void EditGameCommandValidator_IdInvalid_ValidationErrorThrown()
        {
            var model = new EditGameCommand(Guid.Empty, "", 0, 0, false);

            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(g => g.Id)
            .WithErrorMessage("'Id' must not be equal to '00000000-0000-0000-0000-000000000000'.");
        }
        public void AddGameValidator_MinPlayersCountInvalid_ValidationErrorThrown(
            int minPlayers,
            int maxPlayers,
            string errorMessage)
        {
            var model = new EditGameCommand(Guid.Empty, string.Empty, maxPlayers, minPlayers, false);

            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(g => g.MinPlayers)
            .WithErrorMessage(errorMessage);
        }
Example #7
0
        public async Task <IActionResult> Edit([FromRoute] Guid id, [FromBody] EditGameRequest request)
        {
            var command = new EditGameCommand(
                id,
                request.Title,
                request.MaxPlayers,
                request.MinPlayers,
                request.HasScores);

            await _sender.Send(command);

            return(NoContent());
        }
Example #8
0
        public async void ShouldEditGame()
        {
            //arrange
            BoardContext context = new ContextBuilder().BuildClean();

            string expectedName      = "Teraformacja marsa";
            int    expectedMaxAmount = 6;
            int    expectedAge       = 5;
            int    expectedMinAmount = 1;

            string givenName      = "Szybki Talizman";
            int    givenMaxAmount = 3;
            int    givenAge       = 4;
            int    givenMinAmount = 2;

            Game game = new GameBuilder(context)
                        .WithName(givenName)
                        .WithMaxPlayersAmount(givenMaxAmount)
                        .Build();

            var newGame = context.Add(game);

            context.SaveChanges();

            //act
            var query = new EditGameCommand();

            query.Id = newGame.Entity.Id;
            query.MaximalPlayersAmount = expectedMaxAmount;
            query.Name = expectedName;
            query.MinimalPlayersAge    = expectedAge;
            query.MinimalPlayersAmount = expectedMinAmount;

            var handler = new EditGameCommand.Handler(context);
            var result  = await handler.Handle(query, default);

            //assert
            var createdGame = context.Games
                              .Where(x => x.Id == newGame.Entity.Id)
                              .Include(x => x.Visits)
                              .FirstOrDefault();

            Assert.Equal(expectedMaxAmount, createdGame.MaximalPlayersAmount);
            Assert.Equal(expectedName, createdGame.Name);
        }