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 Communicate between framework mscorlib and core framework with Unit Tests #116

Merged
merged 16 commits into from
Oct 15, 2019
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
2 changes: 1 addition & 1 deletion build-system/nightly-builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema for reference

pool:
vmImage: vs2017-win2016
vmImage: windows-2019
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

demands: Cmd

trigger: none
Expand Down
2 changes: 1 addition & 1 deletion build-system/pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
parameters:
name: 'windows_pr'
displayName: 'Windows PR Validation'
vmImage: 'vs2017-win2016'
vmImage: 'windows-2019'
scriptFileName: build.cmd
scriptArgs: all
- template: azure-pipeline.template.yaml
Expand Down
2 changes: 1 addition & 1 deletion build-system/windows-pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- template: azure-pipeline.template.yaml
parameters:
name: Windows
vmImage: 'vs2017-win2016'
vmImage: 'windows-2019'
scriptFileName: build.cmd
scriptArgs: all
2 changes: 1 addition & 1 deletion build-system/windows-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema for reference

pool:
vmImage: vs2017-win2016
vmImage: windows-2019
demands: Cmd

trigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
<Compile Include="Types.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.6.2" />
</ItemGroup>

</Project>
37 changes: 37 additions & 0 deletions src/Hyperion.Tests/CrossFrameworkSerializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.IO;
using Hyperion.Tests.Generator;
using Xunit;

namespace Hyperion.Tests
{
public class CrossFrameworkSerializationTests
{
private readonly Serializer _serializer;
private readonly CrossFrameworkClass _originalObject;

public CrossFrameworkSerializationTests()
{
_serializer = new Serializer();
_originalObject = CrossFrameworkInitializer.Init();
}

[Fact]
public void CanSerializeCrossFramework()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this the only way to do it - have to actually load the sucker and work the payloads on both ends.

{
const string defaultOutputPath = CrossFrameworkInitializer.DefaultOutputPath;
var testFiles = Directory.GetFiles(defaultOutputPath, "*.tf");

Assert.NotEmpty(testFiles);

foreach (string testFile in testFiles)
{
using (var fileStream = new FileStream(testFile, FileMode.Open))
{
var crossFrameworkClass = _serializer.Deserialize<CrossFrameworkClass>(fileStream);

Assert.Equal(_originalObject, crossFrameworkClass);
}
}
}
}
}
125 changes: 125 additions & 0 deletions src/Hyperion.Tests/Generator/CrossFrameworkClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System;

