using System.Diagnostics.CodeAnalysis; using System.Text.Json.Nodes; using CentronNexus.Configuration.Migrations; namespace CentronNexusTests.Configuration.Migrations; public class MultiWebServiceToSingleWebServiceConfigMigrationTests { private readonly MultiWebServiceToSingleWebServiceConfigMigration202308181135 _migration = new(); [Fact] public void Success() { var input = new JsonObject { ["CentronWebService"] = new JsonObject { ["WebServices"] = new JsonArray { new JsonObject { ["IsDefault"] = false, ["Url"] = "https://1.de" }, new JsonObject { ["IsDefault"] = true, ["Url"] = "https://2.de" // This one should be taken as the Url }, } } }; this.Test(true, input); Assert.Equal("https://2.de", (string?)input["CentronWebService"]?["Url"]); // The default web-service should be in CentronWebService->Url now Assert.Null(input["CentronWebService"]?["WebServices"]); // The CentronWebService->WebServices array should be removed } [Fact] public void Failure_CentronWebService_NotFound() { var input = new JsonObject { ["Something"] = 12 // No CentronWebService here, do nothing }; this.Test(false, input); } [Fact] public void Failure_WebServices_NotFound() { var input = new JsonObject { ["CentronWebService"] = new JsonObject { ["Something"] = 12 // NoWebServices here, do nothing } }; this.Test(false, input); } [Fact] public void Failure_Url_AlreadyExists() { var input = new JsonObject { ["CentronWebService"] = new JsonObject { ["Url"] = "https://google.de", // Url already exists, do nothing ["WebServices"] = new JsonArray { new JsonObject { ["IsDefault"] = false, ["Url"] = "https://1.de" }, new JsonObject { ["IsDefault"] = true, ["Url"] = "https://2.de" }, } } }; this.Test(false, input); } private void Test(bool expectedResult, JsonNode input) { var result = this._migration.TryApplyTo(input); Assert.Equal(expectedResult, result); } }