From dea5d5419b82d74882febb5713a18ca2bb17b6e7 Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sun, 9 Jun 2024 18:21:32 +0200 Subject: [PATCH] more test fixes --- .../Test/AssemblyGenerator.cs | 9 +++++++ .../Test/InheritanceCodeGenTests.cs | 26 +++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/OpenRiaServices.Tools/Test/AssemblyGenerator.cs b/src/OpenRiaServices.Tools/Test/AssemblyGenerator.cs index 3da9aa0cf..50c99158a 100644 --- a/src/OpenRiaServices.Tools/Test/AssemblyGenerator.cs +++ b/src/OpenRiaServices.Tools/Test/AssemblyGenerator.cs @@ -7,6 +7,8 @@ using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.CodeAnalysis.Text; +using System.Collections.ObjectModel; +using System.Collections; namespace OpenRiaServices.Tools.Test { @@ -316,6 +318,13 @@ internal static bool TryGetCustomAttributeValue(CustomAttributeData attribute value = (T)ctorArg.Value; return true; } + // Special case to handle backwards compat for tests written againt AssociationAttribute + // that takes string arguments in constructor insterad of Arrrays as EntityAssociationAttribute does + else if (typeof(T) == typeof(string) && ctorArg.ArgumentType.IsArray) + { + value = (T)(object)string.Join(", ", ((IEnumerable)ctorArg.Value).Select(arg => arg.Value?.ToString() ?? "null")); + return true; + } } } diff --git a/src/OpenRiaServices.Tools/Test/InheritanceCodeGenTests.cs b/src/OpenRiaServices.Tools/Test/InheritanceCodeGenTests.cs index b81518391..23608a610 100644 --- a/src/OpenRiaServices.Tools/Test/InheritanceCodeGenTests.cs +++ b/src/OpenRiaServices.Tools/Test/InheritanceCodeGenTests.cs @@ -290,7 +290,7 @@ public void Inherit_Gen_Assoc_Uni_Derived_To_Included_Root() Assert.IsNotNull(pInfo, "Expected 'Target' property on derived type"); Assert.AreEqual(otherType, pInfo.PropertyType, "'Target' property should have been of type " + otherType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Target' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -347,7 +347,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Root() Assert.IsNotNull(pInfo, "Expected 'Target' property on derived type"); Assert.AreEqual(targetType, pInfo.PropertyType, "'Target' property should have been of type " + targetType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Target' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -365,7 +365,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Root() Assert.IsNotNull(pInfo, "Expected 'Source' property on target type"); Assert.AreEqual(derivedType, pInfo.PropertyType, "'Source' property should have been of type " + derivedType); - assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Source' property"); value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -428,7 +428,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Derived() Assert.IsNotNull(pInfo, "Expected 'Target' property on derived type"); Assert.AreEqual(targetType, pInfo.PropertyType, "'Target' property should have been of type " + targetType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Target' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -446,7 +446,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Derived() Assert.IsNotNull(pInfo, "Expected 'Source' property on target type"); Assert.AreEqual(derivedType, pInfo.PropertyType, "'Source' property should have been of type " + derivedType); - assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Source' property"); value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -513,7 +513,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Derived_OneToMany() Type genericType = propType.GetGenericArguments()[0]; Assert.AreEqual(targetType, genericType, "'Targets' property should have been of type " + targetType + ", not " + genericType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Targets' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -532,7 +532,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Derived_OneToMany() propType = pInfo.PropertyType; Assert.AreEqual(derivedType, propType, "'Sources' property should have been of type " + derivedType + ", not " + propType); - assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Source' property"); value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -597,7 +597,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Derived_ManyToOne() Type propType = pInfo.PropertyType; Assert.AreEqual(targetType, propType, "'Target' property should have been of type " + targetType + ", not " + propType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Targets' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -619,7 +619,7 @@ public void Inherit_Gen_Assoc_Bi_Derived_To_Included_Derived_ManyToOne() Type genericType = propType.GetGenericArguments()[0]; Assert.AreEqual(derivedType, genericType, "'Sources' property should have been of type " + derivedType + ", not " + genericType); - assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Source' property"); value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -691,7 +691,7 @@ public void Inherit_Gen_Projection_Bi_Derived_To_Included_Derived() Assert.IsNotNull(pInfo, "Expected 'Target' property on derived type"); Assert.AreEqual(targetType, pInfo.PropertyType, "'Target' property should have been of type " + targetType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Target' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -709,7 +709,7 @@ public void Inherit_Gen_Projection_Bi_Derived_To_Included_Derived() Assert.IsNotNull(pInfo, "Expected 'Source' property on target type"); Assert.AreEqual(derivedType, pInfo.PropertyType, "'Source' property should have been of type " + derivedType); - assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Source' property"); value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -790,7 +790,7 @@ public void Inherit_Gen_Projection_Bi_Derived_To_Included_Derived_Reversed() Assert.IsNotNull(pInfo, "Expected 'Target' property on derived type"); Assert.AreEqual(targetType, pInfo.PropertyType, "'Target' property should have been of type " + targetType); - CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + CustomAttributeData assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Target' property"); string value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey"); @@ -808,7 +808,7 @@ public void Inherit_Gen_Projection_Bi_Derived_To_Included_Derived_Reversed() Assert.IsNotNull(pInfo, "Expected 'Source' property on target type"); Assert.AreEqual(derivedType, pInfo.PropertyType, "'Source' property should have been of type " + derivedType); - assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(AssociationAttribute)).SingleOrDefault(); + assocCad = AssemblyGenerator.GetCustomAttributeData(pInfo, typeof(EntityAssociationAttribute)).SingleOrDefault(); Assert.IsNotNull(assocCad, "Could not find Association custom attribute data on 'Source' property"); value = AssemblyGenerator.GetCustomAttributeValue(assocCad, "thisKey");