using dk.nsi.seal.FunctionalExt; using NUnit.Framework; using static dk.nsi.seal.FunctionalExt.Prelude; namespace SealTest.FunctionalExt; public class UnionTests { readonly record struct Type1 { public Type1() {} public readonly string Value = "Type1"; } readonly record struct Type2 { public Type2() {} public readonly string Value = "Type2"; } [Test] public void GivenUnionThenMatchShouldShouldReturnCorrectValue1() => Assert.AreEqual("Type1", Union(new Type1()).Match(t1 => t1.Value, _ => "failure")); [Test] public void GivenUnionThenMatchShouldShouldReturnCorrectValue2() => Assert.AreEqual("Type2", Union(new Type2()).Match(_ => "failure", t2 => t2.Value)); [Test] public void GivenUnionThenImplicitAssignmentShouldReturnCorrectValue1() { DUnion u = new Type1(); Assert.AreEqual("Type1", u.Match(t1 => t1.Value, _ => "failure")); } [Test] public void GivenUnionThenImplicitAssignmentShouldReturnCorrectValue2() { DUnion u = new Type2(); Assert.AreEqual("Type2", u.Match(_ => "failure", t2 => t2.Value)); } }