public void ApplyDeltaPackageSmokeTest() { var basePackage = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "Shimmer.Core.1.0.0.0-full.nupkg")); var deltaPackage = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "Shimmer.Core.1.1.0.0-delta.nupkg")); var expectedPackageFile = IntegrationTestHelper.GetPath("fixtures", "Shimmer.Core.1.1.0.0-full.nupkg"); var outFile = Path.GetTempFileName() + ".nupkg"; try { basePackage.ApplyDeltaPackage(deltaPackage, outFile); var result = new ZipPackage(outFile); var expected = new ZipPackage(expectedPackageFile); result.Id.ShouldEqual(expected.Id); result.Version.ShouldEqual(expected.Version); this.Log().Info("Expected file list:"); expected.GetFiles().Select(x => x.Path).OrderBy(x => x).ForEach(x => this.Log().Info(x)); this.Log().Info("Actual file list:"); result.GetFiles().Select(x => x.Path).OrderBy(x => x).ForEach(x => this.Log().Info(x)); Enumerable.Zip( expected.GetFiles().Select(x => x.Path).OrderBy(x => x), result.GetFiles().Select(x => x.Path).OrderBy(x => x), (e, a) => e == a ).All(x => x).ShouldBeTrue(); } finally { if (File.Exists(outFile)) { File.Delete(outFile); } } }
IObservable <ReleaseEntry> createFullPackagesFromDeltas(IEnumerable <ReleaseEntry> releasesToApply, ReleaseEntry currentVersion) { Contract.Requires(releasesToApply != null); // If there are no deltas in our list, we're already done if (!releasesToApply.Any() || releasesToApply.All(x => !x.IsDelta)) { return(Observable.Return(releasesToApply.MaxBy(x => x.Version).First())); } if (!releasesToApply.All(x => x.IsDelta)) { return(Observable.Throw <ReleaseEntry>(new Exception("Cannot apply combinations of delta and full packages"))); } // Smash together our base full package and the nearest delta var ret = Observable.Start(() => { var basePkg = new ReleasePackage(Path.Combine(rootAppDirectory, "packages", currentVersion.Filename)); var deltaPkg = new ReleasePackage(Path.Combine(rootAppDirectory, "packages", releasesToApply.First().Filename)); return(basePkg.ApplyDeltaPackage(deltaPkg, Regex.Replace(deltaPkg.InputPackageFile, @"-delta.nupkg$", ".nupkg", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))); }, RxApp.TaskpoolScheduler); if (releasesToApply.Count() == 1) { return(ret.Select(x => ReleaseEntry.GenerateFromFile(x.InputPackageFile))); } return(ret.SelectMany(x => { var fi = fileSystem.GetFileInfo(x.InputPackageFile); var entry = ReleaseEntry.GenerateFromFile(fi.OpenRead(), x.InputPackageFile); // Recursively combine the rest of them return createFullPackagesFromDeltas(releasesToApply.Skip(1), entry); })); }