Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions src/ServiceControl.Config.Tests/ServiceControlAddScreenLoadedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,142 @@ public void Transports_are_populated()
}
}

[Test]
public void Storage_types_are_offered_with_no_default_selection()
{
var viewModel = new ServiceControlAddViewModel();

using (Assert.EnterMultipleScope())
{
Assert.That(viewModel.ErrorStorageTypes.Select(m => m.Name), Is.EquivalentTo(new[] { "PostgreSQL", "RavenDB", "SQLServer" }));
Assert.That(viewModel.ErrorSelectedStorageType, Is.Null);
Assert.That(viewModel.ShowErrorStorageTypePicker, Is.True);
Assert.That(viewModel.ShowErrorStorageConnectionString, Is.False);

Assert.That(viewModel.AuditStorageTypes.Select(m => m.Name), Is.EquivalentTo(new[] { "PostgreSQL", "RavenDB", "SQLServer" }));
Assert.That(viewModel.AuditSelectedStorageType, Is.Null);
Assert.That(viewModel.ShowAuditStorageTypePicker, Is.True);
Assert.That(viewModel.ShowAuditStorageConnectionString, Is.False);
}
}

[Test]
public void Changing_storage_type_notifies_bound_visibility_properties()
{
var viewModel = new ServiceControlAddViewModel();
var raisedPropertyNames = new System.Collections.Generic.HashSet<string>();
viewModel.PropertyChanged += (_, e) => raisedPropertyNames.Add(e.PropertyName);

viewModel.ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence("SQLServer");

using (Assert.EnterMultipleScope())
{
// These are what the XAML's Visibility bindings actually listen to - if WPF never
// hears these changed, the connection string box silently never appears/disappears,
// even though the underlying ErrorSelectedStorageType value is correct.
Assert.That(raisedPropertyNames, Does.Contain(nameof(viewModel.ShowErrorStorageConnectionString)));
Assert.That(raisedPropertyNames, Does.Contain(nameof(viewModel.ShowErrorDatabasePathFields)));
Assert.That(viewModel.ShowErrorStorageConnectionString, Is.True);
}
}

[TestCase("RavenDB", true)]
[TestCase("SQLServer", false)]
[TestCase("PostgreSQL", false)]
public void Database_maintenance_port_is_shown_only_for_RavenDB(string storageTypeName, bool expected)
{
var viewModel = new ServiceControlAddViewModel
{
ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence(storageTypeName),
AuditSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetAuditPersistence(storageTypeName)
};

using (Assert.EnterMultipleScope())
{
Assert.That(viewModel.ShowErrorDatabaseMaintenancePort, Is.EqualTo(expected));
Assert.That(viewModel.ShowAuditDatabaseMaintenancePort, Is.EqualTo(expected));
}
}

[Test]
public void Message_body_storage_is_shown_only_for_storage_types_that_support_it()
{
var viewModel = new ServiceControlAddViewModel();

viewModel.ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence("RavenDB");
Assert.That(viewModel.ShowErrorMessageBodyStorage, Is.False);

viewModel.ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence("SQLServer");

using (Assert.EnterMultipleScope())
{
Assert.That(viewModel.ShowErrorMessageBodyStorage, Is.True);
Assert.That(viewModel.ErrorSelectedMessageBodyStorageType.Value, Is.EqualTo(ServiceControlInstaller.Engine.Instances.MessageBodyStorageType.FileSystem));
Assert.That(viewModel.ShowErrorMessageBodyPath, Is.True);
Assert.That(viewModel.ErrorMessageBodyPath, Does.StartWith(programDataPath).And.EndWith("MessageBodies"));
}
}

[Test]
public void Changing_message_body_storage_type_notifies_bound_visibility_properties()
{
var viewModel = new ServiceControlAddViewModel
{
ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence("SQLServer")
};
var raisedPropertyNames = new System.Collections.Generic.HashSet<string>();
viewModel.PropertyChanged += (_, e) => raisedPropertyNames.Add(e.PropertyName);

viewModel.ErrorSelectedMessageBodyStorageType = viewModel.ErrorMessageBodyStorageTypes.Single(o => o.Value == ServiceControlInstaller.Engine.Instances.MessageBodyStorageType.AzureBlob);
viewModel.ErrorSelectedAzureAuthentication = viewModel.ErrorAzureAuthenticationOptions.Single(o => o.UsesManagedIdentity);

using (Assert.EnterMultipleScope())
{
Assert.That(raisedPropertyNames, Does.Contain(nameof(viewModel.ShowErrorMessageBodyPath)));
Assert.That(raisedPropertyNames, Does.Contain(nameof(viewModel.ShowErrorAzureBlobFields)));
Assert.That(raisedPropertyNames, Does.Contain(nameof(viewModel.ShowErrorAzureManagedIdentity)));
Assert.That(raisedPropertyNames, Does.Contain(nameof(viewModel.ShowErrorAzureConnectionString)));
Assert.That(viewModel.ShowErrorMessageBodyPath, Is.False);
Assert.That(viewModel.ShowErrorAzureManagedIdentity, Is.True);
Assert.That(viewModel.ShowErrorAzureConnectionString, Is.False);
}
}

