Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Svensson committed Jun 9, 2024
1 parent a5af828 commit dea5d54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/OpenRiaServices.Tools/Test/AssemblyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -316,6 +318,13 @@ internal static bool TryGetCustomAttributeValue<T>(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<CustomAttributeTypedArgument>)ctorArg.Value).Select(arg => arg.Value?.ToString() ?? "null"));
return true;
}
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/OpenRiaServices.Tools/Test/InheritanceCodeGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(assocCad, "thisKey");
Expand Down Expand Up @@ -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<string>(assocCad, "thisKey");
Expand All @@ -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<string>(assocCad, "thisKey");
Expand Down Expand Up @@ -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<string>(assocCad, "thisKey");
Expand All @@ -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<string>(assocCad, "thisKey");
Expand Down Expand Up @@ -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<string>(assocCad, "thisKey");
Expand All @@ -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<string>(assocCad, "thisKey");
Expand Down Expand Up @@ -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<string>(assocCad, "thisKey");
Expand All @@ -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<string>(assocCad, "thisKey");
Expand Down Expand Up @@ -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<string>(assocCad, "thisKey");
Expand All @@ -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<string>(assocCad, "thisKey");
Expand Down Expand Up @@ -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<string>(assocCad, "thisKey");
Expand All @@ -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<string>(assocCad, "thisKey");
Expand Down

0 comments on commit dea5d54

Please sign in to comment.