Example #1
0
        public void DoesNotReturnBands_WithNonExistingGenre()
        {
            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();
            string expectedGenre = "Hop";

            var expectedResult = bands.Where(x => x.Genre.GenreName == expectedGenre);

            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 actualResult = bandService.GetBandsByGenre(expectedGenre);

            CollectionAssert.IsEmpty(actualResult);
        }
Example #2
0
        public void ReturnTheRightCount_OfFoundBands_WithGivenGenre()
        {
            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();
            string expectedGenre = "Metal";

            var expectedResult = bands.Where(x => x.Genre.GenreName == expectedGenre).ToList();

            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 actualResult = bandService.GetBandsByGenre(expectedGenre).ToList();

            Assert.That(expectedResult.Count == actualResult.Count);
        }
Example #3
0
        public void ReturnBands_WithInstanceOfBand()
        {
            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();
            string expectedGenre = "Metal";

            var expectedResult = bands.Where(x => x.Genre.GenreName == expectedGenre);

            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 actualResult = bandService.GetBandsByGenre(expectedGenre);

            CollectionAssert.AllItemsAreInstancesOfType(actualResult, typeof(Band));
        }