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 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); }