Пример #1
0
        public void GetStatisticByNumberOfSoldSongsTest()
        {
            //Arrange
            User user = new User()
            {
                Id        = DEFAULT_USER_ID,
                FirstName = "1",
                LastName  = "2",
                Money     = 12
            };
            var song4 = new Song()
            {
                Id    = 4,
                Name  = "4",
                Price = 4.99m,
            };
            var song5 = new Song()
            {
                Id    = 5,
                Name  = "5",
                Price = 4.99m,
            };
            var boughtSong1 = new BoughtSong()
            {
                Id          = 0,
                User        = user,
                IsVisible   = true,
                Song        = song4,
                BoughtPrice = song4.Price,
                BoughtDate  = new DateTime(2018, 10, 3)
            };
            var boughtSong2 = new BoughtSong()
            {
                Id          = 1,
                User        = user,
                IsVisible   = true,
                Song        = song5,
                BoughtPrice = song5.Price,
                BoughtDate  = new DateTime(2018, 10, 3)
            };

            user.BoughtSongs.Add(boughtSong1);
            user.BoughtSongs.Add(boughtSong2);

            var boughtSongList = new List <BoughtSong>()
            {
                boughtSong1, boughtSong2
            };

            mockUnitOfWork.Setup(x => x.BoughtSongRepository).Returns(mockBoughtSongRepository.Object);
            mockBoughtSongRepository.Setup(x => x.GetItemList()).Returns(boughtSongList);
            var adminStatisticService = new AdminStatisticService(mockUnitOfWork.Object);

            //Act
            var result = adminStatisticService.GetStatisticByNumberOfSoldSongs(new DateTime(2018, 10, 1), new DateTime(2018, 10, 10));

            //Assert
            Assert.Equal(2, result);
        }
        public void GetTotalNumberOfSongsTest()
        {
            //Arrange
            User user = new User()
            {
                Id        = DEFAULT_USER_ID,
                FirstName = "1",
                LastName  = "2",
                Money     = 12
            };
            var song4 = new Song()
            {
                Id    = 4,
                Name  = "4",
                Price = 4.99m,
            };
            var song5 = new Song()
            {
                Id    = 5,
                Name  = "5",
                Price = 4.99m,
            };
            var boughtSong1 = new BoughtSong()
            {
                Id          = 0,
                User        = user,
                IsVisible   = true,
                Song        = song4,
                BoughtPrice = song4.Price,
                BoughtDate  = new DateTime(2018, 10, 3)
            };
            var boughtSong2 = new BoughtSong()
            {
                Id          = 1,
                User        = user,
                IsVisible   = true,
                Song        = song5,
                BoughtPrice = song5.Price,
                BoughtDate  = new DateTime(2018, 10, 3)
            };

            user.BoughtSongs.Add(boughtSong1);
            user.BoughtSongs.Add(boughtSong2);

            mockUnitOfWork.Setup(x => x.UserAccountRepository).Returns(mockUserRepository.Object);
            mockUserRepository.Setup(x => x.GetItem(DEFAULT_USER_ID)).Returns(user);
            var userStatisticService = new UserStatisticService(mockUnitOfWork.Object);

            //Act
            var result = userStatisticService.GetTotalNumberOfSongs(DEFAULT_USER_ID);

            //Assert
            Assert.Equal(2, result);
        }
Пример #3
0
 public DataTransfer.BoughtSong AutoMap(BoughtSong item)
 {
     DataTransfer.BoughtSong boughtSong = new DataTransfer.BoughtSong()
     {
         Id          = item.Id,
         BoughtDate  = item.BoughtDate,
         BoughtPrice = item.BoughtPrice,
         Song        = item.Song
     };
     return(boughtSong);
 }
Пример #4
0
        public Domain.DataTransfer.BoughtSong BuySong(int songId, int userId, decimal discountForBuyAllAlbum = 0)
        {
            if (songId <= 0 || userId <= 0)
            {
                throw new ArgumentException("userId is less then 1 or songId is less then 1 in musicStoreService in BuySong", "userId or songId");
            }

            User user = _userRepository.GetItem(userId);

            if (user == null)
            {
                throw new Exception("User is null");
            }

            Song song = _songRepository.GetItem(songId);

            if (song == null)
            {
                throw new Exception("Song is null");
            }

            if (user.Money < song.Price)
            {
                throw new Exception($"User has not enough money for buy {song.Name} song");
            }

            decimal songBoughtPrice = 0;

            songBoughtPrice = discountForBuyAllAlbum > 0 ? song.Price - (song.Price * (discountForBuyAllAlbum / 100)) : song.Price;

            BoughtSong boughtSong = new BoughtSong()
            {
                BoughtPrice = songBoughtPrice,
                IsVisible   = true,
                BoughtDate  = DateTime.Now,
                Song        = song,
                User        = user
            };

            user.Money -= songBoughtPrice;
            _boughtSongRepository.Create(boughtSong);
            _userRepository.Update(user);

            var result = _mapBoughtSong.AutoMap(boughtSong);

            return(result);
        }
Пример #5
0
        public void CheckDiscountAvailableTest()
        {
            //Arrange
            User user = new User()
            {
                Id        = DEFAULT_USER_ID,
                FirstName = "1",
                LastName  = "2",
                Money     = 12
            };
            var album = new Album()
            {
                Id   = 1,
                Name = "Album 1",
                DiscountIfBuyAllSongs = 15.0m,
            };
            var song1 = new Song()
            {
                Id    = 1,
                Name  = "All world for you",
                Price = 1.99m,
                Album = album,
            };
            var song2 = new Song()
            {
                Id    = 2,
                Name  = "All world again you",
                Price = 2.99m,
                Album = album
            };
            var song3 = new Song()
            {
                Id    = 3,
                Name  = "All world do not see you",
                Price = 3.99m,
                Album = album
            };
            var song4 = new Song()
            {
                Id    = 4,
                Name  = "4",
                Price = 4.99m,
            };
            var song5 = new Song()
            {
                Id    = 5,
                Name  = "5",
                Price = 4.99m,
            };
            var boughtSong1 = new BoughtSong()
            {
                Id          = 0,
                User        = user,
                IsVisible   = true,
                Song        = song4,
                BoughtPrice = song4.Price,
                BoughtDate  = new DateTime(2018, 10, 3)
            };
            var boughtSong2 = new BoughtSong()
            {
                Id          = 1,
                User        = user,
                IsVisible   = true,
                Song        = song5,
                BoughtPrice = song5.Price,
                BoughtDate  = new DateTime(2018, 10, 3)
            };

            album.Songs.Add(song1);
            album.Songs.Add(song2);
            album.Songs.Add(song3);
            user.BoughtSongs.Add(boughtSong1);
            user.BoughtSongs.Add(boughtSong2);

            mockUnitOfWork.Setup(x => x.AlbumRepositoryWithPagination).Returns(mockAlbumRepository.Object);
            mockUnitOfWork.Setup(x => x.UserAccountRepository).Returns(mockUserRepository.Object);

            mockUserRepository.Setup(x => x.GetItem(DEFAULT_USER_ID)).Returns(user);
            mockAlbumRepository.Setup(x => x.GetItem(DEFAULT_ALBUM_ID)).Returns(album);
            var discountService = new DiscountService(mockUnitOfWork.Object);
            //Act
            var result = discountService.IsDiscountAvailable(DEFAULT_USER_ID, DEFAULT_ALBUM_ID);

            //Assert
            Assert.True(result);
        }
Пример #6
0
 public BoughtSong ReAutoMap(DataTransfer.BoughtSong item, BoughtSong initialItem)
 {
     throw new System.NotImplementedException();
 }