using System; using Shouldly; using Xunit; namespace Volo.ExtensionMethods.Tests { public class ObjectExtensions_Tests { [Fact] public void As_Test() { var obj = (object)new ObjectExtensions_Tests(); obj.As().ShouldNotBe(null); obj = null; obj.As().ShouldBe(null); } [Fact] public void To_Tests() { "42".To().ShouldBeOfType().ShouldBe(42); "42".To().ShouldBeOfType().ShouldBe(42); "28173829281734".To().ShouldBeOfType().ShouldBe(28173829281734); "28173829281734".To().ShouldBeOfType().ShouldBe(28173829281734); "2.0".To().ShouldBe(2.0); "0.2".To().ShouldBe(0.2); (2.0).To().ShouldBe(2); "false".To().ShouldBeOfType().ShouldBe(false); "True".To().ShouldBeOfType().ShouldBe(true); Assert.Throws(() => "test".To()); Assert.Throws(() => "test".To()); } [Fact] public void IsIn_Test() { 5.IsIn(1, 3, 5, 7).ShouldBe(true); 6.IsIn(1, 3, 5, 7).ShouldBe(false); int? number = null; number.IsIn(2, 3, 5).ShouldBe(false); var str = "a"; str.IsIn("a", "b", "c").ShouldBe(true); str = null; str.IsIn("a", "b", "c").ShouldBe(false); } } }