public void TestInit() { _mp3File = new TestMp3File("/test"); _fileDiff = new FileDifferences(_mp3File); _d1 = new Diff { FileNameValue = "1", TagValue = "2" }; _d2 = new Diff { FileNameValue = "art1", TagValue = "art2" }; _fileDiff.Add(TagType.Id, _d1); _fileDiff.Add(TagType.Artist, _d2); }
public FileDifferences[] GetDifferences() { var list = new List <FileDifferences>(); foreach (var mp3 in _files) { var mp3Data = mp3.GetId3Data(); var extracter = new DataExtracter(_mask); var tags = extracter.GetTags(); var prefixes = extracter.FindAllPrefixes(tags); var diffs = new FileDifferences(mp3); var data = extracter.GetFullDataFromString(prefixes, Path.GetFileNameWithoutExtension(mp3.FilePath), tags); var differenceItems = data.Where(item => mp3Data[item.Key] != item.Value).ToArray(); if (!differenceItems.Any()) { continue; } foreach (var item in differenceItems) { diffs.Add(item.Key, new Diff { FileNameValue = item.Value, TagValue = mp3Data[item.Key] }); } list.Add(diffs); } return(list.ToArray()); }
public FileDifferences[] GetDifferences() { var list = new List<FileDifferences>(); foreach (var mp3 in _files) { var mp3Data = mp3.GetId3Data(); var extracter = new DataExtracter(_mask); var tags = extracter.GetTags(); var prefixes = extracter.FindAllPrefixes(tags); var diffs = new FileDifferences(mp3); var data = extracter.GetFullDataFromString(prefixes, Path.GetFileNameWithoutExtension(mp3.FilePath), tags); var differenceItems = data.Where(item => mp3Data[item.Key] != item.Value).ToArray(); if (!differenceItems.Any()) continue; foreach (var item in differenceItems) { diffs.Add(item.Key, new Diff { FileNameValue = item.Value, TagValue = mp3Data[item.Key] }); } list.Add(diffs); } return list.ToArray(); }
public void Test_AnalyserWithNotEnoughData() { var firstItem = new TestMp3File("1. name1 - title1.mp3") { TrackId = "1", Title = "title1", Artist = "name1" }; var secondItem = new TestMp3File("2. - title2.mp3") { TrackId = "1", Title = "title2", Artist = "name1" }; var thirdItem = new TestMp3File("3. .mp3") { TrackId = "1", Title = "title3", Artist = "name3" }; var files = new TestMp3File[] { firstItem, secondItem, thirdItem, }; var analyser = new Mp3FileAnalyser(files, "{id}. {artist} - {title}"); var diffs = analyser.GetDifferences().ToList(); var expectedDiff1 = new FileDifferences(secondItem); expectedDiff1.Add(TagType.Id, new Diff { FileNameValue = "2", TagValue = "1" }); expectedDiff1.Add(TagType.Artist, new Diff { FileNameValue = "", TagValue = "name1" }); var expectedDiff2 = new FileDifferences(thirdItem); expectedDiff2.Add(TagType.Id, new Diff { FileNameValue = "3", TagValue = "1" }); expectedDiff2.Add(TagType.Title, new Diff { FileNameValue = "", TagValue = "title3" }); expectedDiff2.Add(TagType.Artist, new Diff { FileNameValue = "", TagValue = "name3" }); var expectedDiffs = new List <FileDifferences>() { expectedDiff1, expectedDiff2, }; Assert.AreEqual(expectedDiffs.Count, diffs.Count); for (var i = 0; i < diffs.Count; i++) { Assert.AreEqual(expectedDiffs[i].Mp3File, diffs[i].Mp3File); Assert.AreEqual(expectedDiffs[i].Diffs.Count, diffs[i].Diffs.Count); foreach (var diff in expectedDiffs[i].Diffs) { Assert.AreEqual(expectedDiffs[i].Diffs[diff.Key].FileNameValue, diffs[i].Diffs[diff.Key].FileNameValue); Assert.AreEqual(expectedDiffs[i].Diffs[diff.Key].TagValue, diffs[i].Diffs[diff.Key].TagValue); } } }