public static VersionManifest GenerateFromDirectory(string version, string directory)
        {
            directory = PathUtils.AddTrailingSlash(directory);

            List<VersionManifestFile> files = new List<VersionManifestFile>();
            foreach (string filename in Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories))
            {
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    string checksum = Checksum.Calculate(fs);
                    VersionManifestFile file = new VersionManifestFile(filename.Remove(0, directory.Length), checksum, fs.Length);
                    files.Add(file);
                }
            }

            return new VersionManifest(version, files);
        }
 public void SetUp()
 {
     file = new VersionManifestFile("", "", 1);
     file.Deltas.Add(new VersionManifestDeltaFile("aa.bb", "AAA", 1));
     file.Deltas.Add(new VersionManifestDeltaFile("bb.bb", "BBB", 1));
 }
        public void UpdateTo_WithAnIncorrectDelta_SetTheActionAsDownload()
        {
            VersionManifestFile fileOriginal = new VersionManifestFile("arquivo1.txt", "333", 1000);
            VersionManifestFile fileUpdate = new VersionManifestFile("arquivo1.txt", "123", 1000);
            fileUpdate.Deltas.Add(new VersionManifestDeltaFile("deltas\\arquivo1.txt", "444", 10));
            VersionManifest currentManifest = new VersionManifest("1.0.0", new VersionManifestFile[] { fileOriginal });
            VersionManifest updateManifest = new VersionManifest("2.0.0", new VersionManifestFile[] { fileUpdate });

            UpdateRecipe recipe = currentManifest.UpdateTo(updateManifest);

            Assert.That(recipe.Files, Has.Count.EqualTo(1));
            Assert.That(recipe.Files.First().Action, Is.EqualTo(FileUpdateAction.Download));
        }
        public void UpdateTo_VersionWithTheFileWithIncorrectChecksum_SetTheActionAsDownload()
        {
            VersionManifestFile fileOriginal = new VersionManifestFile("arquivo1.txt", "333", 1000);
            VersionManifestFile fileUpdate = new VersionManifestFile("arquivo1.txt", "123", 1000);
            VersionManifest currentManifest = new VersionManifest("1.0.0", new VersionManifestFile[] { fileOriginal });
            VersionManifest updateManifest = new VersionManifest("2.0.0", new VersionManifestFile[] { fileUpdate });

            UpdateRecipe recipe = currentManifest.UpdateTo(updateManifest);

            Assert.That(recipe.Files, Has.Count.EqualTo(1));
            Assert.That(recipe.Files.First().Action, Is.EqualTo(FileUpdateAction.Download));
        }
        public void UpdateTo_VersionWithEqualFile_SetTheActionAsCopy()
        {
            VersionManifestFile fileUpdate = new VersionManifestFile("arquivo1.txt", "123", 1000);
            VersionManifest currentManifest = new VersionManifest("1.0.0", new VersionManifestFile[] { fileUpdate });
            VersionManifest updateManifest = new VersionManifest("2.0.0", new VersionManifestFile[] { fileUpdate });

            UpdateRecipe recipe = currentManifest.UpdateTo(updateManifest);

            Assert.That(recipe.Files, Has.Count.EqualTo(1));
            Assert.That(recipe.Files.First().Action, Is.EqualTo(FileUpdateAction.Copy));
        }
        public void UpdateTo_ReturnsARecipe()
        {
            VersionManifestFile fileUpdate = new VersionManifestFile("arquivo1.txt", "123", 1000);
            VersionManifest currentManifest = new VersionManifest("1.0.0", new VersionManifestFile[] {  });
            VersionManifest updateManifest = new VersionManifest("2.0.0", new VersionManifestFile[] { fileUpdate });

            UpdateRecipe recipe = currentManifest.UpdateTo(updateManifest);

            Assert.That(recipe, Is.Not.Null);
            Assert.That(recipe.CurrentVersion, Is.EqualTo("1.0.0"));
            Assert.That(recipe.NewVersion, Is.EqualTo("2.0.0"));
            Assert.That(recipe.Files, Has.Count.EqualTo(1));
        }