Skip to content

Commit

Permalink
fix: unit tests updated to run for .net8
Browse files Browse the repository at this point in the history
  • Loading branch information
pksorensen committed May 28, 2024
1 parent 6ad5203 commit d984a55
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 145 deletions.
20 changes: 14 additions & 6 deletions sdk/DTO/AttributeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public override AttributeDefinitionBase Read(
return new AttributeStringDefinition { Value = reader.GetString() ?? "" };
case JsonTokenType.StartObject:
var node = JsonNode.Parse(ref reader);
var t = node.Deserialize<AttributeObjectDefinition>();
return t;

var t = node.Deserialize<AttributeObjectDefinition>(new JsonSerializerOptions { Converters={ new TypeDefinitionConverter()} });
return t;


default:
throw new Exception($"{reader.TokenType} is not supported as AttributeDefinition");
}
Expand Down Expand Up @@ -85,8 +88,11 @@ public override TypeDefinition Read(
return new TypeDefinition { Type = reader.GetString() ?? "" };
case JsonTokenType.StartObject:
var node = JsonNode.Parse(ref reader);
var t = node.Deserialize<TypeDefinition>();
return t;

var t = node.Deserialize<TypeDefinition>();
return t;


default:
throw new Exception($"{reader.TokenType} is not supported as AttributeDefinition");
}
Expand All @@ -106,8 +112,10 @@ public override void Write(Utf8JsonWriter writer, TypeDefinition value, JsonSeri
jsonNode?.WriteTo(writer, options);
}
}
[JsonConverter(typeof(TypeDefinitionConverter))]
public class TypeDefinition

// [JsonConverter(typeof(TypeDefinitionConverter))]