[Test]
public void Message_body_storage_only_includes_values_for_the_selected_options()
{
var viewModel = new ServiceControlAddViewModel
{
ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence("SQLServer"),
ErrorAzureConnectionString = "UseDevelopmentStorage=true",
ErrorAzureServiceUri = "https://account.blob.core.windows.net",
ErrorS3BucketName = "bodies"
};
viewModel.ErrorSelectedMessageBodyStorageType = viewModel.ErrorMessageBodyStorageTypes.Single(o => o.Value == ServiceControlInstaller.Engine.Instances.MessageBodyStorageType.AzureBlob);
viewModel.ErrorSelectedAzureAuthentication = viewModel.ErrorAzureAuthenticationOptions.Single(o => o.UsesManagedIdentity);

var storage = viewModel.ServiceControl.CreateMessageBodyStorage();

using (Assert.EnterMultipleScope())
{
Assert.That(storage.StorageType, Is.EqualTo(ServiceControlInstaller.Engine.Instances.MessageBodyStorageType.AzureBlob));
Assert.That(storage.AzureServiceUri, Is.EqualTo("https://account.blob.core.windows.net"));
Assert.That(storage.AzureConnectionString, Is.Null, "The connection string belongs to the authentication option that is not selected");
Assert.That(storage.S3BucketName, Is.Null);
}
}

[Test]
public void Message_body_storage_is_not_created_for_RavenDB()
{
var viewModel = new ServiceControlAddViewModel
{
ErrorSelectedStorageType = ServiceControlInstaller.Engine.Instances.ServiceControlPersisters.GetPrimaryPersistence("RavenDB")
};

Assert.That(viewModel.ServiceControl.CreateMessageBodyStorage(), Is.Null);
}

[Test]
public void Transport_connection_string_is_null()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,63 @@ public void

#endregion

#region storagetype

[Test]
public void Storage_type_cannot_be_empty_when_adding_audit_instance()
{
var viewModel = new ServiceControlAddViewModel
{
InstallAuditInstance = true,
SubmitAttempted = true,
AuditSelectedStorageType = null
};

viewModel.NotifyOfPropertyChange(nameof(viewModel.AuditSelectedStorageType));

var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditSelectedStorageType));

Assert.That(errors, Is.Not.Empty);
}

[TestCase("SQLServer")]
[TestCase("PostgreSQL")]
public void Storage_connection_string_cannot_be_empty_for_storage_types_that_require_one_when_adding_audit_instance(string storageTypeName)
{
var viewModel = new ServiceControlAddViewModel
{
InstallAuditInstance = true,
AuditSelectedStorageType = ServiceControlPersisters.GetAuditPersistence(storageTypeName),
SubmitAttempted = true,
AuditStorageConnectionString = string.Empty
};

var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditStorageConnectionString));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void Storage_connection_string_can_be_empty_for_RavenDB_when_adding_audit_instance()
{
var viewModel = new ServiceControlAddViewModel
{
InstallAuditInstance = true,
AuditSelectedStorageType = ServiceControlPersisters.GetAuditPersistence("RavenDB"),
SubmitAttempted = true,
AuditStorageConnectionString = string.Empty
};

var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.AuditStorageConnectionString));

Assert.That(errors, Is.Empty);
}

#endregion

#region auditinstancename

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,148 @@ public void Transport_connection_string_cannot_be_null_if_sample_connection_stri
}
#endregion

#region storagetype

[Test]
public void Storage_type_cannot_be_empty_when_adding_error_instance()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
SubmitAttempted = true,
ErrorSelectedStorageType = null
};

viewModel.NotifyOfPropertyChange(nameof(viewModel.ErrorSelectedStorageType));

var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ErrorSelectedStorageType));

Assert.That(errors, Is.Not.Empty);
}

[TestCase("SQLServer")]
[TestCase("PostgreSQL")]
public void Storage_connection_string_cannot_be_empty_for_storage_types_that_require_one_when_adding_error_instance(string storageTypeName)
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence(storageTypeName),
SubmitAttempted = true,
ErrorStorageConnectionString = string.Empty
};

