public void SwitchProperlyHandlesSubclassAndMatchesOnce() { var origOne = new Fake.One(); var origTwo = new Fake.Two(); var origThree = new Fake.Three(); OneOf <Fake, Fake.One, Fake.Two> one = origOne; OneOf <Fake, Fake.One, Fake.Two> two = origTwo; OneOf <Fake, Fake.One, Fake.Two> three = origThree; Func <OneOf <Fake, Fake.One, Fake.Two>, int> testerFunc = o => { var i = 0; o .Switch((Fake f) => i++) .Switch((Fake.One f) => i++) .Switch((Fake.Two f) => i++); return(i); }; Assert.AreEqual(1, testerFunc(one)); Assert.AreEqual(1, testerFunc(two)); Assert.AreEqual(1, testerFunc(three)); }
public void MatcherMatchesOnlyOnceWhenParentClassAndSubClassesAreInOneof() { OneOf <Fake, Fake.One, Fake.Two> one = new Fake.One(); OneOf <Fake, Fake.One, Fake.Two> two = new Fake.Two(); OneOf <Fake, Fake.One, Fake.Two> three = new Fake.Three(); Func <OneOf <Fake, Fake.One, Fake.Two>, int> testerFunc = o => { var result = o.Match((Fake f) => 3). Match((Fake.One f) => 1). Match((Fake.Two f) => 2); return(result); }; Assert.AreEqual(1, testerFunc(one)); Assert.AreEqual(2, testerFunc(two)); Assert.AreEqual(3, testerFunc(three)); }