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

WIP: Model from layout bindings #78

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<ProjectReference Include="..\Altinn.App.ModelGenerator\Altinn.App.ModelGenerator.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="TestData/**">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions src/Altinn.App.ModelGenerator.Tests/LayoutToModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Text.Json;
using System.Collections.Generic;
using Altinn.App.ModelGenerator;
using Xunit;

namespace Altinn.App.ModelGenerator.Tests;

public class LayoutToModelTests
{
[Theory]
[FileData("LayoutToModel/FormLayout.json", "LayoutToModel/Summary.json", "LayoutToModel/bindings.json", "LayoutToModel/model.cs")]
public void TestGetModelDataBindings(string FormLayout, string summary, string expectedBindings, string expectedModel)
{
// while (!System.Diagnostics.Debugger.IsAttached)
// System.Threading.Thread.Sleep(500);
// System.Diagnostics.Debugger.Break();

var bindings = LayoutToModel.GetDataModelBindings(new string[]{FormLayout, summary});
Assert.Equal(JsonSerializer.Deserialize<List<string>>(expectedBindings), bindings);
var generatedModel = LayoutToModel.Convert(bindings, "Altinn.App.Models.Model");
Assert.Equal(
expectedModel.Replace("\r\n","\n"), //Github actions has configured git to translate LF to CRLF
generatedModel);
}
[Theory]
[InlineData("Altinn.App.Models.KRT1226Gjenopprettingsplaner_M", "Altinn.App.Models", "KRT1226Gjenopprettingsplaner_M")]
public void TestSplitNamespace(string fullClassName, string expectedNs, string expectedClassName)
{
var(ns, className) = LayoutToModel.SplitFullClassname(fullClassName);
Assert.Equal(expectedNs, ns);
Assert.Equal(expectedClassName, className);
}
}
20 changes: 20 additions & 0 deletions src/Altinn.App.ModelGenerator.Tests/TestData/FileDataAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Xunit.Sdk;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Linq;

namespace Altinn.App.ModelGenerator.Tests;

public class FileDataAttribute : DataAttribute
{
private readonly string[] Files;
public FileDataAttribute(params string[] files)
{
Files = files;
}
public override IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
return new List<object[]>{Files.Select(f=>File.ReadAllText(Path.Join("TestData",f))).ToArray()};
}
}
Loading