public class TypeDefinition
{
[JsonPropertyName("type")] public string Type { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion sdk/DTO/MessageDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace EAVFW.Extensions.Manifest.SDK
{
public class MessageDefinition
{
[JsonPropertyName("title")] public string? Title { get; set; }
[JsonPropertyName("title")] public string Title { get; set; }
}
}
12 changes: 4 additions & 8 deletions sdk/DefaultManifestReplacementRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DotNETDevOps.JsonFunctions;
using DotNETDevOps.JsonFunctions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -211,14 +211,10 @@ public async Task RunReplacements(JToken jsonraw, string customizationprefix, IL
}
else
{
try
{

parentObj.Add(childProp);
q.Enqueue(childProp);
}catch(Exception ex)
{
throw;
}

}

// parentObj.Add(childProp.Name, childProp.Value);
Expand Down Expand Up @@ -284,7 +280,7 @@ public async Task RunReplacements(JToken jsonraw, string customizationprefix, IL
}

}
catch (Exception ex)
catch (Exception)
{
Console.WriteLine($"{entityPath}| {attributePath}");
throw;
Expand Down
4 changes: 2 additions & 2 deletions sdk/EAVFW.Extensions.Manifest.SDK.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>

Expand Down
10 changes: 5 additions & 5 deletions sdk/ManifestEnricher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -45,7 +45,7 @@ public ManifestPermissionGenerator(IParameterGenerator parameterGenerator)
{
this.parameterGenerator = parameterGenerator ?? throw new ArgumentNullException(nameof(parameterGenerator));
}
public async Task<string> CreateInitializationScript(JToken model, string systemUserEntity)
public Task<string> CreateInitializationScript(JToken model, string systemUserEntity)
{

var sb = new StringBuilder();
Expand Down Expand Up @@ -80,7 +80,7 @@ public async Task<string> CreateInitializationScript(JToken model, string system
WritePermissionStatement(sb, entitiy, "Assign", "Assign", adminSGId);
}

return sb.ToString();
return Task.FromResult(sb.ToString());
}
private void WritePermissionStatement(StringBuilder sb, JProperty entitiy, string permission, string permissionName, string adminSGId, bool adminSRId1 = false)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ private object[] CreateOptions(params string[] args)
{
return args.Select((o, i) => new { label = o, value = i + 1 }).ToArray();
}
private JObject CreateAttribute(JObject attr, string displayName, object type, string? schemaName = null, object? additionalProps = null)
private JObject CreateAttribute(JObject attr, string displayName, object type, string schemaName = null, object additionalProps = null)
{
if (additionalProps != null)
return Merge(Merge(attr, new { displayName, type, schemaName }), additionalProps);
Expand Down Expand Up @@ -777,7 +777,7 @@ JObject SetDefault(JToken obj, JObject localeEnglish)
}

var queue =
new Queue<JObject?>(
new Queue<JObject>(
attributes.Properties()
.Select(c => c.Value as JObject)
.Where(x => x != null)
Expand Down
2 changes: 1 addition & 1 deletion src/EAVFramework.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<PackageId>EAVFramework</PackageId>
<Authors>Poul Kjeldager</Authors>
<Company>EAVFW</Company>
Expand Down
12 changes: 6 additions & 6 deletions test/EAVFramework.UnitTest/EAVFramework.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
<UserSecretsId>5530110b-f598-40fb-a452-3a16fa69df9e</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.17" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.1" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
70 changes: 5 additions & 65 deletions test/EAVFramework.UnitTest/EmitTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EAVFramework.Shared;
using EAVFramework.Shared;
using EAVFramework.Shared.V2;
using EAVFramework.UnitTest.ManifestTests;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
Expand Down Expand Up @@ -29,7 +30,7 @@ namespace EAVFramework.UnitTest
{

[TestClass]
public class EmitTests
public class EmitTests : BaseManifestTests
{
public static string RemoveWhitespace( string input)
{
Expand Down Expand Up @@ -153,6 +154,7 @@ public void TestInherience()

}
[TestMethod]
[DeploymentItem(@"Specs/oidcclient.json", "Specs")]
public void TestCoices()
{
DynamicCodeService codeMigratorV2 = CreateOptions(o =>
Expand Down Expand Up @@ -324,69 +326,7 @@ public void TestExternalBaseClass()


}
private static void NoOp(CodeGenerationOptions o) { }
private static DynamicCodeService CreateOptions(Action<CodeGenerationOptions> onconfig =null)
{
onconfig ??= NoOp;
var o = new CodeGenerationOptions
{
// MigrationName="Initial",

JsonPropertyAttributeCtor = typeof(JsonPropertyAttribute).GetConstructor(new Type[] { typeof(string) }),
JsonPropertyNameAttributeCtor = typeof(System.Text.Json.Serialization.JsonPropertyNameAttribute).GetConstructor(new Type[] { typeof(string) }),
InverseAttributeCtor = typeof(InversePropertyAttribute).GetConstructor(new Type[] { typeof(string) }),
ForeignKeyAttributeCtor= typeof(ForeignKeyAttribute).GetConstructor(new Type[] { typeof(string) }),

EntityConfigurationInterface = typeof(IEntityTypeConfiguration),
EntityConfigurationConfigureName = nameof(IEntityTypeConfiguration.Configure),
EntityTypeBuilderType = typeof(EntityTypeBuilder),
EntityTypeBuilderToTable = Resolve(()=> typeof(RelationalEntityTypeBuilderExtensions).GetMethod(nameof(RelationalEntityTypeBuilderExtensions.ToTable), 0, new[] { typeof(EntityTypeBuilder), typeof(string), typeof(string) }), "EntityTypeBuilderToTable"),
EntityTypeBuilderHasKey = Resolve(() => typeof(EntityTypeBuilder).GetMethod(nameof(EntityTypeBuilder.HasKey), 0, new[] { typeof(string[]) }), "EntityTypeBuilderHasKey"),
EntityTypeBuilderPropertyMethod = Resolve(() => typeof(EntityTypeBuilder).GetMethod(nameof(EntityTypeBuilder.Property), 0, new[] { typeof(string) }), "EntityTypeBuilderPropertyMethod"),

IsRequiredMethod = Resolve(() => typeof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder)
.GetMethod(nameof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder.IsRequired)), "IsRequiredMethod"),
IsRowVersionMethod = Resolve(() => typeof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder)
.GetMethod(nameof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder.IsRowVersion)), "IsRowVersionMethod"),
HasConversionMethod = Resolve(() => typeof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder)
.GetMethod(nameof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder.HasConversion), 1, new Type[] { }), "HasConversionMethod"),
HasPrecisionMethod = Resolve(() => typeof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder)
.GetMethod(nameof(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder.HasPrecision), new Type[] { typeof(int), typeof(int) }), "HasPrecisionMethod"),



DynamicTableType = typeof(IDynamicTable),
DynamicTableArrayType = typeof(IDynamicTable[]),


ColumnsBuilderType = typeof(ColumnsBuilder),
CreateTableBuilderType = typeof(CreateTableBuilder<>),
CreateTableBuilderPrimaryKeyName = nameof(CreateTableBuilder<object>.PrimaryKey),
CreateTableBuilderForeignKeyName = nameof(CreateTableBuilder<object>.ForeignKey),
ColumnsBuilderColumnMethod = Resolve(() => typeof(ColumnsBuilder).GetMethod(nameof(ColumnsBuilder.Column), BindingFlags.Public | BindingFlags.Instance), "ColumnsBuilderColumnMethod"),
OperationBuilderAddColumnOptionType = typeof(OperationBuilder<AddColumnOperation>),


MigrationBuilderDropTable = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.DropTable)), "MigrationBuilderDropTable"),
MigrationBuilderCreateTable = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.CreateTable)), "MigrationBuilderCreateTable"),
MigrationBuilderSQL = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.Sql)), "MigrationBuilderSQL"),
MigrationBuilderCreateIndex = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.CreateIndex), new Type[] { typeof(string), typeof(string), typeof(string[]), typeof(string), typeof(bool), typeof(string) }), "MigrationBuilderCreateIndex"),
MigrationBuilderDropIndex = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.DropIndex)), "MigrationBuilderDropIndex"),
MigrationsBuilderAddColumn = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.AddColumn)), "MigrationsBuilderAddColumn"),
MigrationsBuilderAddForeignKey = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.AddForeignKey), new Type[] { typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(ReferentialAction), typeof(ReferentialAction) }), "MigrationsBuilderAddForeignKey"),
MigrationsBuilderAlterColumn = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.AlterColumn)), "MigrationsBuilderAlterColumn"),
MigrationsBuilderDropForeignKey = Resolve(() => typeof(MigrationBuilder).GetMethod(nameof(MigrationBuilder.DropForeignKey)), "MigrationsBuilderDropForeignKey"),

