From 53d0e7c7a5217b1957cafc343ca1e35ee6cbe214 Mon Sep 17 00:00:00 2001 From: Giuseppe Cramarossa <16326537+gcramarossa@users.noreply.github.com> Date: Sun, 29 Sep 2024 11:23:31 +0200 Subject: [PATCH] fix #30 string arguments not recognized in version 0.4.0 --- .../Program.cs | 2 -- src/InterAppConnector/Rules/DefaultRule.cs | 2 +- .../DataModels/Vehicle.cs | 1 + .../InterAppCommunicationTest.cs | 12 +++++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/samples/InterAppConnector.App.CLI.SampleApplication/Program.cs b/samples/InterAppConnector.App.CLI.SampleApplication/Program.cs index 4e19b8f..6459584 100644 --- a/samples/InterAppConnector.App.CLI.SampleApplication/Program.cs +++ b/samples/InterAppConnector.App.CLI.SampleApplication/Program.cs @@ -24,8 +24,6 @@ static void Main(string[] args) InterAppCommunication connector = new InterAppCommunication(command); connector.ExecuteAsInteractiveCLI(args); - - Console.ReadLine(); } } } \ No newline at end of file diff --git a/src/InterAppConnector/Rules/DefaultRule.cs b/src/InterAppConnector/Rules/DefaultRule.cs index 22908e9..4747710 100644 --- a/src/InterAppConnector/Rules/DefaultRule.cs +++ b/src/InterAppConnector/Rules/DefaultRule.cs @@ -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) diff --git a/tests/InterAppConnector.Test.Library/DataModels/Vehicle.cs b/tests/InterAppConnector.Test.Library/DataModels/Vehicle.cs index bee254e..08a511d 100644 --- a/tests/InterAppConnector.Test.Library/DataModels/Vehicle.cs +++ b/tests/InterAppConnector.Test.Library/DataModels/Vehicle.cs @@ -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; } = ""; } } diff --git a/tests/InterAppConnector.Test.Library/InterAppCommunicationTest.cs b/tests/InterAppConnector.Test.Library/InterAppCommunicationTest.cs index 9f7f782..4035084 100644 --- a/tests/InterAppConnector.Test.Library/InterAppCommunicationTest.cs +++ b/tests/InterAppConnector.Test.Library/InterAppCommunicationTest.cs @@ -132,6 +132,7 @@ public void ExecuteAsBatch_WithEnumAndAliasCorrectParametersAndFieldName_ReturnS dynamic parameters = new ExpandoObject(); ((IDictionary)parameters)[nameof(vehicle.Type)] = "motorcycle"; ((IDictionary)parameters)[nameof(vehicle.LicensePlate)] = "abcd1234"; + ((IDictionary)parameters)[nameof(vehicle.Manufacturer)] = "UnitTest"; InterAppCommunication connector = new InterAppCommunication(command); CommandResult commandExecution = connector.ExecuteAsBatch("testvehicle", parameters); @@ -139,6 +140,7 @@ public void ExecuteAsBatch_WithEnumAndAliasCorrectParametersAndFieldName_ReturnS 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] @@ -149,6 +151,7 @@ public void ExecuteAsBatch_WithEnumAndAliasAndCorrectParameters_ReturnSuccessful dynamic dynamic = new ExpandoObject(); dynamic.type = "motorcycle"; dynamic.licenseplate = "abcd1234"; + dynamic.manufacturer = "UnitTest"; InterAppCommunication connector = new InterAppCommunication(command); CommandResult commandExecution = connector.ExecuteAsBatch("testvehicle", dynamic); @@ -156,6 +159,7 @@ public void ExecuteAsBatch_WithEnumAndAliasAndCorrectParameters_ReturnSuccessful 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 @@ -174,7 +178,7 @@ public void ExecuteAsBatch_WithEnumAndAliasAndWrongParameters_ReturnFailureObjec }; Assert.That(connectorAction, Throws.InstanceOf() - .And.Property("MissingParameters").Count.EqualTo(1)); + .And.Property("MissingParameters").Count.EqualTo(2)); } [Test] @@ -311,7 +315,7 @@ public void ExecuteAsInteractiveCLI_WithEnumAndAliasAndCorrectParameters_ReturnS { CommandManager command = new CommandManager(); command.AddCommand(); - string[] arguments = { "testvehicle", "-type", "motorcycle", "-licenseplate", "abcd1234" }; + string[] arguments = { "testvehicle", "-type", "motorcycle", "-licenseplate", "abcd1234", "-manufacturer", "UnitTest" }; Action connectorAction = () => { @@ -544,6 +548,7 @@ public void CallSingleCommand_WithTestCommandConfiguredProperly_ReturnSuccessMes dynamic dynamic = new ExpandoObject(); dynamic.type = "motorcycle"; dynamic.licenseplate = "abcd1234"; + dynamic.manufacturer = "UnitTest"; InterAppCommunication connector = InterAppCommunication.CallSingleCommand(); CommandResult commandExecution = connector.ExecuteAsBatch("testvehicle", dynamic); @@ -551,6 +556,7 @@ public void CallSingleCommand_WithTestCommandConfiguredProperly_ReturnSuccessMes 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] @@ -583,7 +589,7 @@ public void CallSingleCommand_WithEnumAndAliasAndWrongParameters_ReturnFailureOb }; Assert.That(connectorAction, Throws.InstanceOf() - .And.Property("MissingParameters").Count.EqualTo(1)); + .And.Property("MissingParameters").Count.EqualTo(2)); } [Test]