public void TestCompressor() { var failed = false; string errorMsg = null; Converter.Logger = new Logger(); var testDir = new Uri(Path .Combine(new Uri(Assembly.GetExecutingAssembly().CodeBase) .LocalPath, @"..\..\..\..\..\tst")) .LocalPath; const string amlFileName = "aml.xml"; var res = Directory.GetFiles(testDir).Where(f => !Path.GetFileName(f).Equals(amlFileName)).ToArray(); var amlFile = Directory.GetFiles(testDir).First(f => Path.GetFileName(f).Equals(amlFileName)); // Tests for 1) var finalAmlxFile = Path.Combine(testDir, "myAmlx.amlx"); AMLPackager.Compress(amlFile, Path.Combine(testDir, "myAmlx.amlx"), res, true); using (var archive = ZipFile.OpenRead(finalAmlxFile)) { // Tests for 2) foreach (var fileName in res.Select(Path.GetFileName)) { if (archive.Entries.Any(f => f.Name.Equals(fileName))) { continue; } failed = true; errorMsg = $"We are missing {fileName} in the ZIP-archive."; } } try { File.Delete(finalAmlxFile); } catch { Assert.Fail("Failed to delete the test AMLX File. You might need to delete it by hand under ./tst/ ."); } if (failed) { Assert.Fail(errorMsg); } }
public void TestEmptyResources() { var exceptionOccured = false; var testDir = new Uri(Path .Combine(new Uri(Assembly.GetExecutingAssembly().CodeBase) .LocalPath, @"..\..\..\..\..\tst")) .LocalPath; const string amlFileName = "aml.xml"; var res = new string[0]; var amlFile = Directory.GetFiles(testDir).First(f => Path.GetFileName(f).Equals(amlFileName)); var finalAmlxFile = Path.Combine(testDir, "myAmlx.amlx"); try { AMLPackager.Compress(amlFile, Path.Combine(testDir, "myAmlx.amlx"), res, true); try { File.Delete(finalAmlxFile); } catch { Assert.Fail("Failed to delete the test AMLX File. You might need to delete it by hand under ./tst/ ."); } } catch { exceptionOccured = true; } try { File.Delete(finalAmlxFile); } catch { Assert.Fail("Failed to delete the test AMLX File. You might need to delete it by hand under ./tst/ ."); } if (!exceptionOccured) { return; } Assert.Fail("Compress function should work without resources."); }
public void FailOnOmittedAmlName() { var exceptionOccured = false; try { AMLPackager.Compress("", "randomDestination", null); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.Fail("Compress function should thrown an exception on empty AML name."); } }
public void FailOnOmittedDestinationPath() { var exceptionOccured = false; try { AMLPackager.Compress("myAml.xml", "", null); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.Fail("Compress function should thrown an exception on empty destination string."); } }