public void DisplaySongsOfAlbum()
        {
            //Arrange

            mockUserAccountService.Setup(x => x.ConvertGuidInStringIdToIntId(null)).Returns(DEFAULT_ID_FOR_ENTITIES);

            var             musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);
            var             userMock             = new Mock <IPrincipal>();
            GenericIdentity identity             = new GenericIdentity("a");

            userMock.Setup(p => p.Identity).Returns(identity);
            userMock.Setup(p => p.Identity.IsAuthenticated).Returns(true);

            var contextMock = new Mock <HttpContextBase>();

            contextMock.SetupGet(ctx => ctx.User)
            .Returns(userMock.Object);

            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.SetupGet(con => con.HttpContext)
            .Returns(contextMock.Object);

            musicStoreController.ControllerContext = controllerContextMock.Object;

            //Act
            var result = musicStoreController.DisplaySongsOfAlbum(DEFAULT_ID_FOR_ENTITIES);

            //Assert
            Assert.IsType(typeof(RedirectToRouteResult), result);
        }
        public void DisplayPaginatedAlbums()
        {
            //Arrange
            var albumDomain = new MusicStore.Domain.DataTransfer.Album()
            {
                Id   = 1,
                Name = "Album 1",
                DiscountIfBuyAllSongs = 15.0m,
            };
            var albumDomainList = new List <MusicStore.Domain.DataTransfer.Album>()
            {
                albumDomain
            };
            var indexViewDomainItem = new IndexViewItem <MusicStore.Domain.DataTransfer.Album>()
            {
                Items    = albumDomainList,
                PageInfo = new Repository <MusicStore.Domain.DataTransfer.Album>()
                {
                    PageNumber = 1,
                    PageSize   = 1,
                    TotalItems = 1
                }
            };

            mockMusicStoreDisplayService.Setup(x => x.DisplayAlbumsWithPagination(1, 1)).Returns(indexViewDomainItem);
            var musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);
            //Act
            var result = (ViewResult)musicStoreController.DisplayPaginatedAlbums(1, 1);

            //Assert
            Assert.Equal(indexViewDomainItem, result.Model);
        }
        public void DisplayPaginatedAlbumsTestByNegativeId()
        {
            //Arrange
            var musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);
            //Act
            var result = Assert.Throws <ArgumentException>(() => musicStoreController.DisplayPaginatedAlbums(-1, 1));

            //Assert
            Assert.Equal("page is less then 0\r\nИмя параметра: page", result.Message);
        }
        public void DisplayPaginatedAlbumsTestByException()
        {
            //Arrange
            mockMusicStoreDisplayService.Setup(x => x.DisplayAlbumsWithPagination(1, 1)).Throws(new Exception("exception"));
            var musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);
            //Act
            var result = (HttpStatusCodeResult)musicStoreController.DisplayPaginatedAlbums(1, 1);

            //Assert
            Assert.Equal(400, result.StatusCode);
        }
        public void BuyMusicTestByNegativeId(int userId, int songId)
        {
            //Arrange
            MusicStore.Domain.DataTransfer.BoughtSong boughtSongDTO = new MusicStore.Domain.DataTransfer.BoughtSong();
            mockMusicStoreService.Setup(x => x.BuySong(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES, DEFAULT_DISCOUNT)).Returns(boughtSongDTO);
            MusicStoreController musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);

            //Act
            HttpStatusCodeResult result = (HttpStatusCodeResult)musicStoreController.BuyMusic(userId, songId);

            //Assert
            Assert.Equal(400, result.StatusCode);
        }
        public void BuyMusicTestNoBuy()
        {
            //Arrange
            MusicStore.Domain.DataTransfer.BoughtSong boughtSongDTO = new MusicStore.Domain.DataTransfer.BoughtSong();
            MusicStore.DataAccess.BoughtSong          boughtSong    = new MusicStore.DataAccess.BoughtSong();

            mockMusicStoreService.Setup(x => x.BuySong(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES, DEFAULT_DISCOUNT));
            mockMapBoughtSong.Setup(x => x.AutoMap(boughtSong)).Returns(boughtSongDTO);
            MusicStoreController musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);
            //Act
            ViewResult result = (ViewResult)musicStoreController.BuyMusic(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES);

            //Assert
            Assert.Equal(EXPECTED_NO_BUY_MESSAGE, result.ViewData["OperationResult"]);
        }
        public void BuyMusicTestByArgumentException()
        {
            const string EXPECTED_MESSAGE = "Покупка совершена успешно";

            //Arrange
            MusicStore.Domain.DataTransfer.BoughtSong boughtSongDTO = new MusicStore.Domain.DataTransfer.BoughtSong();
            MusicStore.DataAccess.BoughtSong          boughtSong    = new MusicStore.DataAccess.BoughtSong();

            mockMusicStoreService
            .Setup(x => x.BuySong(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES, DEFAULT_DISCOUNT))
            .Throws(new ArgumentException("exception"));
            mockMapBoughtSong.Setup(x => x.AutoMap(boughtSong)).Returns(boughtSongDTO);
            MusicStoreController musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);

            //Act
            var result = (HttpStatusCodeResult)(musicStoreController.BuyMusic(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES));

            //Assert
            Assert.Equal(400, result.StatusCode);
        }
        public void GetAvailableSongsListForBuyByUserTest()
        {
            var songDomain = new MusicStore.Domain.DataTransfer.Song()
            {
                Id    = 0,
                Name  = "All world for you",
                Price = 1.99m,
            };
            var songsDomain = new List <MusicStore.Domain.DataTransfer.Song>
            {
                songDomain
            };

            mockMusicStoreDisplayService.Setup(x => x.GetSongsListFromAlbumAvailableForBuyByUser(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES)).Returns(songsDomain);

            var musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);

            //Act
            var result = (ViewResult)musicStoreController.GetAvailableSongsListForBuyByUser(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES);

            //Assert
            Assert.Equal(songsDomain, result.Model);
        }
        public void BuyWholeAlbumTestByArgumentException(bool hasDiscount)
        {
            //Arrange
            var songDomain = new MusicStore.Domain.DataTransfer.Song()
            {
                Id    = 0,
                Name  = "All world for you",
                Price = 1.99m,
            };
            var songsDomain = new List <MusicStore.Domain.DataTransfer.Song>
            {
                songDomain
            };

            MusicStore.DataAccess.Song song = new MusicStore.DataAccess.Song()
            {
                Id    = DEFAULT_ID_FOR_ENTITIES,
                Name  = "Name",
                Price = 3
            };
            MusicStore.DataAccess.BoughtSong boughtSong = new MusicStore.DataAccess.BoughtSong()
            {
                Id          = DEFAULT_ID_FOR_ENTITIES,
                BoughtPrice = song.Price,
                IsVisible   = true,
                BoughtDate  = DateTime.Now,
                Song        = song,
            };
            MusicStore.Domain.DataTransfer.BoughtSong boughtSongDTO = new MusicStore.Domain.DataTransfer.BoughtSong()
            {
                BoughtPrice = boughtSong.BoughtPrice,
                Id          = boughtSong.Id,
                BoughtDate  = boughtSong.BoughtDate,
                Song        = song,
            };

            mockUserAccountService.Setup(x => x.ConvertGuidInStringIdToIntId(null)).Returns(DEFAULT_ID_FOR_ENTITIES);
            mockMusicStoreDisplayService.Setup(x => x.GetSongsListFromAlbum(DEFAULT_ID_FOR_ENTITIES)).Returns(songsDomain);
            mockDiscountService.Setup(x => x.IsDiscountAvailable(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES)).Returns(hasDiscount);
            mockMusicStoreService.Setup(x => x.BuySong(0, DEFAULT_ID_FOR_ENTITIES, 0)).Throws(new ArgumentException("exception"));

            var             musicStoreController = new MusicStoreController(mockMusicStoreService.Object, mockUserAccountService.Object, mockMusicStoreDisplayService.Object, mockDiscountService.Object);
            var             userMock             = new Mock <IPrincipal>();
            GenericIdentity identity             = new GenericIdentity("a");

            userMock.Setup(p => p.Identity).Returns(identity);

            var contextMock = new Mock <HttpContextBase>();

            contextMock.SetupGet(ctx => ctx.User)
            .Returns(userMock.Object);

            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.SetupGet(con => con.HttpContext)
            .Returns(contextMock.Object);

            musicStoreController.ControllerContext = controllerContextMock.Object;

            //Act
            var result = (HttpStatusCodeResult)musicStoreController.BuyWholeAlbum(DEFAULT_ID_FOR_ENTITIES, DEFAULT_ID_FOR_ENTITIES);

            //Assert
            Assert.Equal(400, result.StatusCode);
        }