Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,38 @@ public void VerifyThatPropertiesAreSet()
Assert.AreEqual(0, viewmodel.Component.Count);
}

[Test]
public void VerifyThatNewComponentHasValidDefaultShortName()
{
var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);
var transaction = new ThingTransaction(transactionContext);
var viewmodel = new ArrayParameterTypeDialogViewModel(this.arrayPt, transaction, this.session.Object, true, ThingDialogKind.Create, null);

var component = (ParameterTypeComponentRowViewModel)viewmodel.Component.Single();

Assert.AreEqual("{1;1;1}", component.Coordinates);
Assert.AreEqual("C1_1_1", component.ShortName);

// a default short name must not raise a short-name validation error
Assert.IsEmpty(component["ShortName"]);
}

[Test]
public void VerifyThatMissingParameterTypeIsReportedAsError()
{
var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);
var transaction = new ThingTransaction(transactionContext);
var viewmodel = new ArrayParameterTypeDialogViewModel(this.arrayPt, transaction, this.session.Object, true, ThingDialogKind.Create, null);

var component = (ParameterTypeComponentRowViewModel)viewmodel.Component.Single();

Assert.IsNull(component.ParameterType);
Assert.IsNotEmpty(component["ParameterType"]);

component.ParameterType = this.qt;
Assert.IsEmpty(component["ParameterType"]);
}

[Test]
public void VerifyThatParameterlessContructorExists()
{
Expand Down
15 changes: 14 additions & 1 deletion BasicRdl/ViewModels/Dialogs/ArrayParameterTypeDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected override void PopulateComponent()
// create new ParameterTypeComponent
var component = new ParameterTypeComponent();
row = new ParameterTypeComponentRowViewModel(component, this.Session, this);
row.ShortName = coordinates;
row.ShortName = ComputeComponentShortName(coordinates);
}

row.Coordinates = coordinates;
Expand Down Expand Up @@ -296,6 +296,19 @@ private string ComputeComponentCoordinates(int n)
return "{" + string.Join(";", indexList.Select(x => x.ToString(CultureInfo.InvariantCulture))) + "}";
}

/// <summary>
/// Compute a valid default <see cref="ParameterTypeComponent.ShortName"/> from a component's coordinates
/// </summary>
/// <param name="coordinates">The coordinates of the component, e.g. <c>{1;1;1}</c></param>
/// <returns>
/// A short name that complies with the short-name validation rules (starts with a letter, only contains
/// alphanumeric characters or underscores), e.g. <c>C1_1_1</c>
/// </returns>
private static string ComputeComponentShortName(string coordinates)
{
return "C" + coordinates.Trim('{', '}').Replace(";", "_");
}

/// <summary>
/// Compute the denominators used to compute the coordinates of the components on an axis
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,20 @@ public override string this[string columnName]
{
get
{
var shortNameError = this.ValidationService.ValidateObjectProperty("ShortName", this);
var parameterTypeError = this.ParameterType == null ? "The ParameterType must be selected." : null;

this.ErrorMsg = shortNameError ?? parameterTypeError;
((CompoundParameterTypeDialogViewModel)this.ContainerViewModel).UpdateOkCanExecuteStatus();

if (columnName == "ShortName")
{
var validationResult = this.ValidationService.ValidateObjectProperty(columnName, this);
this.ErrorMsg = validationResult;
((CompoundParameterTypeDialogViewModel)this.ContainerViewModel).UpdateOkCanExecuteStatus();
return validationResult != null ? validationResult : string.Empty;
return shortNameError ?? string.Empty;
}

if (columnName == "ParameterType")
{
return parameterTypeError ?? string.Empty;
}

return string.Empty;
Expand Down
Loading