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

Convert E2E Tests to use MSTest to enable NativeAOT unit testing #432

Merged
merged 16 commits into from
Mar 6, 2024
Merged
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
64 changes: 0 additions & 64 deletions .github/workflows/NativeAotTest.yml

This file was deleted.

18 changes: 16 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ jobs:
build:
strategy:
matrix:
os: [ windows-latest, ubuntu-latest, macos-latest ]
include:
- os: windows-latest
rid: win-x64
- os: ubuntu-latest
rid: linux-x64
- os: macos-latest
rid: osx-x64
runs-on: ${{ matrix.os }}
env:
AppVeyorBuild: true
Expand Down Expand Up @@ -65,10 +71,18 @@ jobs:
working-directory: src
run: dotnet build -c Release /p:SignAssembly=true

- name: E2E Test
- name: E2E Test (JIT)
working-directory: src/Tests/FlatSharpEndToEndTests
run: dotnet test -c Release /p:SignAssembly=true --verbosity normal

- name: E2E Test (AOT)
working-directory: src/Tests/FlatSharpEndToEndTests
env:
BuildAot: 'true'
run: |
dotnet publish -c Release -f net8.0 -r ${{ matrix.rid }}
./bin/Release/net8.0/${{ matrix.rid }}/publish/FlatSharpEndToEndTests

- name: Poolable E2E Test
working-directory: src/Tests/FlatSharpPoolableEndToEndTests
run: dotnet test -c Release /p:SignAssembly=true --verbosity normal
Expand Down
5 changes: 5 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.9.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="1.0.2" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.9.0" />
<PackageVersion Include="MSTest.Engine" Version="1.0.0-alpha.24151.3" />
<PackageVersion Include="MSTest.SourceGeneration" Version="1.0.0-alpha.24151.3" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.2.2" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="protobuf-net" Version="3.2.30" />
<PackageVersion Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
Expand Down
18 changes: 18 additions & 0 deletions src/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- MSTest early access packages. See: https://aka.ms/mstest/preview -->
<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
</packageSources>
<packageSourceMapping>
<!-- key value for <packageSource> should match key values from <packageSources> element -->
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="test-tools">
<package pattern="MSTest.*" />
<package pattern="Microsoft.Testing.*" />
</packageSource>
</packageSourceMapping>
</configuration>

Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,62 @@

namespace FlatSharpEndToEndTests.ClassLib.FlatBufferSerializerNonGenericTests;

