public async Task <Result <SongDto> > UpdateSongAsync(Song newSong) { var result = new SongValidator().Validate(newSong); if (!result.IsValid) { return(new Result <SongDto>(ResultType.Invalid, string.Join("; ", result.Errors))); } var song = _unitOfWork.SongRepository .Get(c => c.Id == newSong.Id) .FirstOrDefault(); if (song == null) { return(new Result <SongDto>(ResultType.Invalid, "Could not find Song!")); } song.TrackNo = newSong.TrackNo; song.Name = newSong.Name; song.TimeLength = newSong.TimeLength; song.Rate = newSong.Rate; _unitOfWork.SongRepository.Edit(song); await _unitOfWork.SaveAsync().ConfigureAwait(false); return(new Result <SongDto>(Auto.Mapper.Map <SongDto>(song))); }
static void Main() { var numberOfSongs = int.Parse(Console.ReadLine()); Playlist playlist = new Playlist(); for (int i = 0; i < numberOfSongs; i++) { try { var song = Console .ReadLine() .Split(";", StringSplitOptions.RemoveEmptyEntries); SongValidator.Song(song); Track track = new Track(song[0], song[1], song[2]); Console.WriteLine("Song added."); playlist.Add(track); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine(playlist); }
public void Assign_MoreThan256Characters_to_SongTitleAlbumComposer_ReturnsError(string locale) { //arrange var lorem = new Bogus.DataSets.Lorem(locale: locale) { Random = new Randomizer(1080) }; Song fakeSong = new Song() { Title = lorem.Letter(257), Album = lorem.Letter(257), Composer = lorem.Letter(257) }; SongValidator validator = new SongValidator(); ValidationResult results = validator.Validate(fakeSong); bool isValid = results.IsValid; IList <ValidationFailure> failures = results.Errors; Assert.False(isValid); foreach (var failure in failures) { _output.WriteLine(failure.ErrorMessage); } }
public SongForEditContract(Song song, ContentLanguagePreference languagePreference) : base(song, languagePreference) { ParamIs.NotNull(() => song); Lyrics = song.Lyrics.Select(l => new LyricsForSongContract(l)).ToArray(); Names = new NameManagerEditContract(song.Names); ValidationResult = SongValidator.Validate(song); UpdateNotes = string.Empty; }
public async Task <Result <SongDto> > AddSongAsync(Song song) { var result = new SongValidator().Validate(song); if (!result.IsValid) { return(new Result <SongDto>(ResultType.Invalid, string.Join("; ", result.Errors))); } _unitOfWork.SongRepository.Add(song); await _unitOfWork.SaveAsync().ConfigureAwait(false); return(new Result <SongDto>(Auto.Mapper.Map <SongDto>(song))); }
public void Can_ParseSongNode_As_ValidSongTitle(string xPath, string songTitle, string composer, string bpm, string album, string genre) { var doc = new HtmlDocument(); doc.Load("ez2onDBSample.html"); var songNode = doc.DocumentNode.SelectSingleNode(xPath); var mockLogger = new Mock <ILogger <Ez2OnParser> >(); Ez2OnParser parser = new Ez2OnParser(mockLogger.Object); Song actualSong = parser.ParseSongFromHtmlNode(songNode); Assert.Equal(songTitle, actualSong.Title); Assert.Equal(composer, actualSong.Composer); Assert.Equal(bpm, actualSong.Bpm); Assert.Equal(album, actualSong.Album); Assert.Equal(genre, actualSong.Genre); SongValidator songValidator = new SongValidator(); var validationResults = songValidator.Validate(actualSong); Assert.True(validationResults.IsValid); }
public void Assign_NullOrWhitespace_to_SongTitleAlbumComposer_ReturnsError(string whitespace) { Song fakeSong = new Song() { Title = whitespace, Album = whitespace, Composer = whitespace }; SongValidator validator = new SongValidator(); ValidationResult results = validator.Validate(fakeSong); bool isValid = results.IsValid; IList <ValidationFailure> failures = results.Errors; Assert.False(isValid); foreach (var failure in failures) { _output.WriteLine(failure.ErrorMessage); } }
public void GameSong_MustBeAssociatedWith_EitherGameOrDlc(string locale) { var lorem = new Bogus.DataSets.Lorem(locale) { Random = new Randomizer(1080) }; Game fakeGame = new Game() { Title = lorem.Letter(1) }; Song fakeSong = new Song() { Title = lorem.Letter(1), Composer = lorem.Letter((1)), Album = lorem.Letter(1) }; var randomFluent = new Bogus.Faker() { Random = new Randomizer(1080) }; DifficultyMode fakeMode = new DifficultyMode(); fakeMode.Level = randomFluent.Random.Int(1, 20); fakeMode.Category = DifficultyCategory.Easy; Ez2OnGameTrack fakeGameTrack = new Ez2OnGameTrack(fakeSong, fakeGame, fakeMode); SongValidator fakeSongValidator = new SongValidator(); GameValidator fakeGameValidator = new GameValidator(); GameTrackValidator mockValidator = new GameTrackValidator(fakeSongValidator, fakeGameValidator); var gameMusicResults = mockValidator.Validate(fakeGameTrack); Assert.True(gameMusicResults.IsValid); }
public int UpdateEntryStatuses() { VerifyAdmin(); SysLog("updating entry statuses"); return(HandleTransaction(session => { int count = 0; var artists = session.Query <Artist>().Where(a => !a.Deleted).ToArray(); foreach (var artist in artists) { var result = ArtistValidator.Validate(artist); if (result.Passed && artist.Status == EntryStatus.Draft) { artist.Status = EntryStatus.Finished; session.Update(artist); count++; } else if (!result.Passed && artist.Status == EntryStatus.Finished) { artist.Status = EntryStatus.Draft; session.Update(artist); count++; } } var albums = session.Query <Album>().Where(a => !a.Deleted).ToArray(); foreach (var album in albums) { var result = AlbumValidator.Validate(album); if (result.Passed && album.Status == EntryStatus.Draft) { album.Status = EntryStatus.Finished; session.Update(album); count++; } else if (!result.Passed && album.Status == EntryStatus.Finished) { album.Status = EntryStatus.Draft; session.Update(album); count++; } } var songs = session.Query <Song>().Where(a => !a.Deleted).ToArray(); foreach (var song in songs) { var result = SongValidator.Validate(song); if (result.Passed && song.Status == EntryStatus.Draft) { song.Status = EntryStatus.Finished; session.Update(song); count++; } else if (!result.Passed && song.Status == EntryStatus.Finished) { song.Status = EntryStatus.Draft; session.Update(song); count++; } } return count; })); }