public void ReturnAllBands_WithIncludedCountryAndGenre() { var contextMock = new Mock <IMusicLibraryContext>(); var contextBaseMock = new Mock <IMusicLibraryBaseContext>(); var countryServiceMock = new Mock <ICountryService>(); var genreServiceMock = new Mock <IGenreService>(); var userServiceMock = new Mock <IUserService>(); var bandFactoryMock = new Mock <IBandFactory>(); var bands = GetBands(); var expectedResult = bands.AsQueryable(); var bandsSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bands); bandsSetMock.Include("Country"); bandsSetMock.Include("Genre"); contextMock.Setup(x => x.Bands).Returns(bandsSetMock); var bandService = new BandService( contextMock.Object, contextBaseMock.Object, countryServiceMock.Object, genreServiceMock.Object, userServiceMock.Object, bandFactoryMock.Object); var bandResultSet = bandService.GetAllBands(); CollectionAssert.AreEquivalent(expectedResult, bandResultSet.ToList()); }
public void DoesNotReturnsBands_WithoutIncludingGenre() { var contextMock = new Mock <IMusicLibraryContext>(); var contextBaseMock = new Mock <IMusicLibraryBaseContext>(); var countryServiceMock = new Mock <ICountryService>(); var genreServiceMock = new Mock <IGenreService>(); var userServiceMock = new Mock <IUserService>(); var bandFactoryMock = new Mock <IBandFactory>(); var bands = GetBands(); var expectedResult = bands.Where(x => x.Genre.GenreName.Contains("Metal")).AsQueryable(); var bandsSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bands); contextMock.Setup(x => x.Bands).Returns(bandsSetMock); var bandService = new BandService( contextMock.Object, contextBaseMock.Object, countryServiceMock.Object, genreServiceMock.Object, userServiceMock.Object, bandFactoryMock.Object); var bandResultSet = bandService.GetAllBands(); CollectionAssert.AreNotEquivalent(expectedResult, bandResultSet.ToList()); }
public void ReturnedBands_AreAllInstancesOfBand() { var contextMock = new Mock <IMusicLibraryContext>(); var contextBaseMock = new Mock <IMusicLibraryBaseContext>(); var countryServiceMock = new Mock <ICountryService>(); var genreServiceMock = new Mock <IGenreService>(); var userServiceMock = new Mock <IUserService>(); var bandFactoryMock = new Mock <IBandFactory>(); var bands = GetBands(); var expectedResult = bands.AsQueryable(); var bandsSetMock = QueryableDbSetMock.GetQueryableMockDbSet(bands); bandsSetMock.Include("Country"); bandsSetMock.Include("Genre"); contextMock.Setup(x => x.Bands).Returns(bandsSetMock); var bandService = new BandService( contextMock.Object, contextBaseMock.Object, countryServiceMock.Object, genreServiceMock.Object, userServiceMock.Object, bandFactoryMock.Object); var bandResultSet = bandService.GetAllBands().ToList(); CollectionAssert.AllItemsAreInstancesOfType(bandResultSet, typeof(Band)); }
public IActionResult Index() { var bands = service.GetAllBands(); return(View(bands)); }