public async Task Create_InvalidInput_ReturnsCrewMemberModelWithErrorID(string characterName, CrewRoles crewRole, int movieID, int personID, int expectedCrewMemberID) { #region Arrange var dbContext = new ApplicationDbContext(_dbContextOptions); await dbContext.Database.EnsureDeletedAsync(); await CreateMovieAndPerson(dbContext); var newCrewMember = new AdminCrewMemberModel { CharacterName = characterName, Role = crewRole, MovieID = movieID, PersonID = personID }; var appCrewMember = new CrewMember(dbContext); #endregion #region Act var actualCrewMember = await appCrewMember.Create(newCrewMember); #endregion #region Assert Assert.Equal(actualCrewMember.ID, expectedCrewMemberID); #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 <IActionResult> Create([FromBody] AdminCrewMemberModel adminCrewMemberModel) { var result = await crewMember.Create(adminCrewMemberModel); if (result != null) { if (result.ID > 0) { return(CreatedAtAction(nameof(Read), new { id = result.ID }, result)); } return(GetCustomNotFound(result.ID)); } return(StatusCode((int)HttpStatusCode.InternalServerError)); }