diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index ca6b772e..b7d3958f 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -374,17 +374,24 @@ protected override ValidationResult Validate(string property) } break; case nameof(ApplicationOptions): - if (ApplicationOptions == null) + if (ExportType == ExportType.Cuesheet) { - var validationMessages = new List() + if (ApplicationOptions == null) { - new("{0} has no value!", nameof(ApplicationOptions)) - }; - validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + var validationMessages = new List() + { + new("{0} has no value!", nameof(ApplicationOptions)) + }; + validationResult = ValidationResult.Create(ValidationStatus.Error, validationMessages); + } + else + { + validationResult = ValidationResult.Create(ValidationStatus.Success); + } } else { - validationResult = ValidationResult.Create(ValidationStatus.Success); + validationResult = ValidationResult.Create(ValidationStatus.NoValidation); } break; case nameof(Exportprofile): diff --git a/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs b/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs index 69a21f3d..a58f4c74 100644 --- a/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs +++ b/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs @@ -56,8 +56,8 @@ public async Task GenerateCuesheetFilesTestAsync() track.End = begin; cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(Exportfile.DefaultCuesheetFilename, generatedFiles.First().Name); var content = generatedFiles.First().Content; @@ -83,7 +83,7 @@ public async Task GenerateCuesheetFilesTestAsync() File.Delete(fileName); cuesheet.CDTextfile = new CDTextfile("Testfile.cdt"); cuesheet.Cataloguenumber.Value = "0123456789123"; - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -95,8 +95,8 @@ public async Task GenerateCuesheetFilesTestAsync() File.Delete(fileName); cuesheet.CDTextfile = new CDTextfile("Testfile.cdt"); cuesheet.Cataloguenumber.Value = "Testvalue"; - Assert.IsFalse(generator.CanWrite(ExportType.Cuesheet)); - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + Assert.AreEqual(ValidationStatus.Error, generator.Validate().Status); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(0, generatedFiles.Count); } @@ -131,8 +131,8 @@ public async Task GenerateCuesheetFilesWithPreGapAndPostGapTestAsync() track.PreGap = new TimeSpan(0, 0, 3); cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); var content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -193,8 +193,8 @@ public async Task GenerateCuesheetFilesWithTrackFlagsTestAsync() } cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); var content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -245,16 +245,16 @@ public async Task GenerateCuesheetFilesWithIncorrectTrackPositionsTestAsync() track.End = begin; cuesheet.AddTrack(track, testHelper.ApplicationOptions); } - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions); - Assert.IsFalse(generator.CanWrite(ExportType.Cuesheet)); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions); + Assert.AreEqual(ValidationStatus.Error, generator.Validate().Status); //Rearrange positions cuesheet.Tracks.ElementAt(0).Position = 1; cuesheet.Tracks.ElementAt(1).Position = 2; cuesheet.Tracks.ElementAt(2).Position = 3; cuesheet.Tracks.ElementAt(3).Position = 4; cuesheet.Tracks.ElementAt(4).Position = 5; - Assert.IsTrue(generator.CanWrite(ExportType.Cuesheet)); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + Assert.AreEqual(ValidationStatus.Success, generator.Validate().Status); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); var content = generatedFiles.First().Content; Assert.IsNotNull(content); @@ -315,9 +315,9 @@ public async Task GenerateCuesheetFilesWithSplitPointsTestAsync() splitPoint.Title = "Title 3"; splitPoint.Moment = new TimeSpan(1, 30, 0); testHelper.ApplicationOptions.CuesheetFilename = "Unit test.cue"; - var generator = new ExportfileGenerator(cuesheet, applicationOptions: testHelper.ApplicationOptions, audioConverterService:testHelper.AudioConverterService); - Assert.IsTrue(generator.CanWrite(ExportType.Cuesheet)); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Cuesheet); + var generator = new ExportfileGenerator(ExportType.Cuesheet, cuesheet, applicationOptions: testHelper.ApplicationOptions, audioConverterService:testHelper.AudioConverterService); + Assert.AreEqual(ValidationStatus.Success, generator.Validate().Status); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(5, generatedFiles.Count); var position = 1; var counter = 1; @@ -427,8 +427,8 @@ public async Task GenerateExportfilesTestAsync() SchemeFooter = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor" }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); - var generator = new ExportfileGenerator(cuesheet, exportprofile: exportProfile); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + var generator = new ExportfileGenerator(ExportType.Exportprofile, cuesheet, exportprofile: exportProfile); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); var fileContent = generatedFiles.First().Content; @@ -461,7 +461,7 @@ public async Task GenerateExportfilesTestAsync() }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); generator.Exportprofile = exportProfile; - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); fileContent = generatedFiles.First().Content; @@ -495,7 +495,7 @@ public async Task GenerateExportfilesTestAsync() }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); generator.Exportprofile = exportProfile; - generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); fileContent = generatedFiles.First().Content; @@ -565,8 +565,8 @@ public async Task GenerateExportfilesWithPregapAndPostgapTestAsync() SchemeFooter = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor at %Date%" }; Assert.AreEqual(ValidationStatus.Success, exportProfile.Validate().Status); - var generator = new ExportfileGenerator(cuesheet, exportprofile: exportProfile); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + var generator = new ExportfileGenerator(ExportType.Exportprofile, cuesheet, exportprofile: exportProfile); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(1, generatedFiles.Count); Assert.AreEqual(exportProfile.Filename, generatedFiles.First().Name); var fileContent = generatedFiles.First().Content; @@ -641,9 +641,9 @@ public async Task GenerateExportfilesWithSplitPointsTestAsync() SchemeTracks = "%Track.Position%;%Track.Artist%;%Track.Title%;%Track.Begin%;%Track.End%;%Track.Length%", SchemeFooter = "Exported %Cuesheet.Title% from %Cuesheet.Artist% using AudioCuesheetEditor" }; - var generator = new ExportfileGenerator(cuesheet, exportProfile, audioConverterService: testHelper.AudioConverterService); - Assert.IsTrue(generator.CanWrite(ExportType.Exportprofile)); - var generatedFiles = await generator.GenerateExportfilesAsync(ExportType.Exportprofile); + var generator = new ExportfileGenerator(ExportType.Exportprofile, cuesheet, exportProfile, audioConverterService: testHelper.AudioConverterService); + Assert.AreEqual(ValidationStatus.Success, generator.Validate().Status); + var generatedFiles = await generator.GenerateExportfilesAsync(); Assert.AreEqual(5, generatedFiles.Count); //Check split according to split points