public void InstanceIsExactlyTypeReference() { ModelBase act = new ModelDerived(); Type t = typeof(ModelBase); // MSTest does not support this case. // NUnit Assert.That(act, Is.TypeOf(t), () => "Some context"); // Some context // Expected: <ModelBase> // But was: <ModelDerived> // XUnit XUnitAssert.IsType(t, act); // Assert.IsType() Failure // Expected: ModelBase // Actual: ModelDerived // Fluent act.Should().BeOfType(t, "SOME REASONS"); // Expected type to be ModelBase because SOME REASONS, but found ModelDerived. // Shouldly act.ShouldBeOfType(t, "Some context"); // act // should be of type // ModelBase // but was // ModelDerived // // Additional Info: // Some context }
public void InstanceIsExactlyStaticType() { ModelBase act = new ModelDerived(); ModelBase iModel; // MSTest does not support this case. // NUnit Assert.That(act, Is.TypeOf <ModelBase>(), () => "Some context"); // Some context // Expected: <ModelBase> // But was: <ModelDerived> // XUnit iModel = XUnitAssert.IsType <ModelBase>(act); // Assert.IsType() Failure // Expected: ModelBase // Actual: ModelDerived // Fluent iModel = act.Should().BeOfType <ModelBase>("SOME REASONS").Which; // Expected type to be ModelBase because SOME REASONS, but found ModelDerived. // Shouldly iModel = act.ShouldBeOfType <ModelBase>("Some context"); // act // should be of type // ModelBase // but was // ModelDerived // // Additional Info: // Some context }