ReferentialActionType = typeof(ReferentialAction),
ReferentialActionNoAction = (int)ReferentialAction.NoAction,


LambdaBase = Resolve(() => typeof(Expression).GetMethod(nameof(Expression.Lambda), 1, BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(Expression), typeof(ParameterExpression[]) }, null), "LambdaBase"),

};
onconfig(o);
return new DynamicCodeService(o);
}

}

[EntityInterface(EntityKey ="*")]
Expand Down
8 changes: 5 additions & 3 deletions test/EAVFramework.UnitTest/GenericTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EAVFramework.Shared;
using EAVFramework.Shared;
using EAVFramework.Shared.V2;
using EAVFramework.UnitTest.ManifestTests;
using EAVFW.Extensions.Manifest.SDK;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using System;
Expand All @@ -11,6 +12,7 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml.Linq;

Expand Down Expand Up @@ -104,8 +106,8 @@ public static string RemoveWhitespace(string input)
public async Task TestInherienceLevel2()
{
//Arrange
var manifest = JToken.Parse(File.ReadAllText(@"Specs/manifest.payments.json"));

var manifest = JToken.Parse(File.ReadAllText(@"Specs/manifest.payments.json"));

//Act
var sql = RunDBWithSchema("payments", manifest);
Expand Down
Loading

0 comments on commit d984a55

Please sign in to comment.