Example #1
0
        public void BuySongTests()
        {
            //Arrange
            User user = new User()
            {
                Id        = DEFAULT_ENTITIES_ID,
                FirstName = "1",
                LastName  = "2",
                Money     = 12
            };

            MusicStore.DataAccess.Song song = new MusicStore.DataAccess.Song()
            {
                Id    = DEFAULT_ENTITIES_ID,
                Name  = "Name",
                Price = 3
            };
            MusicStore.DataAccess.BoughtSong boughtSong = new MusicStore.DataAccess.BoughtSong()
            {
                Id          = DEFAULT_ENTITIES_ID,
                BoughtPrice = song.Price,
                IsVisible   = true,
                BoughtDate  = DateTime.Now,
                Song        = song,
                User        = user
            };
            MusicStore.Domain.DataTransfer.BoughtSong boughtSongDTO = new MusicStore.Domain.DataTransfer.BoughtSong()
            {
                BoughtPrice = boughtSong.BoughtPrice,
                Id          = boughtSong.Id,
                BoughtDate  = boughtSong.BoughtDate,
                Song        = song,
            };
            mockUnitOfWork.Setup(x => x.SongRepository).Returns(mockSongRepository.Object);
            mockUnitOfWork.Setup(x => x.UserAccountRepository).Returns(mockUserRepository.Object);
            mockUnitOfWork.Setup(x => x.BoughtSongRepository).Returns(mockBoughtSongRepository.Object);

            mockUserRepository.Setup(x => x.GetItem(DEFAULT_ENTITIES_ID)).Returns(user);
            mockSongRepository.Setup(x => x.GetItem(DEFAULT_ENTITIES_ID)).Returns(song);
            mockMapBoughtSong.Setup(x => x.AutoMap(It.IsAny <MusicStore.DataAccess.BoughtSong>())).Returns(boughtSongDTO);

            var musicStoreService = new MusicStoreService(mockUnitOfWork.Object, mockMapBoughtSong.Object);

            //Act
            var result = musicStoreService.BuySong(DEFAULT_ENTITIES_ID, DEFAULT_ENTITIES_ID);

            //Assert
            Assert.Equal(boughtSongDTO, result);
        }
Example #2
0
        public void BuySongTestByNegativeId(int userId, int songId)
        {
            //Arrange
            mockUnitOfWork.Setup(x => x.SongRepository).Returns(mockSongRepository.Object);
            mockUnitOfWork.Setup(x => x.UserAccountRepository).Returns(mockUserRepository.Object);
            mockUnitOfWork.Setup(x => x.BoughtSongRepository).Returns(mockBoughtSongRepository.Object);

            var musicStoreService = new MusicStoreService(mockUnitOfWork.Object, mockMapBoughtSong.Object);

            //Act
            ArgumentException ex = Assert.Throws <ArgumentException>(() => musicStoreService.BuySong(userId, songId));

            //Assert
            Assert.Equal("userId is less then 1 or songId is less then 1 in musicStoreService in BuySong\r\nИмя параметра: userId or songId", ex.Message);
        }