Exemplo n.º 1
0
        public void TestExtractingMetadata()
        {
            var f = File.Open(TestManifestPath, FileMode.Open);

            IRegistrationOwnership registrationOwnership = new MockIRegistrationOwnership();
            PowerShellPublishImpl  pub = new PowerShellPublishImpl(registrationOwnership);

            PrivateObject pubPrivateObject = new PrivateObject(pub);
            var           result           = pubPrivateObject.Invoke("CreateMetadataObject", "", (Stream)f) as JObject;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, (result.GetValue("authors") as JArray)?.Count);
            Assert.AreEqual("Darek", result.GetValue("authors")[0].Value <string>());
            Assert.AreEqual("1.0", result.GetValue("ModuleVersion"));
            Assert.AreEqual("Microsoft", result.GetValue("CompanyName"));
            Assert.AreEqual("e4da48d8-20df-4d58-bfa6-2e54486fca5b", result.GetValue("GUID"));
            Assert.AreEqual(null, result.GetValue("PowerShellHostVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("DotNetFrameworkVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("CLRVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("ProcessorArchitecture").Value <string>());
            Assert.AreEqual(2, (result.GetValue("CmdletsToExport") as JArray)?.Count);
            Assert.AreEqual("Get-Test", result.GetValue("CmdletsToExport")[0].Value <string>());
            Assert.AreEqual("Set-Test", result.GetValue("CmdletsToExport")[1].Value <string>());
            Assert.AreEqual(1, (result.GetValue("FunctionsToExport") as JArray)?.Count);
            Assert.AreEqual("*", result.GetValue("FunctionsToExport")[0].Value <string>());
            Assert.AreEqual(0, (result.GetValue("DscResourcesToExport") as JArray)?.Count);
            Assert.AreEqual("http://this.is.test.license.com", result.GetValue("licenseUrl"));
            Assert.AreEqual(null, result.GetValue("iconUrl").Value <string>());
            Assert.AreEqual(1, (result.GetValue("tags") as JArray)?.Count);
            Assert.AreEqual("tag1", result.GetValue("tags")[0].Value <string>());
            Assert.AreEqual("http://github.com/TestModule", result.GetValue("projectUrl"));
            Assert.AreEqual("This is our best release so far.", result.GetValue("releaseNotes"));
        }
Exemplo n.º 2
0
        public void TestExtractingMetadataEmptyFile()
        {
            var f = File.Open(TestEmptyManifestPath, FileMode.Open);

            IRegistrationOwnership registrationOwnership = new MockIRegistrationOwnership();
            PowerShellPublishImpl  pub = new PowerShellPublishImpl(registrationOwnership);

            PrivateObject pubPrivateObject = new PrivateObject(pub);
            var           result           = pubPrivateObject.Invoke("CreateMetadataObject", "", (Stream)f) as JObject;

            Assert.IsNotNull(result);
            Assert.AreEqual(0, (result.GetValue("authors") as JArray)?.Count);
            Assert.AreEqual(null, result.GetValue("ModuleVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("CompanyName").Value <string>());
            Assert.AreEqual(null, result.GetValue("GUID").Value <string>());
            Assert.AreEqual(null, result.GetValue("PowerShellHostVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("DotNetFrameworkVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("CLRVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("ProcessorArchitecture").Value <string>());
            Assert.AreEqual(0, (result.GetValue("CmdletsToExport") as JArray)?.Count);
            Assert.AreEqual(0, (result.GetValue("FunctionsToExport") as JArray)?.Count);
            Assert.AreEqual(0, (result.GetValue("DscResourcesToExport") as JArray)?.Count);
            Assert.AreEqual(null, result.GetValue("licenseUrl").Value <string>());
            Assert.AreEqual(null, result.GetValue("iconUrl").Value <string>());
            Assert.AreEqual(0, (result.GetValue("tags") as JArray)?.Count);
            Assert.AreEqual(null, result.GetValue("projectUrl").Value <string>());
            Assert.AreEqual(null, result.GetValue("releaseNotes").Value <string>());
        }
Exemplo n.º 3
0
        public void TestIsMetadataFile()
        {
            IRegistrationOwnership registrationOwnership = new MockIRegistrationOwnership();
            PowerShellPublishImpl  pub = new PowerShellPublishImpl(registrationOwnership);

            PrivateObject pubPrivateObject = new PrivateObject(pub);

            Assert.AreEqual(true, pubPrivateObject.Invoke("IsMetadataFile", "test.psd1") as bool?);
            Assert.AreEqual(false, pubPrivateObject.Invoke("IsMetadataFile", "test.psm1") as bool?);
            Assert.AreEqual(false, pubPrivateObject.Invoke("IsMetadataFile", "subdir/test.psd1") as bool?);
        }
Exemplo n.º 4
0
        public void TestMissingRequiredFieldsMetadata()
        {
            var f = File.Open(TestMissingRequiredFieldsPath, FileMode.Open);

            IRegistrationOwnership registrationOwnership = new MockIRegistrationOwnership();
            PowerShellPublishImpl  pub = new PowerShellPublishImpl(registrationOwnership);

            PrivateObject pubPrivateObject = new PrivateObject(pub);

            pubPrivateObject.Invoke("IsMetadataFile", TestMissingRequiredFieldsPath);

            var result = pubPrivateObject.Invoke("CreateMetadataObject", "", (Stream)f) as JObject;

            Assert.IsNotNull(result);
            Assert.AreEqual("Microsoft", result.GetValue("CompanyName"));
            Assert.AreEqual(null, result.GetValue("PowerShellHostVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("DotNetFrameworkVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("CLRVersion").Value <string>());
            Assert.AreEqual(null, result.GetValue("ProcessorArchitecture").Value <string>());
            Assert.AreEqual(2, (result.GetValue("CmdletsToExport") as JArray)?.Count);
            Assert.AreEqual("Get-Test", result.GetValue("CmdletsToExport")[0].Value <string>());
            Assert.AreEqual("Set-Test", result.GetValue("CmdletsToExport")[1].Value <string>());
            Assert.AreEqual(1, (result.GetValue("FunctionsToExport") as JArray)?.Count);
            Assert.AreEqual("*", result.GetValue("FunctionsToExport")[0].Value <string>());
            Assert.AreEqual(0, (result.GetValue("DscResourcesToExport") as JArray)?.Count);
            Assert.AreEqual("http://this.is.test.license.com", result.GetValue("licenseUrl"));
            Assert.AreEqual(null, result.GetValue("iconUrl").Value <string>());
            Assert.AreEqual(1, (result.GetValue("tags") as JArray)?.Count);
            Assert.AreEqual("tag1", result.GetValue("tags")[0].Value <string>());
            Assert.AreEqual("http://github.com/TestModule", result.GetValue("projectUrl"));
            Assert.AreEqual("This is our best release so far.", result.GetValue("releaseNotes"));

            var validationMessage = pubPrivateObject.Invoke("Validate", new object[1] {
                null
            }) as List <string>;

            Assert.IsNotNull(validationMessage);
            Assert.AreEqual(1, validationMessage.Count);
            Assert.IsTrue(validationMessage[0].Contains("Author"));
            Assert.IsTrue(validationMessage[0].Contains("ModuleVersion"));
            Assert.IsTrue(validationMessage[0].Contains("GUID"));
        }
Exemplo n.º 5
0
        public void TestCorruptedMetadata()
        {
            var f = File.Open(TestCorruptedManifestPath, FileMode.Open);

            IRegistrationOwnership registrationOwnership = new MockIRegistrationOwnership();
            PowerShellPublishImpl  pub = new PowerShellPublishImpl(registrationOwnership);

            PrivateObject pubPrivateObject = new PrivateObject(pub);

            pubPrivateObject.Invoke("IsMetadataFile", TestCorruptedManifestPath);

            pubPrivateObject.Invoke("CreateMetadataObject", "", (Stream)f);

            var result = pubPrivateObject.Invoke("Validate", new object[1] {
                null
            }) as List <string>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Unexpected element encountered.", result[0]);
        }