Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        public string this[string columnName]
        {
            get
            {
                var result = _validator.Validate(Mapper.Map <Song>(this));

                if (!result.Errors.Any(e => e.PropertyName == columnName))
                {
                    return(string.Empty);
                }

                var error = result.Errors
                            .First(e => e.PropertyName == columnName)
                            .ErrorMessage;
                return(error);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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;
            }));
        }