public MusicStoreController(IMusicStoreService musicStoreService, IUserAccountService userAccountService, IMusicStoreDisplayService musicStoreDisplayService, IDiscountService discountService) { _musicStoreService = musicStoreService; _userAccountService = userAccountService; _musicStoreDisplayService = musicStoreDisplayService; _discountService = discountService; }
public AlbumsController ( IMusicStoreService musicStoreService, ILogger <AlbumsController> logger ) { _musicStoreService = musicStoreService; _logger = logger; }
public static void ConfigureContainer() { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); builder.RegisterType <UnitOfWork>().As <IUnitOfWork>().SingleInstance(); builder.RegisterType <MapSong>().As <IMapper <DataAccess.Song, Domain.DataTransfer.Song> >().SingleInstance(); builder.RegisterType <MapAlbum>().As <IMapper <DataAccess.Album, Domain.DataTransfer.Album> >().SingleInstance(); builder.RegisterType <MapBoughtSong>().As <IMapper <DataAccess.BoughtSong, Domain.DataTransfer.BoughtSong> >().SingleInstance(); builder.RegisterType <MapUserAccount>().As <IMapper <User, UserAccount> >().SingleInstance(); builder.RegisterType <MusicStoreService>().As <IMusicStoreService>().SingleInstance(); builder.RegisterType <MusicStoreDisplayService>().As <IMusicStoreDisplayService>().SingleInstance(); builder.RegisterType <UserAccountService>().As <IUserAccountService>().SingleInstance(); builder.RegisterType <AdminService>().As <IAdminService>().SingleInstance(); builder.RegisterType <UserStatisticService>().As <IUserStatisticService>().SingleInstance(); builder.RegisterType <AdminStatisticService>().As <IAdminStatisticService>().SingleInstance(); builder.RegisterType <DiscountService>().As <IDiscountService>().SingleInstance(); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); IUnitOfWork unitOfWork = container.Resolve <IUnitOfWork>(); var songMapper = container.Resolve <IMapper <DataAccess.Song, Domain.DataTransfer.Song> >(); var boughtSongMapper = container.Resolve <IMapper <DataAccess.BoughtSong, Domain.DataTransfer.BoughtSong> >(); var userAccountMapper = container.Resolve <IMapper <User, UserAccount> >(); var albumMapper = container.Resolve <IMapper <DataAccess.Album, Domain.DataTransfer.Album> >(); IMusicStoreDisplayService musicStoreDisplayService = container.Resolve <IMusicStoreDisplayService>(); IMusicStoreService musicStoreService = container.Resolve <IMusicStoreService>(); IUserAccountService userAccountService = container.Resolve <IUserAccountService>(); IAdminService adminService = container.Resolve <IAdminService>(); IUserStatisticService userStatisticService = container.Resolve <IUserStatisticService>(); IAdminStatisticService adminStatisticService = container.Resolve <IAdminStatisticService>(); IDiscountService discountService = container.Resolve <IDiscountService>(); }
public MusicStoreServiceTests() { long testAlbumId = 1; var artist = new Artist() { Id = 1, PublicName = "Backstreet Boys", Country = "United States" }; var users = new List <User>() { new User() { Id = 1, UserName = "******", Email = "Email", SignUpDate = DateTime.Now }, new User() { Id = 2, UserName = "******", Email = "Email2", SignUpDate = DateTime.Now } }; var genre = new Genre() { Id = 1, Name = "Pop" }; var album = new Album() { Id = testAlbumId, Name = "DNA", CoverUrl = "http", Description = "Description", Price = 12.99M, ArtistId = artist.Id, Artist = artist, GenreId = genre.Id, Genre = genre, CopyrightInfo = "@", ReleaseDate = DateTime.Now }; var songs = new List <Song>() { new Song() { Id = 1, Name = "Song 1", Duration = 320, Price = 1.29M, AlbumId = testAlbumId, Album = album, GenreId = genre.Id, Genre = genre, ArtistId = artist.Id, Artist = artist, TrackNumber = 1, Reproductions = new List <Reproduction>() { new Reproduction() { Id = 1, UserId = users.ElementAt(0).Id } } }, new Song() { Id = 2, Name = "Song 2", Duration = 300, Price = 1.29M, AlbumId = testAlbumId, Album = album, GenreId = genre.Id, Genre = genre, TrackNumber = 2, Reproductions = new List <Reproduction>() { new Reproduction() { Id = 1, UserId = users.ElementAt(0).Id }, new Reproduction() { Id = 2, UserId = users.ElementAt(1).Id } } } }; var reviews = new List <Review>() { new Review() { Id = 1, AlbumId = testAlbumId, Score = 1, UserId = users.ElementAt(0).Id, DateReviewed = DateTime.Now }, new Review() { Id = 2, AlbumId = testAlbumId, Score = 5, UserId = users.ElementAt(1).Id, DateReviewed = DateTime.Now } }; // Setup AlbumRepository Mock call being tested. AlbumRepository = new Mock <IRepository <Album, long> >(); AlbumRepository.Setup(l => l.FindById(testAlbumId)) .ReturnsAsync(album); // Setup SongRepository Mock call being tested. SongRepository = new Mock <ISongRepository>(); SongRepository.Setup(l => l.GetSongs(testAlbumId)) .ReturnsAsync(songs); // Setup UserRepository Mock call being tested. UserRepository = new Mock <IUserRepository>(); UserRepository.Setup(l => l.Count()) .ReturnsAsync(users.Count); // Setup ReviewRepository Mock call being tested. ReviewRepository = new Mock <IReviewRepository>(); ReviewRepository.Setup(l => l.GetAlbumReviews(testAlbumId)) .ReturnsAsync(reviews); // Setup MusicStoreService Mock for unit tests. MusicStoreService = new MusicStoreService( AlbumRepository.Object, SongRepository.Object, UserRepository.Object, ReviewRepository.Object ); }