public async Task Given_An_Valid_Deck_Create_Command_Should_Be_Successful() { // Arrange var deck = new DeckInputModel { Name = "deck tester", UserId = Guid.NewGuid().ToString(), MainDeck = new List <CardInputModel>() }; _fixture.RepeatCount = 40; deck.MainDeck = _fixture .Build <CardInputModel>() .With(c => c.BaseType, "monster") .Without(c => c.Types) .CreateMany() .ToList(); var command = new CreateDeckCommand { Deck = deck }; _deckService.Add(Arg.Any <DeckModel>()).Returns(new Deck { Id = 23424 /*new deck id*/ }); // Act var result = await _sut.Handle(command, CancellationToken.None); // Assert result.IsSuccessful.Should().BeTrue(); }
[RequestSizeLimit(100_000_00)] // 10MB request size public async Task <IActionResult> Post([FromBody] DeckInputModel newDeck) { if (ModelState.IsValid) { var user = await GetCurrentUserAsync(); if (user != null) { newDeck.UserId = user.Id; var command = new CreateDeckCommand { Deck = newDeck }; var result = await _mediator.Send(command); if (result.IsSuccessful) { return(CreatedAtRoute("GetDeckById", new { id = result.Data }, result.Data)); } return(BadRequest(result.Errors)); } } else { return(BadRequest(ModelState.Errors())); } return(BadRequest()); }
public async Task Given_An_Invalid_Deck_Create_Command_Should_Return_A_List_Of_Errors() { // Arrange var deck = new DeckInputModel { MainDeck = new List <CardInputModel>() }; var command = new CreateDeckCommand { Deck = deck }; // Act var result = await _sut.Handle(command, CancellationToken.None); // Assert result.Errors.Should().NotBeEmpty(); }
public async Task Given_An_Invalid_Deck_Create_Command_Should_Not_Be_Successful() { // Arrange var deck = new DeckInputModel { MainDeck = new List <CardInputModel>() }; var command = new CreateDeckCommand { Deck = deck }; // Act var result = await _sut.Handle(command, CancellationToken.None); // Assert result.IsSuccessful.Should().BeFalse(); }
public async Task Given_An_Valid_Deck_Create_Command_Should_Be_Successful_And_New_DeckId_Returned() { // Arrange const int expected = 23424; var deck = new DeckInputModel { Name = "deck tester", UserId = Guid.NewGuid().ToString(), MainDeck = new List <CardInputModel>() }; _fixture.RepeatCount = 40; deck.MainDeck = _fixture .Build <CardInputModel>() .With(c => c.BaseType, "monster") .Without(c => c.Types) .CreateMany() .ToList(); var command = new CreateDeckCommand { Deck = deck }; _deckService.Add(Arg.Any <DeckModel>()).Returns(new Deck { Id = 23424 /*new deck id*/ }); // Act var result = await _sut.Handle(command, CancellationToken.None); // Assert dynamic dyn = result.Data; int newDeckId = int.Parse(dyn.GetType().GetProperty("deckId").GetValue(dyn, null).ToString()); newDeckId.Should().Be(expected); }
public Task <IdDto> CreateDeck(CreateDeckCommand command, CancellationToken cancellationToken) { return(mediator.Send(command, cancellationToken)); }