public async Task TestCreateReadUpdateDeleteConfiguration()
        {
            var          now      = DateTime.UtcNow;
            const string systemId = "TestSystemId";
            const string originalPersonIdFieldName = "OriginalPersonIdFieldName";
            const string updatedPersonIdFieldName  = "UpdatedPersonIdFieldName";

            var testConfiguration = new PowerofficeConfiguration
            {
                AcceptedOrganisationStatuses = new[] { "AcceptedOrganisationStatuses1", "AcceptedOrganisationStatuses2" },
                AcceptedOrganisationTypes    = new[] { "AcceptedOrganisationTypes1", "AcceptedOrganisationTypes2" },
                DeliveryIdFieldName          = "DeliveryIdFieldName",
                Disabled = true,
                LastSuccessfulCopyFromErpHeartbeat = now,
                LastSuccessfulCopyToErpHeartbeat   = now,
                OrganisationCodeFieldName          = "OrganisationCodeFieldName",
                OrganisationIdFieldName            = "OrganisationIdFieldName",
                PersonIdFieldName               = originalPersonIdFieldName,
                PowerofficeClientKey            = new Guid("7931f515-1114-4215-940a-aa18c3b49f31"),
                PrimaryContactCheckboxFieldName = "PrimaryContactCheckboxFieldName",
                ProductCodeFieldName            = "ProductCodeFieldName",
                ProductIdFieldName              = "ProductIdFieldName",
                ProductNameFieldName            = "ProductNameFieldName",
                WebcrmApiKey   = "WebcrmApiKey",
                WebcrmSystemId = systemId
            };

            bool isValid = testConfiguration.Validate(out var results);

            foreach (var result in results)
            {
                OutputLogger.LogTrace(result.ErrorMessage);
            }

            isValid.Should().BeTrue();
            results.Should().HaveCount(0);

            await ConfigService.SavePowerofficeConfiguration(testConfiguration);

            var loadedConfiguration = ConfigService.LoadPowerofficeConfiguration(systemId);

            loadedConfiguration.Should().NotBeNull();
            loadedConfiguration.Disabled.Should().BeTrue();
            loadedConfiguration.PersonIdFieldName.Should().Be(originalPersonIdFieldName);
            loadedConfiguration.WebcrmSystemId.Should().Be(systemId);

            loadedConfiguration.PersonIdFieldName = updatedPersonIdFieldName;
            await ConfigService.SavePowerofficeConfiguration(loadedConfiguration);

            var updatedConfiguration = ConfigService.LoadPowerofficeConfiguration(systemId);

            updatedConfiguration.PersonIdFieldName.Should().Be(updatedPersonIdFieldName);

            await ConfigService.DeletePowerofficeConfiguration(updatedConfiguration);

            var deletedConfiguration = ConfigService.LoadPowerofficeConfiguration(systemId);

            deletedConfiguration.Should().BeNull();
        }
        public void TestValidatePowerofficeConfiguration()
        {
            var invalidConfigurations = new[] {
                // PersonIdFieldName is missing in the config below.
                new PowerofficeConfiguration
                {
                    AcceptedOrganisationStatuses = new[] { "status" },
                    AcceptedOrganisationTypes    = new [] { "type" },
                    DeliveryIdFieldName          = "DeliveryIdFieldName",
                    Disabled = true,
                    LastSuccessfulCopyFromErpHeartbeat = DateTime.UtcNow,
                    LastSuccessfulCopyToErpHeartbeat   = DateTime.UtcNow,
                    OrganisationCodeFieldName          = "OrganisationCodeFieldName",
                    OrganisationIdFieldName            = "OrganisationIdFieldName",
                    PowerofficeClientKey            = new Guid("7931f515-1114-4215-940a-aa18c3b49f31"),
                    PrimaryContactCheckboxFieldName = "PrimaryContactCheckboxFieldName",
                    ProductCodeFieldName            = "ProductCodeFieldName",
                    ProductIdFieldName   = "ProductIdFieldName",
                    ProductNameFieldName = "ProductNameFieldName",
                    WebcrmApiKey         = "WebcrmApiKey",
                    WebcrmSystemId       = "WebcrmSystemId"
                },
                new PowerofficeConfiguration
                {
                    AcceptedOrganisationStatuses = new[] { "", " " },
                    AcceptedOrganisationTypes    = new string[] { },
                    DeliveryIdFieldName          = "DeliveryIdFieldName",
                    Disabled = true,
                    LastSuccessfulCopyFromErpHeartbeat = DateTime.UtcNow,
                    LastSuccessfulCopyToErpHeartbeat   = DateTime.UtcNow,
                    OrganisationCodeFieldName          = "OrganisationCodeFieldName",
                    OrganisationIdFieldName            = "OrganisationIdFieldName",
                    PersonIdFieldName               = "PersonIdFieldName",
                    PowerofficeClientKey            = new Guid("7931f515-1114-4215-940a-aa18c3b49f31"),
                    PrimaryContactCheckboxFieldName = "PrimaryContactCheckboxFieldName",
                    ProductCodeFieldName            = "ProductCodeFieldName",
                    ProductIdFieldName              = "ProductIdFieldName",
                    ProductNameFieldName            = "ProductNameFieldName",
                    WebcrmApiKey   = "WebcrmApiKey",
                    WebcrmSystemId = "WebcrmSystemId"
                }
            };

            foreach (var invalidConfiguration in invalidConfigurations)
            {
                invalidConfiguration.Validate(out _).Should().BeFalse();
            }

            var validConfigurations = new[] {
                new PowerofficeConfiguration
                {
                    AcceptedOrganisationStatuses = new[] { "status" },
                    AcceptedOrganisationTypes    = new [] { "" },
                    DeliveryIdFieldName          = "DeliveryIdFieldName",
                    Disabled = true,
                    LastSuccessfulCopyFromErpHeartbeat = DateTime.UtcNow,
                    LastSuccessfulCopyToErpHeartbeat   = DateTime.UtcNow,
                    OrganisationCodeFieldName          = "OrganisationCodeFieldName",
                    OrganisationIdFieldName            = "OrganisationIdFieldName",
                    PersonIdFieldName               = "PersonIdFieldName",
                    PowerofficeClientKey            = new Guid("7931f515-1114-4215-940a-aa18c3b49f31"),
                    PrimaryContactCheckboxFieldName = "PrimaryContactCheckboxFieldName",
                    ProductCodeFieldName            = "ProductCodeFieldName",
                    ProductIdFieldName              = "ProductIdFieldName",
                    ProductNameFieldName            = "ProductNameFieldName",
                    WebcrmApiKey   = "WebcrmApiKey",
                    WebcrmSystemId = "WebcrmSystemId"
                },
                new PowerofficeConfiguration
                {
                    AcceptedOrganisationStatuses = new[] { " " },
                    AcceptedOrganisationTypes    = new [] { "type" },
                    DeliveryIdFieldName          = "DeliveryIdFieldName",
                    Disabled = true,
                    LastSuccessfulCopyFromErpHeartbeat = DateTime.UtcNow,
                    LastSuccessfulCopyToErpHeartbeat   = DateTime.UtcNow,
                    OrganisationCodeFieldName          = "OrganisationCodeFieldName",
                    OrganisationIdFieldName            = "OrganisationIdFieldName",
                    PersonIdFieldName               = "PersonIdFieldName",
                    PowerofficeClientKey            = new Guid("7931f515-1114-4215-940a-aa18c3b49f31"),
                    PrimaryContactCheckboxFieldName = "PrimaryContactCheckboxFieldName",
                    ProductCodeFieldName            = "ProductCodeFieldName",
                    ProductIdFieldName              = "ProductIdFieldName",
                    ProductNameFieldName            = "ProductNameFieldName",
                    WebcrmApiKey   = "WebcrmApiKey",
                    WebcrmSystemId = "WebcrmSystemId"
                }
            };

            foreach (var validConfiguration in validConfigurations)
            {
                bool isValid = validConfiguration.Validate(out var results);
                foreach (var result in results)
                {
                    OutputLogger.LogTrace(result.ErrorMessage);
                }

                isValid.Should().BeTrue();
            }
        }