public void Interface() { // Arrange J value = new C(); string name = null; // Act TypeSwitch.On(value) .Case((J x) => name = x.ShortName) .Case((C x) => name = x.FullName) .Default((x) => name = x.ToString()); // Assert Assert.AreEqual("CJ", name); }
public void DefaultNoArg() { // Arrange var value = new object(); string name = null; // Act TypeSwitch.On(value) .Case((J x) => name = x.ShortName) .Case((C x) => name = x.FullName) .Default(() => name = "Default"); // Assert Assert.AreEqual("Default", name); }
public void DerivedClassAsBaseClass() { // Arrange A value = new C(); string name = null; // Act TypeSwitch.On(value) .Case((C x) => name = x.FullName) .Case((B x) => name = x.LongName) .Case <A>(() => name = "A") .Default((x) => name = x.ToString()); // Assert Assert.AreEqual("C", name); }
public void BaseClassObject() { // Arrange object value = new A(); string name = null; // Act TypeSwitch.On(value) .Case((C x) => name = x.FullName) .Case((B x) => name = x.LongName) .Case <A>(() => name = "A") .Default((x) => name = x.ToString()); // Assert Assert.AreEqual("A", name); }
public void InterfaceObject() { // Arrange object value = new C(); string name = null; // Act TypeSwitch.On(value) .Case((I x) => name = x.GetID()) .Case((J x) => name = x.ShortName) .Case((C x) => name = x.FullName) .Case <A>(() => name = "A") .Default((x) => name = x.ToString()); // Assert Assert.AreEqual("CI", name); }