public void ShouldProduceValidManifestXml()
        {
            var manifest = new PackageDefinition {MetaData = {AzureVersion = "2.6"}};
            manifest.Contents.Add(
                new ContentDefinition
                {
                    Name = "ServiceDefinition/ServiceDefinition.csdef",
                    Description = new ContentDescription
                    {
                        LengthInBytes = 688,
                        HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256,
                        Hash = "NMkHuVQbi+g+ny+kvjiunBgt8rLQT8Jd9FGJvWsRtZE=",
                        DataStorePath = new Uri("ServiceDefinition/ServiceDefinition.csdef", UriKind.Relative)
                    }
                });
            manifest.Contents.Add(
            new ContentDefinition
            {
                Name = "LocalContent/ab3574e8f52d4c939aa6ff065e8b7cfd",
                Description = new ContentDescription
                {
                    LengthInBytes = 19469,
                    HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256,
                    Hash = "UK4lyWPyRI6I8WNzlVP2dtiFZj+kjMIjyGieq5b4TiE=",
                    DataStorePath = new Uri("LocalContent/ab3574e8f52d4c939aa6ff065e8b7cfd", UriKind.Relative)
                }
            });

            var workerRoleLayout = new LayoutDefinition {Name = "Roles/WorkerRole1"};
            workerRoleLayout.FileDefinitions.Add(new FileDefinition
            {
                FilePath = "\\Cloud.uar.csman",
                Description =
                    new FileDescription
                    {
                        DataContentReference = "LocalContent/ab3574e8f52d4c939aa6ff065e8b7cfd",
                        Created = DateTime.UtcNow,
                        Modified = DateTime.UtcNow
                    }
            });
            manifest.Layouts.Add(workerRoleLayout);

            var manifestXml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            manifestXml.Add(manifest.ToXml());

            var schemaSet = new XmlSchemaSet();
            schemaSet.Add(null, XmlReader.Create(new StringReader(GetPackageManifestSchema()), XmlUtils.DtdSafeReaderSettings));
            manifestXml.Validate(schemaSet, (o, e) =>
            {
                Assert.Fail("Xml failed to validate: " + e.Message);
            });
        }
 void AddLocalContent(Package package, PackageDefinition manifest, string workingDirectory)
 {
     foreach (var roleDirectory in fileSystem.EnumerateDirectories(Path.Combine(workingDirectory, "LocalContent")))
     {
         var layout = new LayoutDefinition {Name = "Roles/" + new DirectoryInfo(roleDirectory).Name};
         manifest.Layouts.Add(layout);
         AddLocalContentParts(package, manifest, layout, roleDirectory, "");
     }
 }
        void AddLocalContentParts(Package package, PackageDefinition manifest, LayoutDefinition layout, string baseDirectory, string relativeDirectory)
        {
            var currentDirectory = Path.Combine(baseDirectory, relativeDirectory);

            foreach (var file in fileSystem.EnumerateFiles(currentDirectory))
            {
                var uniqueFileName = Guid.NewGuid().ToString("N");
                var partUri = new Uri("LocalContent/" + uniqueFileName, UriKind.Relative);
                AddContent(package, manifest, partUri, file);

                //add file definition
                var fileDate = DateTime.UtcNow; //todo: use original timestamps if un-modified
                layout.FileDefinitions.Add(
                    new FileDefinition
                    {
                        FilePath = "\\" + Path.Combine(relativeDirectory, Path.GetFileName(file)),
                        Description =
                            new FileDescription
                            {
                                DataContentReference = partUri.ToString(),
                                ReadOnly = false,
                                Created = fileDate,
                                Modified = fileDate
                            }
                    });
            }

            foreach (var subDirectory in Directory.GetDirectories(currentDirectory).Select(x => new DirectoryInfo(x)))
            {
               AddLocalContentParts(package, manifest, layout, baseDirectory, Path.Combine(relativeDirectory, subDirectory.Name));
            }
        }