private static void RegisterTestFilePacker(ContainerBuilder builder) { builder.Register(c => new TestSuitePackage()) .As<ITestSuitePackage>() .SingleInstance(); builder.Register( c => { var ctx = c.Resolve<IComponentContext>(); StoreFileDataForEnvironment func = (environment, stepOrder, storedPath, filePath) => { var suitePackage = ctx.Resolve<ITestSuitePackage>(); var environmentPackage = suitePackage.Environment(environment); if (environmentPackage == null) { environmentPackage = new TestEnvironmentPackage(environment); suitePackage.Add(environmentPackage); } var testPackage = environmentPackage.Test(stepOrder); if (testPackage == null) { testPackage = new TestStepPackage(stepOrder); environmentPackage.Add(testPackage); } testPackage.Add(filePath, storedPath); }; return func; }); }
/// <summary> /// Unpacks the test files from a given package file to a given destination location. /// </summary> /// <param name="destinationDirectory">The full path to the destination directory.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="destinationDirectory"/> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="destinationDirectory"/> is an empty string. /// </exception> /// <exception cref="NeedPackagePathException"> /// Thrown if no <see cref="PackagePath"/> has been provided. /// </exception> public void UnpackTo(string destinationDirectory) { { Lokad.Enforce.Argument(() => destinationDirectory); Lokad.Enforce.Argument(() => destinationDirectory, Lokad.Rules.StringIs.NotEmpty); Lokad.Enforce.With<NeedPackagePathException>( !string.IsNullOrWhiteSpace(PackagePath), Resources.Exceptions_Messages_NeedPackagePath); } if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); } using (var zipFile = ZipFile.Read(PackagePath)) { foreach (var entry in zipFile) { entry.Extract(destinationDirectory, ExtractExistingFileAction.OverwriteSilently); var step = new TestEnvironmentPackage(); step.LoadFrom(Path.Combine(destinationDirectory, entry.FileName)); m_TestEnvironments.Add(step.Environment, step); } } }