public async Task GetGenreByExistingId() { //Preparation var databaseName = Guid.NewGuid().ToString(); var context = BuildContext(databaseName); var mapper = BuildMap(); context.Genres.Add(new Genre() { Name = "Genre1" }); context.Genres.Add(new Genre() { Name = "Genre2" }); context.SaveChanges(); //will use another context in the same db(and data) because this new context it is dont have on the memorh the 2 records var context2 = BuildContext(databaseName); //Testing var controller = new GenresV2Controller(context2, mapper); var Id = 1; var response = await controller.Get(Id); var result = response.Result as OkObjectResult; var genre = result.Value as GenreDto; Assert.AreEqual(Id, genre.Id); }
public async Task GetAllGenres() { //Preparation var databaseName = Guid.NewGuid().ToString(); var context = BuildContext(databaseName); var mapper = BuildMap(); context.Genres.Add(new Genre() { Name = "Genre1" }); context.Genres.Add(new Genre() { Name = "Genre2" }); context.SaveChanges(); //will use another context in the same db(and data) because this new context it is dont have on the memorh the 2 records var context2 = BuildContext(databaseName); //Testing var controller = new GenresV2Controller(context2, mapper); var response = await controller.Get(); var result = response.Result as OkObjectResult; var genres = result.Value as List <GenreDto>; //Verification Assert.AreEqual(2, genres.Count); //if use as return type Task<ActionResult<List<GenreDTO>>> //// Testing //var controller = new GenresController(context2, mapper); //var response = await controller.Get(); //// Verification //var genres = response.Value; //Assert.AreEqual(2, genres.Count); }
public async Task GetGenreByIdDoesNotExist() { //Preparation var databaseName = Guid.NewGuid().ToString(); var context = BuildContext(databaseName); var mapper = BuildMap(); //Testing var controller = new GenresV2Controller(context, mapper); ActionResult <GenreDto> response = await controller.Get(1); var result = response.Result as NotFoundResult; var statusCode = result.StatusCode; Assert.AreEqual(404, statusCode); //if use as return type Task<ActionResult<GenreDTO>> //var response = await controller.Get(1); //var result = response.Result as StatusCodeResult; //Assert.AreEqual(404, result.StatusCode); }