[TestClass]
public class FlatBufferSerializerNonGenericTests
{
[Fact]
[TestMethod]
public void NonGenericSerializer_FromInstance()
{
ISerializer serializer = (ISerializer)SomeTable.Serializer.WithSettings(s => s.UseLazyDeserialization());

Assert.IsAssignableFrom<ISerializer<SomeTable>>(serializer);
Assert.Equal(typeof(SomeTable), serializer.RootType);
Assert.IsInstanceOfType<ISerializer<SomeTable>>(serializer);
Assert.AreEqual(typeof(SomeTable), serializer.RootType);

Assert.True(serializer.GetMaxSize(new SomeTable()) > 0);
Assert.Throws<ArgumentNullException>(() => serializer.GetMaxSize(null));
Assert.Throws<ArgumentException>(() => serializer.GetMaxSize(new SomeOtherTable()));
Assert.IsTrue(serializer.GetMaxSize(new SomeTable()) > 0);
Assert.ThrowsException<ArgumentNullException>(() => serializer.GetMaxSize(null));
Assert.ThrowsException<ArgumentException>(() => serializer.GetMaxSize(new SomeOtherTable()));

#if NET6_0_OR_GREATER
{
var bw = new ArrayBufferWriter<byte>();
Assert.Throws<ArgumentNullException>(() => serializer.Write(bw, null));
Assert.Throws<ArgumentException>(() => serializer.Write(bw, new SomeOtherTable()));
Assert.ThrowsException<ArgumentNullException>(() => serializer.Write(bw, null));
Assert.ThrowsException<ArgumentException>(() => serializer.Write(bw, new SomeOtherTable()));

int written = serializer.Write(bw, new SomeTable { A = 3 });
Assert.True(written > 0);
Assert.Equal(written, bw.WrittenCount);
Assert.IsTrue(written > 0);
Assert.AreEqual(written, bw.WrittenCount);

object parsed = serializer.Parse(bw.WrittenMemory);
Assert.True(typeof(SomeTable).IsAssignableFrom(parsed.GetType()));
Assert.NotEqual(typeof(SomeTable), parsed.GetType());
Assert.IsAssignableFrom<IFlatBufferDeserializedObject>(parsed);
Assert.IsTrue(typeof(SomeTable).IsAssignableFrom(parsed.GetType()));
Assert.AreNotEqual(typeof(SomeTable), parsed.GetType());
Assert.IsInstanceOfType<IFlatBufferDeserializedObject>(parsed);

var deserialized = (IFlatBufferDeserializedObject)parsed;
Assert.Equal(typeof(SomeTable), deserialized.TableOrStructType);
Assert.NotNull(deserialized.InputBuffer); // lazy
Assert.Equal(FlatBufferDeserializationOption.Lazy, deserialized.DeserializationContext.DeserializationOption);
Assert.Equal(FlatBufferDeserializationOption.Lazy, serializer.DeserializationOption);
Assert.AreEqual(typeof(SomeTable), deserialized.TableOrStructType);
Assert.IsNotNull(deserialized.InputBuffer); // lazy
Assert.AreEqual(FlatBufferDeserializationOption.Lazy, deserialized.DeserializationContext.DeserializationOption);
Assert.AreEqual(FlatBufferDeserializationOption.Lazy, serializer.DeserializationOption);
}
#endif

{
var bw = new byte[1024];
Assert.Throws<ArgumentNullException>(() => serializer.Write(bw, null));
Assert.Throws<ArgumentException>(() => serializer.Write(bw, new SomeOtherTable()));
Assert.ThrowsException<ArgumentNullException>(() => serializer.Write(bw, null));
Assert.ThrowsException<ArgumentException>(() => serializer.Write(bw, new SomeOtherTable()));

int written = serializer.Write(bw, new SomeTable { A = 3 });
Assert.True(written > 0);
Assert.IsTrue(written > 0);

object parsed = serializer.Parse(bw);
Assert.True(typeof(SomeTable).IsAssignableFrom(parsed.GetType()));
Assert.NotEqual(typeof(SomeTable), parsed.GetType());
Assert.IsAssignableFrom<IFlatBufferDeserializedObject>(parsed);
Assert.IsTrue(typeof(SomeTable).IsAssignableFrom(parsed.GetType()));
Assert.AreNotEqual(typeof(SomeTable), parsed.GetType());
Assert.IsInstanceOfType<IFlatBufferDeserializedObject>(parsed);

var deserialized = (IFlatBufferDeserializedObject)parsed;
Assert.Equal(typeof(SomeTable), deserialized.TableOrStructType);
Assert.NotNull(deserialized.InputBuffer); // lazy
Assert.Equal(FlatBufferDeserializationOption.Lazy, deserialized.DeserializationContext.DeserializationOption);
Assert.Equal(FlatBufferDeserializationOption.Lazy, serializer.DeserializationOption);
Assert.AreEqual(typeof(SomeTable), deserialized.TableOrStructType);
Assert.IsNotNull(deserialized.InputBuffer); // lazy
Assert.AreEqual(FlatBufferDeserializationOption.Lazy, deserialized.DeserializationContext.DeserializationOption);
Assert.AreEqual(FlatBufferDeserializationOption.Lazy, serializer.DeserializationOption);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace FlatSharpEndToEndTests.ClassLib.FlatBufferVectorOfUnionTests;
/// <summary>
/// Tests for FlatSharp's IList of Union.
/// </summary>

[TestClass]
public class FlatBufferVectorOfUnionTests
{
private TableVector vector;
Expand All @@ -39,47 +39,47 @@ public FlatBufferVectorOfUnionTests()
this.vector = original.SerializeAndParse(FlatBufferDeserializationOption.Lazy);
}

[Fact]
[TestMethod]
public void FlatBufferVector_OutOfRange()
{
Assert.Throws<IndexOutOfRangeException>(() => this.vector.Vector[-1]);
Assert.Throws<IndexOutOfRangeException>(() => this.vector.Vector[5]);
Assert.ThrowsException<IndexOutOfRangeException>(() => this.vector.Vector[-1]);
Assert.ThrowsException<IndexOutOfRangeException>(() => this.vector.Vector[5]);
}

[Fact]
[TestMethod]
public void FlatBufferVector_NotMutable()
{
Assert.True(this.vector.Vector.IsReadOnly);
Assert.Throws<NotMutableException>(() => this.vector.Vector[0] = new MyUnion("foobar"));
Assert.Throws<NotMutableException>(() => this.vector.Vector.Add(new MyUnion("foobar")));
Assert.Throws<NotMutableException>(() => this.vector.Vector.Clear());
Assert.Throws<NotMutableException>(() => this.vector.Vector.Insert(0, new MyUnion("foobar")));
Assert.Throws<NotMutableException>(() => this.vector.Vector.Remove(new MyUnion("foobar")));
Assert.Throws<NotMutableException>(() => this.vector.Vector.RemoveAt(0));
Assert.IsTrue(this.vector.Vector.IsReadOnly);
Assert.ThrowsException<NotMutableException>(() => this.vector.Vector[0] = new MyUnion("foobar"));
Assert.ThrowsException<NotMutableException>(() => this.vector.Vector.Add(new MyUnion("foobar")));
Assert.ThrowsException<NotMutableException>(() => this.vector.Vector.Clear());
Assert.ThrowsException<NotMutableException>(() => this.vector.Vector.Insert(0, new MyUnion("foobar")));
Assert.ThrowsException<NotMutableException>(() => this.vector.Vector.Remove(new MyUnion("foobar")));
Assert.ThrowsException<NotMutableException>(() => this.vector.Vector.RemoveAt(0));
}

[Fact]
[TestMethod]
public void FlatBufferVector_GetEnumerator()
{
int i = 0;
foreach (var item in this.vector.Vector)
{
Assert.Equal(i + 1, item.Discriminator);
Assert.AreEqual(i + 1, item.Discriminator);
i++;
}
}

[Fact]
[TestMethod]
public void FlatBufferVector_Contains()
{
Assert.True(this.vector.Vector.Contains(new MyUnion("foobar")));
Assert.False(this.vector.Vector.Contains(new MyUnion("blah")));
Assert.IsTrue(this.vector.Vector.Contains(new MyUnion("foobar")));
Assert.IsFalse(this.vector.Vector.Contains(new MyUnion("blah")));
}

[Fact]
[TestMethod]
public void FlatBufferVector_IndexOf()
{
Assert.Equal(0, this.vector.Vector.IndexOf(new MyUnion("foobar")));
Assert.Equal(-1, this.vector.Vector.IndexOf(new MyUnion("monster")));
Assert.AreEqual(0, this.vector.Vector.IndexOf(new MyUnion("foobar")));
Assert.AreEqual(-1, this.vector.Vector.IndexOf(new MyUnion("monster")));
}
}
Loading
Loading