public async Task CreateWithValidReturnsCreatedResult() { // ARRANGE var cInstantie = new CursusInstantie { Id = 1, Cursus = new Cursus { }, CursusId = 1, StartDatum = DateTime.Now }; var cursist = new Cursist { Id = 1, Naam = "Test1", Achternaam = "Test1", Cursussen = new List <CursusInstantie>() { cInstantie } }; _cursistService.Setup(x => x.CreateAsync(It.IsAny <Cursist>())) .Returns(Task.FromResult(cursist)); _cursistInstantieService.Setup(x => x.GetAsync(It.IsAny <int>())) .Returns(Task.FromResult(cInstantie)); _cursistInstantieService.Setup(x => x.AddCursist(It.IsAny <int>(), It.IsAny <Cursist>())) .Returns(Task.FromResult(cInstantie)); var inputDto = new CursistToCreateDto { CursusInstantieId = 1, Achternaam = "Test1", Naam = "Test1" }; // Act var result = await _cursistenController.CreateAsync(inputDto); var objectResult = result as CreatedNegotiatedContentResult <CursistToDetailsDto>; // Assert Assert.IsNotNull(objectResult); }
public async Task <IHttpActionResult> CreateAsync([FromBody] CursistToCreateDto dto) { var cursusFromDto = Mapper.Map <Cursist>(dto); var cursusInstantie = await _cursusInstantieService.GetAsync(dto.CursusInstantieId); if (cursusInstantieService == null) { return(BadRequest("CursusInstantie is onbekend")); } var cursist = await _cursistSerivce.CreateAsync(cursusFromDto); if (cursist == null) { return(BadRequest("Cursist aanmaken is mislukt")); } var addedDB = await _cursusInstantieService.AddCursist(dto.CursusInstantieId, cursist); if (addedDB == null) { return(BadRequest("Cursist niet aan instantie kunnen toevoegen")); } var resultDto = Mapper.Map <CursistToDetailsDto>(cursist); return(Created(resultDto.Id.ToString(), resultDto)); }
public async Task CreateWithInValidCursistInstantieIdReturnsBadRequestResult() { // ARRANGE var cursusToCreate = new Cursist { Naam = "Test1", Achternaam = "Test1", Cursussen = new List <CursusInstantie>() }; _cursistService.Setup(x => x.CreateAsync(It.IsAny <Cursist>())) .Returns(Task.FromResult(cursusToCreate)); _cursistInstantieService.Setup(x => x.GetAsync(It.IsAny <int>())) .Returns(Task.FromResult(It.IsAny <CursusInstantie>())); var inputDto = new CursistToCreateDto { CursusInstantieId = 1, Achternaam = "Test1", Naam = "Test1" }; // Act var result = await _cursistenController.CreateAsync(new CursistToCreateDto { CursusInstantieId = 1, Achternaam = "Test1", Naam = "Test1" }); var objectResult = result as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(objectResult); }