var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ErrorStorageConnectionString));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void Message_body_path_cannot_be_empty_for_file_system_storage()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence("SQLServer"),
SubmitAttempted = true
};
viewModel.ErrorMessageBodyPath = string.Empty;

var errors = GetNotifyErrorInfo(viewModel).GetErrors(nameof(viewModel.ErrorMessageBodyPath));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void Azure_service_uri_must_be_absolute()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence("SQLServer")
};
viewModel.ErrorSelectedMessageBodyStorageType = viewModel.ErrorMessageBodyStorageTypes.Single(o => o.Value == MessageBodyStorageType.AzureBlob);
viewModel.ErrorSelectedAzureAuthentication = viewModel.ErrorAzureAuthenticationOptions.Single(o => o.UsesManagedIdentity);
viewModel.ErrorAzureServiceUri = "account.blob.core.windows.net";

var errors = GetNotifyErrorInfo(viewModel).GetErrors(nameof(viewModel.ErrorAzureServiceUri));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void Azure_connection_string_is_required_when_selected()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence("SQLServer"),
SubmitAttempted = true
};
viewModel.ErrorSelectedMessageBodyStorageType = viewModel.ErrorMessageBodyStorageTypes.Single(o => o.Value == MessageBodyStorageType.AzureBlob);
viewModel.ErrorAzureConnectionString = string.Empty;

var errors = GetNotifyErrorInfo(viewModel).GetErrors(nameof(viewModel.ErrorAzureConnectionString));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void S3_bucket_is_required()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence("SQLServer"),
SubmitAttempted = true
};
viewModel.ErrorSelectedMessageBodyStorageType = viewModel.ErrorMessageBodyStorageTypes.Single(o => o.Value == MessageBodyStorageType.S3);
viewModel.ErrorS3BucketName = string.Empty;

var errors = GetNotifyErrorInfo(viewModel).GetErrors(nameof(viewModel.ErrorS3BucketName));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void S3_secret_access_key_is_required_with_an_access_key_id()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence("SQLServer"),
SubmitAttempted = true
};
viewModel.ErrorSelectedMessageBodyStorageType = viewModel.ErrorMessageBodyStorageTypes.Single(o => o.Value == MessageBodyStorageType.S3);
viewModel.ErrorS3AccessKeyId = "key";
viewModel.ErrorS3SecretAccessKey = string.Empty;

var errors = GetNotifyErrorInfo(viewModel).GetErrors(nameof(viewModel.ErrorS3SecretAccessKey));

Assert.That(errors, Is.Not.Empty);
}

[Test]
public void Storage_connection_string_can_be_empty_for_RavenDB_when_adding_error_instance()
{
var viewModel = new ServiceControlAddViewModel
{
InstallErrorInstance = true,
ErrorSelectedStorageType = ServiceControlPersisters.GetPrimaryPersistence("RavenDB"),
SubmitAttempted = true,
ErrorStorageConnectionString = string.Empty
};

var notifyErrorInfo = GetNotifyErrorInfo(viewModel);
var errors = notifyErrorInfo.GetErrors(nameof(viewModel.ErrorStorageConnectionString));

Assert.That(errors, Is.Empty);
}

#endregion

#region errorinstancename

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ public void Transport_connection_string_can_be_null_if_sample_connection_string_

#region hostname

[TestCase("SQLServer", false)]
[TestCase("PostgreSQL", false)]
[TestCase("RavenDB", true)]
public void Database_maintenance_port_is_required_only_for_RavenDB_when_editing_audit_instance(string storageTypeName, bool required)
{
var viewModel = new ServiceControlAuditEditViewModel
{
PersistenceManifest = ServiceControlPersisters.GetAuditPersistence(storageTypeName),
SubmitAttempted = true,
DatabaseMaintenancePortNumber = null
};

viewModel.NotifyOfPropertyChange(nameof(viewModel.DatabaseMaintenancePortNumber));

var errors = GetNotifyErrorInfo(viewModel).GetErrors(nameof(viewModel.DatabaseMaintenancePortNumber));

using (Assert.EnterMultipleScope())
{
Assert.That(viewModel.DatabaseMaintenancePortNumberRequired, Is.EqualTo(required));
Assert.That(errors, required ? Is.Not.Empty : Is.Empty);
}
}

[Test]
public void Audit_hostname_can_not_be_empty_when_editing_audit_instance()
{
Expand Down
Loading
Loading