public async Task Create_ValidRequest_ReturnsJsonResponseAndCreated(string characterName, CrewRoles crewRole, int movieID, int personID) { #region Arrange await DeleteDbContent(); var client = GetHttpClient(); var data = await CreatePersonAndMovie(); var movie = data[0] as Domain.Movie; var person = data[1] as Domain.Person; var newCrewMember = new AdminCrewMemberModel { CharacterName = characterName, Role = crewRole, MovieID = movieID, PersonID = personID }; var expectedCrewMember = new CrewMemberModel { ID = 1, CharacterName = characterName, Role = crewRole.ToString(), Movie = new MovieModel { ID = movie.ID, Name = movie.Name }, Person = new PersonModel { ID = person.ID, FirstName = person.FirstName, LastName = person.LastName } }; #endregion #region Act var response = await client.PostAsJsonAsync("/api/crewmember", newCrewMember); var responseBody = await response.Content.ReadAsStreamAsync(); var actualCrewMember = await JsonSerializer.DeserializeAsync <CrewMemberModel>(responseBody); #endregion #region Assert Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID); Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName); Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role); Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID); Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name); Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID); Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName); Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName); #endregion }
public async Task Create_ValidInput_ReturnsCorrectData(string characterName, CrewRoles crewRole, int movieID, int personID) { #region Arrange var dbContext = new ApplicationDbContext(_dbContextOptions); await dbContext.Database.EnsureDeletedAsync(); var data = await CreateMovieAndPerson(dbContext); var movie = data[0] as Domain.Movie; var person = data[1] as Domain.Person; var newCrewMember = new AdminCrewMemberModel { CharacterName = characterName, Role = crewRole, MovieID = movieID, PersonID = personID }; var expectedCrewMember = new CrewMemberModel { ID = 1, CharacterName = characterName, Role = crewRole.ToString(), Movie = new MovieModel { ID = movie.ID, Name = movie.Name }, Person = new PersonModel { ID = person.ID, FirstName = person.FirstName, LastName = person.LastName } }; var appCrewMember = new CrewMember(dbContext); #endregion #region Act var actualCrewMember = await appCrewMember.Create(newCrewMember); #endregion #region Assert Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID); Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName); Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role); Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID); Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name); Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID); Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName); Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName); #endregion }
public async Task Update_ValidRequest_ReturnsJsonResponseAndOk(int id, string characterName, CrewRoles crewRole, int movieID, int personID) { #region Arrange await DeleteDbContent(); var client = GetHttpClient(); var dbContext = GetDbContext(); var data = await CreatePersonAndMovie(); var movie = data[0] as Domain.Movie; var person = data[1] as Domain.Person; var data2 = await CreatePersonAndMovie(); var movie2 = data2[0] as Domain.Movie; var person2 = data2[1] as Domain.Person; dbContext.CrewMembers.Add(new Domain.CrewMember { Role = CrewRoles.Writer, MovieID = movie.ID, PersonID = person.ID }); await dbContext.SaveChangesAsync(); var newCrewMember = new AdminCrewMemberModel { ID = id, CharacterName = characterName, Role = crewRole, MovieID = movieID, PersonID = personID }; var expectedCrewMember = new CrewMemberModel { ID = 1, CharacterName = characterName, Role = crewRole.ToString(), Movie = new MovieModel { ID = movie2.ID, Name = movie2.Name }, Person = new PersonModel { ID = person2.ID, FirstName = person2.FirstName, LastName = person2.LastName } }; #endregion #region Act var response = await client.PutAsJsonAsync($"/api/crewmember/{id}", newCrewMember); var responseBody = await response.Content.ReadAsStreamAsync(); var actualCrewMember = await JsonSerializer.DeserializeAsync <CrewMemberModel>(responseBody); #endregion #region Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID); Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName); Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role); Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID); Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name); Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID); Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName); Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName); #endregion }