namespace Hyperion.Tests.Generator
{
public class CrossFrameworkClass
{
public sbyte Sbyte { get; set; }

public short Short { get; set; }

public int Int { get; set; }

public long Long { get; set; }

public byte Byte { get; set; }

public ushort UShort { get; set; }

public uint UInt { get; set; }

public ulong ULong { get; set; }

public char Char { get; set; }

public float Float { get; set; }

public double Double { get; set; }

public decimal Decimal { get; set; }

public bool Boolean { get; set; }

public string String { get; set; }

public DateTime DateTime { get; set; }

public Exception Exception { get; set; }

public CrossFrameworkEnum Enum { get; set; }

public CrossFrameworkStruct Struct { get; set; }

public override bool Equals(object obj)
{
if (!(obj is CrossFrameworkClass))
{
return false;
}

var objectToCompare = (CrossFrameworkClass) obj;


//return Sbyte == objectToCompare.Sbyte
// && Short == objectToCompare.Short
// && Int == objectToCompare.Int
// && Long == objectToCompare.Long
// && Byte == objectToCompare.Byte
// && UShort == objectToCompare.UShort
// && UInt == objectToCompare.UInt
// && ULong == objectToCompare.ULong
// && Char == objectToCompare.Char
// && Math.Abs(Float - objectToCompare.Float) < float.Epsilon
// && Math.Abs(Double - objectToCompare.Double) < double.Epsilon
// && Decimal == objectToCompare.Decimal
// && Boolean == objectToCompare.Boolean
// && String == objectToCompare.String
// && DateTime == objectToCompare.DateTime
// && Exception == objectToCompare.Exception
// && Enum == objectToCompare.Enum
// && Struct.Equals(objectToCompare.Struct);

return Equals(objectToCompare);

}

public override int GetHashCode()
{
unchecked
{
int hashCode = Sbyte.GetHashCode();
hashCode = (hashCode * 397) ^ Short.GetHashCode();
hashCode = (hashCode * 397) ^ Int;
hashCode = (hashCode * 397) ^ Long.GetHashCode();
hashCode = (hashCode * 397) ^ Byte.GetHashCode();
hashCode = (hashCode * 397) ^ UShort.GetHashCode();
hashCode = (hashCode * 397) ^ (int) UInt;
hashCode = (hashCode * 397) ^ ULong.GetHashCode();
hashCode = (hashCode * 397) ^ Char.GetHashCode();
hashCode = (hashCode * 397) ^ Float.GetHashCode();
hashCode = (hashCode * 397) ^ Double.GetHashCode();
hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
hashCode = (hashCode * 397) ^ Boolean.GetHashCode();
hashCode = (hashCode * 397) ^ (String != null ? String.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ DateTime.GetHashCode();
hashCode = (hashCode * 397) ^ (Exception != null ? Exception.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (int) Enum;
hashCode = (hashCode * 397) ^ Struct.GetHashCode();
return hashCode;
}
}

private bool Equals(CrossFrameworkClass other)
{
return Sbyte == other.Sbyte
&& Short == other.Short
&& Int == other.Int
&& Long == other.Long
&& Byte == other.Byte
&& UShort == other.UShort
&& UInt == other.UInt
&& ULong == other.ULong
&& Char == other.Char
&& Math.Abs(Float - other.Float) < float.Epsilon
&& Math.Abs(Double - other.Double) < double.Epsilon
&& Decimal == other.Decimal
&& Boolean == other.Boolean
&& string.Equals(String, other.String)
&& DateTime.Equals(other.DateTime)
// && Equals(Exception, other.Exception)
&& Exception.Message == other.Exception.Message
&& Enum == other.Enum
&& Struct.Equals(other.Struct);
}
}
}
13 changes: 13 additions & 0 deletions src/Hyperion.Tests/Generator/CrossFrameworkEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Hyperion.Tests.Generator
{
public enum CrossFrameworkEnum
{
ShortSword,
LongSword,
BastardSword,
Claymore,
Scimitar,
Yatagan,
Katana
}
}
49 changes: 49 additions & 0 deletions src/Hyperion.Tests/Generator/CrossFrameworkInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;

namespace Hyperion.Tests.Generator
{
public static class CrossFrameworkInitializer
{
public const string DefaultOutputPath = "../../../testfiles";

public static CrossFrameworkClass Init()
{
return new CrossFrameworkClass()
{
Exception = new Exception("Test message", new ArgumentNullException("param", "Cannot be null")),
DateTime = new DateTime(1944, 6, 6), // DDay
Enum = CrossFrameworkEnum.Yatagan,
String = "On June 6, 1944, more than 160,000 Allied troops landed along a 50-mile stretch of heavily-fortified French coastline",
Struct = new CrossFrameworkStruct()
{
Boolean = true,
Long = long.MaxValue,
Decimal = decimal.MinusOne,
Double = double.MaxValue,
Int = int.MaxValue,
Short = short.MaxValue,
ULong = ulong.MinValue,
Byte = byte.MaxValue,
Char = char.MaxValue,
Float = float.MinValue,
UShort = ushort.MinValue,
UInt = uint.MaxValue,
Sbyte = sbyte.MaxValue
},
Decimal = decimal.MaxValue,
Float = float.MaxValue,
Long = long.MinValue,
Int = int.MinValue,
Double = double.Epsilon,
Char = char.MaxValue,
Byte = byte.MaxValue,
Sbyte = sbyte.MaxValue,
Short = short.MaxValue,
UInt = uint.MaxValue,
ULong = ulong.MaxValue,
UShort = ushort.MaxValue,
Boolean = true
};
}
}
}
83 changes: 83 additions & 0 deletions src/Hyperion.Tests/Generator/CrossFrameworkStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;

namespace Hyperion.Tests.Generator
{
public struct CrossFrameworkStruct
{
public sbyte Sbyte { get; set; }

public short Short { get; set; }

public int Int { get; set; }

public long Long { get; set; }

public byte Byte { get; set; }

public ushort UShort { get; set; }

public uint UInt { get; set; }

public ulong ULong { get; set; }

public char Char { get; set; }

public float Float { get; set; }

public double Double { get; set; }

public decimal Decimal { get; set; }

public bool Boolean { get; set; }

public override bool Equals(object obj)
{
if (!(obj is CrossFrameworkStruct))
{
return false;
}

var objectToCompare = (CrossFrameworkStruct)obj;

return Equals(objectToCompare);
}

public override int GetHashCode()
{
unchecked
{
int hashCode = Sbyte.GetHashCode();
hashCode = (hashCode * 397) ^ Short.GetHashCode();
hashCode = (hashCode * 397) ^ Int;
hashCode = (hashCode * 397) ^ Long.GetHashCode();
hashCode = (hashCode * 397) ^ Byte.GetHashCode();
hashCode = (hashCode * 397) ^ UShort.GetHashCode();
hashCode = (hashCode * 397) ^ (int) UInt;
hashCode = (hashCode * 397) ^ ULong.GetHashCode();
hashCode = (hashCode * 397) ^ Char.GetHashCode();
hashCode = (hashCode * 397) ^ Float.GetHashCode();
hashCode = (hashCode * 397) ^ Double.GetHashCode();
hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
hashCode = (hashCode * 397) ^ Boolean.GetHashCode();
return hashCode;
}
}

private bool Equals(CrossFrameworkStruct other)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - validates that all of the primitives are covered.

{
return Sbyte == other.Sbyte
&& Short == other.Short
&& Int == other.Int
&& Long == other.Long
&& Byte == other.Byte
&& UShort == other.UShort
&& UInt == other.UInt
&& ULong == other.ULong
&& Char == other.Char
&& Math.Abs(Float - other.Float) < float.Epsilon
&& Math.Abs(Double - other.Double) < double.Epsilon
&& Decimal == other.Decimal
&& Boolean == other.Boolean;
}
}
}
Loading