public async Task <IActionResult> Update([FromBody] AdminCrewMemberModel adminCrewMemberModel) { var result = await crewMember.Update(adminCrewMemberModel); if (result != null) { if (result.ID > 0) { return(Ok(result)); } return(GetCustomNotFound(result.ID)); } return(NotFound()); }
public async Task Update_InvalidInput_ReturnsCrewMemberModelWithErrorID(int id, string characterName, CrewRoles crewRole, int movieID, int personID, int expectedCrewMemberID) { #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 crewMember = new Domain.CrewMember { CharacterName = "Character Name", Role = CrewRoles.Actor, MovieID = movie.ID, PersonID = person.ID }; dbContext.CrewMembers.Add(crewMember); await dbContext.SaveChangesAsync(); var newCrewMember = new AdminCrewMemberModel { ID = id, CharacterName = characterName, Role = crewRole, MovieID = movieID, PersonID = personID }; var appCrewMember = new CrewMember(dbContext); #endregion #region Act var actualCrewMember = await appCrewMember.Update(newCrewMember); #endregion #region Assert Assert.Equal(actualCrewMember.ID, expectedCrewMemberID); #endregion }
public async Task Update_ValidInput_ReturnsCorrectData(int id, 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 data2 = await CreateMovieAndPerson(dbContext); var movie2 = data2[0] as Domain.Movie; var person2 = data2[1] as Domain.Person; var crewMember = new Domain.CrewMember { CharacterName = "Character Name", Role = CrewRoles.Actor, MovieID = movie.ID, PersonID = person.ID }; dbContext.CrewMembers.Add(crewMember); await dbContext.SaveChangesAsync(); var newCrewMember = new AdminCrewMemberModel { ID = id, CharacterName = characterName, Role = crewRole, MovieID = movieID, PersonID = personID }; var expectedCrewMember = new CrewMemberModel { ID = id, 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 } }; var appCrewMember = new CrewMember(dbContext); #endregion #region Act var actualCrewMember = await appCrewMember.Update(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 }