public void Importing_same_object_twice_should_not_throw(JsonConfigurationSerializer sut, ObjectWithComplexArray testSource, string rootSectionName) { _ = sut.Serialize(testSource, rootSectionName); var result = sut.Serialize(testSource, rootSectionName); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Text)}")); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Value)}")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Text)}"], Is.EqualTo($"{testSource.Items[0].Text}")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Value)}"], Is.EqualTo($"{testSource.Items[0].Value}")); }
public void Object_with_array_is_correctly_serialized(JsonConfigurationSerializer sut, ObjectWithSimpleIntArray testSource, string rootSectionName) { var result = sut.Serialize(testSource, rootSectionName); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.Values)}:0")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.Values)}:0"], Is.EqualTo($"{testSource.Values[0]}")); }
public void Object_with_array_is_correctly_serialized(JsonConfigurationSerializer sut, ObjectWithComplexArray testSource, string rootSectionName) { var result = sut.Serialize(testSource, rootSectionName); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Text)}")); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Value)}")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Text)}"], Is.EqualTo($"{testSource.Items[0].Text}")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.Items)}:0:{nameof(ObjectWithSimpleProperties.Value)}"], Is.EqualTo($"{testSource.Items[0].Value}")); }
public void Object_is_correctly_serialized(JsonConfigurationSerializer sut, ObjectWithInnerObject testSource, string rootSectionName) { var result = sut.Serialize(testSource, rootSectionName); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.InnerObject)}:{nameof(testSource.InnerObject.Text)}")); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.InnerObject)}:{nameof(testSource.InnerObject.Value)}")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.InnerObject)}:{nameof(testSource.InnerObject.Text)}"], Is.EqualTo(testSource.InnerObject.Text)); Assert.That(result[$"{rootSectionName}:{nameof(testSource.InnerObject)}:{nameof(testSource.InnerObject.Value)}"], Is.EqualTo($"{testSource.InnerObject.Value}")); }
public void Null_values_should_not_be_added(JsonConfigurationSerializer sut, ObjectWithSimpleProperties testSource, string rootSectionName) { testSource.Text = null; var result = sut.Serialize(testSource, rootSectionName); Assert.That(result, Does.Not.ContainKey($"{rootSectionName}:{nameof(testSource.Text)}")); Assert.That(result, Contains.Key($"{rootSectionName}:{nameof(testSource.Value)}")); Assert.That(result[$"{rootSectionName}:{nameof(testSource.Value)}"], Is.EqualTo($"{testSource.Value}")); }
public static string SetVersionFile( [NotNull] InstalledPackage installedPackage, [NotNull] DirectoryInfo targetDirectoryInfo, [NotNull] DeploymentExecutionDefinition deploymentExecutionDefinition, [NotNull] IEnumerable <string> xmlTransformedFiles, [NotNull] IEnumerable <string> replacedFiles, [NotNull] EnvironmentPackageResult environmentPackageResult, ILogger logger) { if (installedPackage == null) { throw new ArgumentNullException(nameof(installedPackage)); } if (targetDirectoryInfo == null) { throw new ArgumentNullException(nameof(targetDirectoryInfo)); } if (deploymentExecutionDefinition == null) { throw new ArgumentNullException(nameof(deploymentExecutionDefinition)); } if (xmlTransformedFiles == null) { throw new ArgumentNullException(nameof(xmlTransformedFiles)); } if (replacedFiles == null) { throw new ArgumentNullException(nameof(replacedFiles)); } if (environmentPackageResult == null) { throw new ArgumentNullException(nameof(environmentPackageResult)); } string applicationMetadataJsonFilePath = Path.Combine(targetDirectoryInfo.FullName, ConfigurationKeys.ApplicationMetadataFileName); var existingKeys = new List <KeyValue>(); if (File.Exists(applicationMetadataJsonFilePath)) { logger?.Debug("Appending existing metadata file {Path}", applicationMetadataJsonFilePath); string json = File.ReadAllText(applicationMetadataJsonFilePath, Encoding.UTF8); ConfigurationItems configurationItems = JsonConfigurationSerializer.Deserialize(json); if (!configurationItems.Keys.IsDefaultOrEmpty) { existingKeys.AddRange(configurationItems.Keys); } } var version = new KeyValue(ConfigurationKeys.SemVer2Normalized, installedPackage.Version.ToNormalizedString(), null); var packageId = new KeyValue(ConfigurationKeys.PackageId, installedPackage.PackageId, null); var deployStartTimeUtc = new KeyValue( ConfigurationKeys.DeployStartTimeUtc, DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture), null); var deployedFromMachine = new KeyValue( ConfigurationKeys.DeployerDeployedFromMachine, Environment.MachineName, null); var deployerAssemblyVersion = new KeyValue( ConfigurationKeys.DeployerAssemblyVersion, GetAssemblyVersion(), null); var deployerAssemblyFileVersion = new KeyValue( ConfigurationKeys.DeployerAssemblyFileVersion, GetAssemblyFileVersion(), null); var environmentConfiguration = new KeyValue( ConfigurationKeys.DeployerEnvironmentConfiguration, deploymentExecutionDefinition.EnvironmentConfig, null); var keys = new List <KeyValue>(existingKeys) { version, deployStartTimeUtc, deployerAssemblyVersion, deployerAssemblyFileVersion, packageId }.ToImmutableArray(); if (environmentPackageResult.Version != null) { keys.Add(environmentConfiguration); } string serialized = JsonConfigurationSerializer.Serialize(new ConfigurationItems("1.0", keys)); File.WriteAllText(applicationMetadataJsonFilePath, serialized, Encoding.UTF8); logger?.Debug("Metadata file update {Path}", applicationMetadataJsonFilePath); return(applicationMetadataJsonFilePath); }
protected override async Task BeforeInitialize(CancellationToken cancellationToken) { var portPoolRange = new PortPoolRange(5200, 5299); TestSiteHttpPort = TcpHelper.GetAvailablePort(portPoolRange); TestConfiguration = await new TestPathHelper().CreateTestConfigurationAsync(cancellationToken); Environment.SetEnvironmentVariable("TestDeploymentTargetPath", TestConfiguration.SiteAppRoot.FullName); Environment.SetEnvironmentVariable("TestDeploymentUri", $"http://localhost:{TestSiteHttpPort.Port}"); string deployerDir = Path.Combine(VcsTestPathHelper.GetRootDirectory(), "tools", "milou.deployer"); const string milouDeployerWebTestsIntegration = "Milou.Deployer.Web.Tests.Integration"; ImmutableArray <KeyValue> keys = new List <KeyValue> { new KeyValue(Deployer.Core.Configuration.ConfigurationKeys.NuGetSource, milouDeployerWebTestsIntegration, null), new KeyValue(ConfigurationConstants.NugetConfigFile, TestConfiguration.NugetConfigFile.FullName, null), new KeyValue(Deployer.Core.Configuration.ConfigurationKeys.NuGetConfig, TestConfiguration.NugetConfigFile.FullName, null), new KeyValue(Deployer.Core.Configuration.ConfigurationKeys.LogLevel, "Verbose", null), }.ToImmutableArray(); var jsonConfigurationSerializer = new JsonConfigurationSerializer(); string serializedConfigurationItems = jsonConfigurationSerializer.Serialize(new ConfigurationItems("1.0", keys)); string settingsFile = Path.Combine(deployerDir, $"{Environment.MachineName}.settings.json"); FilesToClean.Add(new FileInfo(settingsFile)); await File.WriteAllTextAsync(settingsFile, serializedConfigurationItems, Encoding.UTF8, cancellationToken); var integrationTestProjectDirectory = new DirectoryInfo(Path.Combine(VcsTestPathHelper.GetRootDirectory(), "src", milouDeployerWebTestsIntegration)); FileInfo[] nugetPackages = integrationTestProjectDirectory.GetFiles("*.nupkg"); if (nugetPackages.Length == 0) { throw new DeployerAppException($"Could not find nuget test packages located in {integrationTestProjectDirectory.FullName}"); } foreach (FileInfo nugetPackage in nugetPackages) { nugetPackage.CopyTo(Path.Combine(TestConfiguration.NugetPackageDirectory.FullName, nugetPackage.Name)); } Environment.SetEnvironmentVariable(Deployer.Core.Configuration.ConfigurationKeys.KeyValueConfigurationFile, settingsFile); Environment.SetEnvironmentVariable(ConfigurationConstants.NugetConfigFile, TestConfiguration.NugetConfigFile.FullName); Environment.SetEnvironmentVariable(ConfigurationConstants.NuGetPackageSourceName, milouDeployerWebTestsIntegration); Environment.SetEnvironmentVariable( $"{ConfigurationConstants.AutoDeployConfiguration}:default:StartupDelayInSeconds", "0"); Environment.SetEnvironmentVariable( $"{ConfigurationConstants.AutoDeployConfiguration}:default:afterDeployDelayInSeconds", "1"); Environment.SetEnvironmentVariable( $"{ConfigurationConstants.AutoDeployConfiguration}:default:MetadataTimeoutInSeconds", "10"); Environment.SetEnvironmentVariable( $"{ConfigurationConstants.AutoDeployConfiguration}:default:enabled", "true"); DirectoriesToClean.Add(TestConfiguration.BaseDirectory); }