Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test run on Net8 #458

Merged
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net6.0;netstandard2.0;</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net6.0;netstandard2.0</TargetFrameworks>
<PackageTags>WCF;RIA;Services;RIAServices;Silverlight;OpenRiaServices</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoWarn>108</NoWarn>
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net472;net6.0-windows;net8.0-windows</TargetFrameworks>
<Version>1.0.0.0</Version>
<UseWPF>true</UseWPF>
<DefineConstants>$(DefineConstants);HAS_COLLECTIONVIEW</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0</TargetFrameworks>
<RootNamespace>OpenRiaServices.Hosting.AspNetCore</RootNamespace>
<Version>1.0.0.0</Version>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<NoWarn>618</NoWarn>
<DefineConstants>$(DefineConstants);SERVERFX</DefineConstants>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/OpenRiaServices.Tools/Framework/AssemblyUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ internal static Assembly LoadAssembly(string assemblyFileName, ILogger logger)
catch (Exception ex)
{
// Some common exceptions log a warning and keep running
if (ex is System.IO.FileNotFoundException ||
ex is System.IO.FileLoadException ||
ex is System.IO.PathTooLongException ||
ex is System.IO.DirectoryNotFoundException ||
if (ex is FileNotFoundException ||
ex is FileLoadException ||
ex is PathTooLongException ||
ex is DirectoryNotFoundException ||
ex is BadImageFormatException ||
ex is System.Security.SecurityException)
{
Expand Down
41 changes: 27 additions & 14 deletions src/OpenRiaServices.Tools/Framework/DataContractProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal abstract class DataContractProxyGenerator : ProxyGenerator
{
private readonly bool _isRoundtripType;
private readonly IDictionary<Type, CodeTypeDeclaration> _typeMapping;
private readonly List<Type> _attributeTypesToFilter;

/// <summary>
/// Initializes a new instance of the <see cref="DataContractProxyGenerator"/> class.
Expand All @@ -32,10 +33,23 @@ internal abstract class DataContractProxyGenerator : ProxyGenerator
protected DataContractProxyGenerator(CodeDomClientCodeGenerator proxyGenerator, Type type, IDictionary<Type, CodeTypeDeclaration> typeMapping)
: base(proxyGenerator)
{
this.Type = type;
this._typeMapping = typeMapping;
this.NotificationMethodGen = new NotificationMethodGenerator(proxyGenerator);
this._isRoundtripType = type.Attributes()[typeof(RoundtripOriginalAttribute)] != null;
Type = type;
_typeMapping = typeMapping;
NotificationMethodGen = new NotificationMethodGenerator(proxyGenerator);
_isRoundtripType = type.Attributes()[typeof(RoundtripOriginalAttribute)] != null;

// Add attributes which should be used to filter the attributes on type to be generated
_attributeTypesToFilter = new()
{
// DataContractAttribute and KnownTypeAttribute are handled seperatly
typeof(DataContractAttribute),
typeof(KnownTypeAttribute),
#if NET
// Filter out NullableAttribute and NullableContextAttribute, should only be used by compiler
Type.GetType("System.Runtime.CompilerServices.NullableAttribute"),
Type.GetType("System.Runtime.CompilerServices.NullableContextAttribute"),
#endif
};
}

/// <summary>
Expand Down Expand Up @@ -105,7 +119,7 @@ public override void Generate()
this.ProxyClass.TypeAttributes = TypeAttributes.Public;

// Abstract classes must be preserved as abstract to avoid explicit instantiation on client
bool isAbstract = (this.Type.IsAbstract);
bool isAbstract = (this.Type.IsAbstract);
if (isAbstract)
{
this.ProxyClass.TypeAttributes |= TypeAttributes.Abstract;
Expand Down Expand Up @@ -140,7 +154,7 @@ public override void Generate()
constructor.Attributes = isAbstract ? MemberAttributes.Family : MemberAttributes.Public;

// add default ctor doc comments
comment = string.Format(CultureInfo.CurrentCulture, Resource.CodeGen_Default_Constructor_Summary_Comments, this.Type.Name);
comment = string.Format(CultureInfo.CurrentCulture, Resource.CodeGen_Default_Constructor_Summary_Comments, this.Type.Name);
constructor.Comments.AddRange(CodeGenUtilities.GenerateSummaryCodeComment(comment, this.ClientProxyGenerator.IsCSharp));

// add call to default OnCreated method
Expand Down Expand Up @@ -284,9 +298,9 @@ protected static CodeStatement GeneratePropertySetterValidation(string propertyN
new CodeMethodInvokeExpression(
new CodeThisReferenceExpression(),
"ValidateProperty",
new CodeExpression[]
new CodeExpression[]
{
new CodePrimitiveExpression(propertyName),
new CodePrimitiveExpression(propertyName),
new CodePropertySetValueReferenceExpression()
}));
}
Expand Down Expand Up @@ -420,9 +434,9 @@ protected virtual void GenerateProperty(PropertyDescriptor propertyDescriptor)
}

// Here we check for database generated fields. In that case we strip any RequiredAttribute from the property.
if (propertyAttributes.Any(a=>a.GetType().Name == "DatabaseGeneratedAttribute"))
if (propertyAttributes.Any(a => a.GetType().Name == "DatabaseGeneratedAttribute"))
{
propertyAttributes.RemoveAll(attr => attr.GetType() == typeof (RequiredAttribute));
propertyAttributes.RemoveAll(attr => attr.GetType() == typeof(RequiredAttribute));
}

// Here, we check for the presence of a complex type. If it exists we need to add a DisplayAttribute
Expand Down Expand Up @@ -520,7 +534,7 @@ protected virtual void ValidateTypeAttributes(AttributeCollection typeAttributes
private IEnumerable<Attribute> FilterTypeAttributes(AttributeCollection typeAttributes)
{
List<Attribute> filteredAttributes = new List<Attribute>();

// Ignore DefaultMemberAttribute if it has been put for an indexer
IEnumerable<Attribute> defaultMemberAttribs = typeAttributes.Cast<Attribute>().Where(a => a.GetType() == typeof(DefaultMemberAttribute));
if (defaultMemberAttribs.Any())
Expand All @@ -535,9 +549,8 @@ private IEnumerable<Attribute> FilterTypeAttributes(AttributeCollection typeAttr
}
}

// Filter out attributes in filteredAttributes as well as DataContractAttribute and KnownTypeAttribute (since they are already handled)
return typeAttributes.Cast<Attribute>().Where(a => a.GetType() != typeof(DataContractAttribute) && a.GetType() != typeof(KnownTypeAttribute) &&
!(filteredAttributes.Contains(a)));
// Filter out attributes in filteredAttributes and attributeTypesToFilter
return typeAttributes.Cast<Attribute>().Where(a => !_attributeTypesToFilter.Contains(a.GetType()) && !filteredAttributes.Contains(a));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<DefineConstants>$(DefineConstants);SERVERFX;DBCONTEXT</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net472'">$(DefineConstants);HAS_LINQ2SQL</DefineConstants>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
<PackageId>OpenRiaServices.Client.CodeGen</PackageId>
<Title>OpenRiaServices Client Code Generator</Title>
<Description>OpenRiaServices CodeGen provides the MsBuild Tasks to generate the client proxy. </Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern alias TextTemplate;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.IO;
Expand All @@ -12,6 +11,7 @@
using OpenRiaServices.Server.Test.Utilities;
using OpenRiaServices.Tools.Test.T4Generator;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mono.Cecil;

namespace OpenRiaServices.Tools.Test
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public void ClientCodeGenerationDispatcher_Finds_Custom()
// into the MEF composition container
using (ClientCodeGenerationDispatcher dispatcher = new ClientCodeGenerationDispatcher())
{
string[] compositionAssemblies = new string[] { Assembly.GetExecutingAssembly().Location};
string[] compositionAssemblies = new string[] { Assembly.GetExecutingAssembly().Location };

IDomainServiceClientCodeGenerator generator = dispatcher.FindCodeGenerator(host, options, compositionAssemblies, MockCodeGenerator.GeneratorName);
Assert.IsNotNull(generator, "the dispatcher did not find any code generator");
Expand Down Expand Up @@ -180,11 +180,11 @@ public void ClientCodeGenerationDispatcher_Error_Missing_Custom()
IDomainServiceClientCodeGenerator generator = dispatcher.FindCodeGenerator(host, options, compositionAssemblies, "NotAGenerator");
Assert.IsNull(generator, "the dispatcher should not find any code generator");

string error = string.Format(CultureInfo.CurrentCulture,
Resource.Code_Generator_Not_Found,
"NotAGenerator",
options.Language,
options.ServerProjectPath,
string error = string.Format(CultureInfo.CurrentCulture,
Resource.Code_Generator_Not_Found,
"NotAGenerator",
options.Language,
options.ServerProjectPath,
options.ClientProjectPath,
CodeDomClientCodeGenerator.GeneratorName);
TestHelper.AssertContainsErrors(logger, error);
Expand Down Expand Up @@ -479,11 +479,11 @@ public void ClientCodeGenerationDispatcher_Error_Multiple_Generators()
string errorParam = " " + MockCodeGenerator.GeneratorName + Environment.NewLine +
" " + T4DomainServiceClientCodeGenerator.GeneratorName + Environment.NewLine;

string error = (string.Format(CultureInfo.CurrentCulture,
Resource.Multiple_Custom_Code_Generators_Using_Default,
options.Language,
errorParam,
options.ClientProjectPath,
string error = (string.Format(CultureInfo.CurrentCulture,
Resource.Multiple_Custom_Code_Generators_Using_Default,
options.Language,
errorParam,
options.ClientProjectPath,
MockCodeGenerator.GeneratorName,
CodeDomClientCodeGenerator.GeneratorName));
TestHelper.AssertContainsWarnings(logger, error);
Expand Down Expand Up @@ -518,19 +518,18 @@ public void ClientCodeGenerationDispatcher_Error_Multiple_Generators_Same_Name()
string errorParam = " " + typeof(MockFSharpCodeGenerator1).FullName + Environment.NewLine +
" " + typeof(MockFSharpCodeGenerator2).FullName + Environment.NewLine;

string error = string.Format(CultureInfo.CurrentCulture,
Resource.Multiple_Named_Code_Generators,
string error = string.Format(CultureInfo.CurrentCulture,
Resource.Multiple_Named_Code_Generators,
generatorName,
options.Language,
options.Language,
errorParam,
options.ServerProjectPath,
options.ServerProjectPath,
options.ClientProjectPath,
typeof(MockFSharpCodeGenerator1).AssemblyQualifiedName);
TestHelper.AssertContainsErrors(logger, error);
}
}

[DeploymentItem("TypeLoadExceptionProject.dll")]
[Description("ClientCodeGenerationDispatcher logs an warning and survives a TypeLoadException creating MEF")]
[TestMethod]
public void ClientCodeGenerationDispatcher_Error_TypeLoadException()
Expand All @@ -553,7 +552,18 @@ public void ClientCodeGenerationDispatcher_Error_TypeLoadException()
string unitTestAssemblyLocation = Assembly.GetExecutingAssembly().Location;
string typeLoadExceptionProjectLocation = Path.Combine(Path.GetDirectoryName(unitTestAssemblyLocation), "TypeLoadExceptionProject.dll");

Assert.IsTrue(File.Exists(typeLoadExceptionProjectLocation), "Expected TypeLoadExceptionProject.dll to coreside with this assembly in test folder");
if (!File.Exists(typeLoadExceptionProjectLocation))
{
var assemblyNameDefinition = new AssemblyNameDefinition("TestAssemblyNameDefinition", new Version(0, 0, 0, 0));
using var newAssembly = AssemblyDefinition.CreateAssembly(assemblyNameDefinition, "TestModuleName", ModuleKind.Dll);
var modules = newAssembly.MainModule;
var class1 = new TypeDefinition("TestNamespace", "Class1", Mono.Cecil.TypeAttributes.Class);
var class2 = new TypeDefinition("TestNamespace", "Class2", Mono.Cecil.TypeAttributes.Class, class1);
class1.BaseType = class2;
modules.Types.Add(class1);
modules.Types.Add(class2);
newAssembly.Write(typeLoadExceptionProjectLocation);
}

// Do what MEF does to load the types so we can capture the exception
Exception expectedException = null;
Expand Down Expand Up @@ -657,7 +667,7 @@ public string GenerateCode(ICodeGenerationHost host, IEnumerable<DomainServiceDe
return MockCodeGenerator.FakeGeneratedCode;
}
}

// Commented out so MEF does not discover this generator.
// It is used exclusively for testing fully qualified assembly name loading of generators.
// [DomainServiceClientCodeGenerator("ThrowingCtorCodeGenerator", "C#")]
Expand Down
2 changes: 2 additions & 0 deletions src/OpenRiaServices.Tools/Test/MsBuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ internal static ProjectWrapper LoadProject(string projectPath)

#if NETFRAMEWORK
string framework = frameworks.First(f => f.StartsWith("net4", StringComparison.Ordinal));
#elif NET6_0
string framework = frameworks.First(f => f.StartsWith("net6", StringComparison.Ordinal));
#else
string framework = frameworks.First(f => !f.StartsWith("net4", StringComparison.Ordinal));
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>618</NoWarn>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<TargetFrameworks>net472;net6.0;net8.0</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<DefineConstants Condition="'$(TargetFramework)' == 'net472'">$(DefineConstants);HAS_LINQ2SQL</DefineConstants>
Expand All @@ -28,6 +28,7 @@
<PackageReference Include="Microsoft.Build.Framework" Version="17.0.0" PrivateAssets="All" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.0.0" PrivateAssets="All" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.0.0" PrivateAssets="All" ExcludeAssets="Runtime" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="8.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
Expand Down Expand Up @@ -58,7 +59,6 @@
</ProjectReference>
<ProjectReference Include="..\..\Test\Desktop\OpenRiaServices.Common.DomainServices.Test\OpenRiaServices.Common.DomainServices.Test.csproj" />
<ProjectReference Include="..\..\Test\Desktop\OpenRiaServices.Common.Test\OpenRiaServices.Common.Test.csproj" />
<ProjectReference Include="..\..\Test\Desktop\TypeLoadExceptionProject\TypeLoadExceptionProject.csproj" />
<ProjectReference Include="..\Framework\OpenRiaServices.Tools.csproj" />
<ProjectReference Include="ServerClassLib\ServerClassLib.csproj" />
<ProjectReference Include="T4DomainServiceCodeGenerator\T4ClientCodeGenerator.csproj" />
Expand Down
Loading