示例#1
0
        public void Should_Return_SongVM_Properly()
        {
            ObjectId id = new ObjectId();

            SongVM songVM = new SongVM()
            {
                Id          = new ObjectId(),
                DisplayName = "test1",
                AlbumId     = new ObjectId(),
                ArtistId    = new ObjectId()
            };

            Song song = new Song()
            {
                Id          = new ObjectId(),
                DisplayName = "test1",
                AlbumId     = new ObjectId(),
                ArtistId    = new ObjectId()
            };

            _mockedSongRepository.Setup(x => x.GetById(id)).Returns(song);

            var result = _songController.Get(id);

            result.DisplayName.Should().Be(songVM.DisplayName);

            result.Id.Should().Be(songVM.Id);

            result.ArtistId.Should().Be(songVM.ArtistId);

            result.AlbumId.Should().Be(songVM.AlbumId);
        }
示例#2
0
        public void Should_Throw_BadRequest_If_Value_Is_Null()
        {
            SongVM value = null;

            var exception = Assert.Throws <HttpResponseException>(() => _songController.Insert(value));

            exception.Response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
示例#3
0
        public EditOrAddSongWindow(ICollectionsEntity entity, SongVM song = null)
        {
            InitializeComponent();

            DataContext = new EditOrAddSongWindowVM(entity, song);

            Logger.Info("EditOrAddSongWindow.EditOrAddSongWindow", "Екземпляр EditOrAddSongWindow створений.");
        }
示例#4
0
        public void Add(object item)
        {
            SongVM newItem = item as SongVM;

            if (newItem != null)
            {
                _songCollection.Add(newItem);
            }
        }
示例#5
0
        public void Should_Throw_BadRequest_If_There_Is_An_Exception()
        {
            SongVM song = new SongVM();

            _mockedSongRepository.Setup(x => x.Insert(It.IsAny <Song>())).Throws(new Exception());

            var exception = Assert.Throws <HttpResponseException>(() => _songController.Insert(song));

            exception.Response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
示例#6
0
        public void Should_Return_One_If_Inserted_Properly()
        {
            SongVM songVM = new SongVM()
            {
                DisplayName = "test",
                AlbumId     = new ObjectId(),
                ArtistId    = new ObjectId()
            };

            _mockedSongRepository.Setup(x => x.Insert(It.IsAny <Song>())).Returns(1);

            _songController.Insert(songVM).Should().Be(1);
        }
        public EditOrAddSongWindowVM(ICollectionsEntity collectionEntity, SongVM song = null)
        {
            _collectionEntity = collectionEntity;
            _song             = song;

            if (_song != null)
            {
                Name     = _song.Name;
                Duration = _song.Duration;
                Lyrics   = _song.Lyrics;
            }

            NameErrorVisibility     = Visibility.Hidden;
            DurationErrorVisibility = Visibility.Hidden;

            Logger.Info("EditOrAddSongWindow.EditOrAddSongWindow", "Екземпляр EditOrAddSongWindow створений.");
        }
        internal bool OkButtonClick()
        {
            _isError = false;

            if (Name == null || Name == String.Empty)
            {
                NameErrorVisibility = Visibility.Visible;
                _isError            = true;
            }
            else
            {
                NameErrorVisibility = Visibility.Hidden;
            }

            if (Duration == null)
            {
                DurationErrorVisibility = Visibility.Visible;
                _isError = true;
            }
            else
            {
                DurationErrorVisibility = Visibility.Hidden;
            }

            if (_isError)
            {
                return(false);
            }

            if (_song == null)
            {
                SongVM song = new SongVM(Name, (TimeSpan)Duration, Lyrics);
                song.SongDL.Save();
                _collectionEntity.Add(song);
            }
            else
            {
                _song.Name     = Name;
                _song.Duration = (TimeSpan)Duration;
                _song.Lyrics   = Lyrics;

                _song.SongDL.Save();
            }
            return(true);
        }
示例#9
0
 internal void DeleteButtonClick()
 {
     foreach (SongInEntertainmentVM songInEntertainment in _songInEntertainmentCollection)
     {
         if (songInEntertainment.SongComparison(AddedSelectedSong))
         {
             _deletedSongCollection.Add(AddedSelectedSong);
             break;
         }
     }
     for (int i = 0; i < _addedSongCollection.Count; i++)
     {
         if (SongVM.Comparison(_addedSongCollection[i], AddedSelectedSong))
         {
             _addedSongCollection.Remove(_addedSongCollection[i]);
             break;
         }
     }
 }
示例#10
0
 internal void AddButtonClick()
 {
     foreach (SongVM song in _addedSongCollection)
     {
         if (SongVM.Comparison(song, SongViewModel.SelectedSong))
         {
             return;
         }
     }
     for (int i = 0; i < _deletedSongCollection.Count; i++)
     {
         if (SongVM.Comparison(_deletedSongCollection[i], SongViewModel.SelectedSong))
         {
             _deletedSongCollection.Remove(_deletedSongCollection[i]);
             break;
         }
     }
     _addedSongCollection.Add(SongViewModel.SelectedSong);
 }
示例#11
0
        public SongVM Get(ObjectId id)
        {
            try
            {
                var result = _songRepository.GetById(id);

                SongVM user = new SongVM()
                {
                    Id          = result.Id,
                    DisplayName = result.DisplayName,
                    ArtistId    = result.ArtistId,
                    AlbumId     = result.AlbumId
                };

                return(user);
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
示例#12
0
        public void The_Properties_Of_The_Song_Should_Be_The_Same()
        {
            SongVM songVM = new SongVM()
            {
                DisplayName = "test",
                AlbumId     = new ObjectId(),
                ArtistId    = new ObjectId()
            };

            Song insertedSong = new Song();

            _mockedSongRepository.Setup(x => x.Insert(It.IsAny <Song>())).Callback <Song>((insertSong) => insertedSong = insertSong);

            _songController.Insert(songVM);

            insertedSong.DisplayName.Should().Be(songVM.DisplayName);

            insertedSong.ArtistId.Should().Be(songVM.ArtistId);

            insertedSong.AlbumId.Should().Be(songVM.AlbumId);
        }
示例#13
0
        public short Insert([Microsoft.AspNetCore.Mvc.FromBody] SongVM value)
        {
            if (value == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            try
            {
                Song user = new Song()
                {
                    DisplayName = value.DisplayName,
                    ArtistId    = value.ArtistId,
                    AlbumId     = value.AlbumId,
                };

                return(_songRepository.Insert(user));
            }
            catch
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
示例#14
0
        public async Task <ActionResult> CreateConfirm([Bind(Include = "Name,File,Genres")] SongVM songVM)
        {
            if (!Session.UserHasRole("Authorized"))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(String.Empty, "Some field are not filled");

                songVM.Genres = (await db.Genres.ToListAsync()).Select(g => g.ToViewModel());
                return(View(songVM));
            }

            if (await db.Songs
                .Where(s => s.Name == songVM.Name)
                .FirstOrDefaultAsync() != null)
            {
                ModelState.AddModelError(String.Empty, "This song is exist");

                return(View(songVM));
            }

            string filename;

            string mappedSongsFolderPath = Server.MapPath(AppConstants.SONGS_FOLDER_VIRTUAL_PATH);
            string savePath;

            // check if random filename exist
            do
            {
                filename = $"{Guid.NewGuid()}.mp3";
                savePath = Path.Combine(mappedSongsFolderPath, filename);
            } while (System.IO.File.Exists(savePath));

            using (FileStream f = System.IO.File.Create(savePath, 4096, FileOptions.Asynchronous))
            {
                await songVM.File.InputStream.CopyToAsync(f);
            }

            Song newSong = new Song()
            {
                Name     = songVM.Name,
                FileName = filename,
                Genres   = await Task.Run(() =>
                {
                    // Transform selected genres to Domain model
                    return(songVM
                           .Genres
                           .Where(genre => genre.IsSelected)
                           .Select(async selectedGenre => await db.Genres.FindAsync(selectedGenre.Id))
                           .Select(t => t.Result)
                           .ToList());
                })
            };

            db.Songs.Add(newSong);

            await db.SaveChangesAsync();

            return(Redirect("~/"));
        }
示例#15
0
 public TagListVM GetTagListBySong(SongVM song)
 {
     throw new NotImplementedException();
 }