public void TestPlainTextJsonConfig()
        {
            // Test for the json config, we will take the whole private config as plain text and only replace the storage account info.
            var expected = @"{
""EventHub"": {
    ""Url"": ""Url"",
    ""SharedAccessKeyName"": ""sasKeyName"",
    ""SharedAccessKey"": ""sasKey""
},
""storageAccountEndPoint"": ""https://core.windows.net"",
""storageAccountName"": ""name"",
""storageAccountKey"": ""key"",
""PlainTextItem"": {
    ""Item"":  ""Value""
}
}";

            expected = TrimEndLineSpace(expected);

            // Test json config
            var table  = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(@"Resources\Diagnostics\PlainText.json", "name", "key", "https://core.windows.net");
            var config = JsonConvert.SerializeObject(table);

            Assert.Equal(expected, config);
        }
        public void TestDiagnosticsConfigBuilderMismatchAccountNames()
        {
            string pubJsonConfigPath  = GetConfigFilePath("DiagnosticsExtensionPublicConfigWithStorageType.json");
            string privJsonConfigPath = GetConfigFilePath("DiagnosticsExtensionprivateConfigWithWrongName.json");

            var exception = Record.Exception(() => DiagnosticsHelper.GetConfigurationsFromFiles(pubJsonConfigPath, privJsonConfigPath, "a-resouce-id", null, null));

            Assert.IsType(typeof(ArgumentException), exception);


            string[] configs = new[] {
                GetConfigFilePath("DiagnosticsExtensionConfigWithWrongName.json"),
                GetConfigFilePath("DiagnosticsExtensionConfigWithWrongName.xml")
            };

            foreach (var configPath in configs)
            {
                exception = Record.Exception(() => DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(configPath, "wrong-name", "a-key", "an-endpoint"));
                Assert.IsType(typeof(ArgumentException), exception);
            }
        }
        public void TestPlainTextXmlConfig()
        {
            // Test for the xml config, we only take those elements they are recognized by the schema.
            var expected = @"{
""storageAccountKey"": ""key"",
""storageAccountName"": ""name"",
""storageAccountEndPoint"": ""https://core.windows.net"",
""EventHub"": {
    ""Url"": ""Url"",
    ""SharedAccessKeyName"": ""sasKeyName"",
    ""SharedAccessKey"": ""sasKey""
}
}";

            expected = TrimEndLineSpace(expected);

            // Test json config
            var table  = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(@"Resources\Diagnostics\PlainText.xml", "name", "key", "https://core.windows.net");
            var config = JsonConvert.SerializeObject(table);

            Assert.Equal(expected, config);
        }
        public void TestPurePublicConfig()
        {
            // Test the basic case that the storage account info can be correctly set if user only provide a pure public config file.
            var expected = @"{
""storageAccountName"": ""name"",
""storageAccountKey"": ""key"",
""storageAccountEndPoint"": ""https://core.windows.net""
}";

            expected = TrimEndLineSpace(expected);

            // Test json config
            var table  = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(@"Resources\Diagnostics\PurePublic.json", "name", "key", "https://core.windows.net");
            var config = JsonConvert.SerializeObject(table);

            Assert.Equal(expected, config);

            // Test xml config
            table  = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(@"Resources\Diagnostics\PurePublic.xml", "name", "key", "https://core.windows.net");
            config = JsonConvert.SerializeObject(table);
            Assert.Equal(expected, config);
        }
        public void TestDiagnosticsConfigBuilderWithSasToken()
        {
            string pubJsonConfigPath  = GetConfigFilePath("DiagnosticsExtensionPublicConfigWithStorageType.json");
            string privJsonConfigPath = GetConfigFilePath("DiagnosticsExtensionprivateConfigWithSasToken.json");

            string sasTokenValue = "This-is-a-sas-token";
            var    result        = DiagnosticsHelper.GetConfigurationsFromFiles(pubJsonConfigPath, privJsonConfigPath, "a-resource-id", null, null);

            Assert.Equal <string>(sasTokenValue, result.Item2["storageAccountSasToken"] as string);

            string[] configs = new[] {
                GetConfigFilePath("DiagnosticsExtensionConfigWithSasToken.json"),
                GetConfigFilePath("DiagnosticsExtensionConfigWithSasToken.xml")
            };

            foreach (var configPath in configs)
            {
                var privateSettings = DiagnosticsHelper.GetPrivateDiagnosticsConfiguration(configPath, "[StorageAccountName]", "a-key", "an-endpoint");
                Assert.Null(privateSettings["storageAccountKey"]);
                Assert.NotNull(privateSettings["storageAccountEndPoint"]);
                Assert.Equal <string>(sasTokenValue, privateSettings["storageAccountSasToken"] as string);
            }
        }