public async Task <IActionResult> ReadAll() { if (await crewMember.ReadAll() is ICollection <CrewMemberModel> result && result.Count > 0) { return(Ok(result)); } return(NoContent()); }
public async Task ReadAll_NoCrewMembersExist_ReturnsEmptyList() { #region Arrange var dbContext = new ApplicationDbContext(_dbContextOptions); await dbContext.Database.EnsureDeletedAsync(); int expectedAmount = 0; var appCrewMember = new CrewMember(dbContext); #endregion #region Act var result = await appCrewMember.ReadAll(); #endregion #region Assert var actualAmount = Assert.IsAssignableFrom <IEnumerable <CrewMemberModel> >(result).Count(); Assert.Equal(expectedAmount, actualAmount); #endregion }
public async Task ReadAll_CrewMembersExist_ReturnsAllCrewMembers() { #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; int expectedAmount = 2; dbContext.CrewMembers.AddRange( Enumerable.Range(1, expectedAmount).Select(x => new Domain.CrewMember { CharacterName = $"Character Name {x}", Role = CrewRoles.Actor, MovieID = movie.ID, PersonID = person.ID }) ); await dbContext.SaveChangesAsync(); var appCrewMember = new CrewMember(dbContext); #endregion #region Act var result = await appCrewMember.ReadAll(); #endregion #region Assert var actualAmount = Assert.IsAssignableFrom <IEnumerable <CrewMemberModel> >(result).Count(); Assert.Equal(expectedAmount, actualAmount); #endregion }