Skip to content

Commit

Permalink
fix #30 string arguments not recognized in version 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gcramarossa committed Sep 29, 2024
1 parent e66ae56 commit 53d0e7c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ static void Main(string[] args)

InterAppCommunication connector = new InterAppCommunication(command);
connector.ExecuteAsInteractiveCLI(args);

Console.ReadLine();
}
}
}
2 changes: 1 addition & 1 deletion src/InterAppConnector/Rules/DefaultRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public bool IsRuleEnabledInArgumentSetting(PropertyInfo property)
}
bool isEnumType = parameterType.IsEnum;
bool isValueTypeAndIsNotAStruct = parameterType.IsValueType && !StructHelper.IsStruct(parameterType);
return isEnumType || isValueTypeAndIsNotAStruct;
return isEnumType || isValueTypeAndIsNotAStruct || property.PropertyType == typeof(string);
}

public bool IsRuleEnabledInArgumentSetting(FieldInfo field)
Expand Down
1 change: 1 addition & 0 deletions tests/InterAppConnector.Test.Library/DataModels/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class Vehicle
// This format is used for example in Germany
[CustomInputString("llllnnnn")]
public LicensePlate LicensePlate { get; set; } = new LicensePlate("aaaa0000");
public string Manufacturer { get; set; } = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ public void ExecuteAsBatch_WithEnumAndAliasCorrectParametersAndFieldName_ReturnS
dynamic parameters = new ExpandoObject();
((IDictionary<string, object>)parameters)[nameof(vehicle.Type)] = "motorcycle";
((IDictionary<string, object>)parameters)[nameof(vehicle.LicensePlate)] = "abcd1234";
((IDictionary<string, object>)parameters)[nameof(vehicle.Manufacturer)] = "UnitTest";

InterAppCommunication connector = new InterAppCommunication(command);
CommandResult<Vehicle> commandExecution = connector.ExecuteAsBatch<Vehicle>("testvehicle", parameters);

Assert.That(commandExecution.MessageStatus, Is.EqualTo(CommandExecutionMessageType.Success));
Assert.That(commandExecution.Message.Type, Is.EqualTo(VehicleType.Motorbike));
Assert.That(commandExecution.Message.LicensePlate.Plate, Is.EqualTo("abcd1234"));
Assert.That(commandExecution.Message.Manufacturer, Is.EqualTo("UnitTest"));
}

[Test]
Expand All @@ -149,13 +151,15 @@ public void ExecuteAsBatch_WithEnumAndAliasAndCorrectParameters_ReturnSuccessful
dynamic dynamic = new ExpandoObject();
dynamic.type = "motorcycle";
dynamic.licenseplate = "abcd1234";
dynamic.manufacturer = "UnitTest";

InterAppCommunication connector = new InterAppCommunication(command);
CommandResult<Vehicle> commandExecution = connector.ExecuteAsBatch<Vehicle>("testvehicle", dynamic);

Assert.That(commandExecution.MessageStatus, Is.EqualTo(CommandExecutionMessageType.Success));
Assert.That(commandExecution.Message.Type, Is.EqualTo(VehicleType.Motorbike));
Assert.That(commandExecution.Message.LicensePlate.Plate, Is.EqualTo("abcd1234"));
Assert.That(commandExecution.Message.Manufacturer, Is.EqualTo("UnitTest"));
}

/// llllnnnn
Expand All @@ -174,7 +178,7 @@ public void ExecuteAsBatch_WithEnumAndAliasAndWrongParameters_ReturnFailureObjec
};

Assert.That(connectorAction, Throws.InstanceOf<MissingMandatoryArgumentException>()
.And.Property("MissingParameters").Count.EqualTo(1));
.And.Property("MissingParameters").Count.EqualTo(2));
}

[Test]
Expand Down Expand Up @@ -311,7 +315,7 @@ public void ExecuteAsInteractiveCLI_WithEnumAndAliasAndCorrectParameters_ReturnS
{
CommandManager command = new CommandManager();
command.AddCommand<VehicleTestCommand, Vehicle>();
string[] arguments = { "testvehicle", "-type", "motorcycle", "-licenseplate", "abcd1234" };
string[] arguments = { "testvehicle", "-type", "motorcycle", "-licenseplate", "abcd1234", "-manufacturer", "UnitTest" };

Action connectorAction = () =>
{
Expand Down Expand Up @@ -544,13 +548,15 @@ public void CallSingleCommand_WithTestCommandConfiguredProperly_ReturnSuccessMes
dynamic dynamic = new ExpandoObject();
dynamic.type = "motorcycle";
dynamic.licenseplate = "abcd1234";
dynamic.manufacturer = "UnitTest";

InterAppCommunication connector = InterAppCommunication.CallSingleCommand<VehicleTestCommand, Vehicle>();
CommandResult<Vehicle> commandExecution = connector.ExecuteAsBatch<Vehicle>("testvehicle", dynamic);

Assert.That(commandExecution.MessageStatus, Is.EqualTo(CommandExecutionMessageType.Success));
Assert.That(commandExecution.Message.Type, Is.EqualTo(VehicleType.Motorbike));
Assert.That(commandExecution.Message.LicensePlate.Plate, Is.EqualTo("abcd1234"));
Assert.That(commandExecution.Message.Manufacturer, Is.EqualTo("UnitTest"));
}

[Test]
Expand Down Expand Up @@ -583,7 +589,7 @@ public void CallSingleCommand_WithEnumAndAliasAndWrongParameters_ReturnFailureOb
};

Assert.That(connectorAction, Throws.InstanceOf<MissingMandatoryArgumentException>()
.And.Property("MissingParameters").Count.EqualTo(1));
.And.Property("MissingParameters").Count.EqualTo(2));
}

[Test]
Expand Down

0 comments on commit 53d0e7c

Please sign in to comment.