コード例 #1
0
    public void Should_return_invalid_item_if_enum_doesnt_have_any_items()
    {
        var item = EmptyEnum.Get("unknown");

        item.IsValid.Should().BeFalse();
        item.Key.Should().Be("unknown");
    }
コード例 #2
0
    public void Should_return_false_if_null_is_provided()
    {
        EmptyEnum.TryGet(null, out var item).Should().BeFalse();
        item.Should().BeNull();

        ExtensibleTestEnum.TryGet(null, out var extensibleItem).Should().BeFalse();
        extensibleItem.Should().BeNull();

        ExtendedTestEnum.TryGet(null, out var extendedItem).Should().BeFalse();
        extendedItem.Should().BeNull();

        DifferentAssemblyExtendedTestEnum.TryGet(null, out var differentAssemblyExtendedItem).Should().BeFalse();
        differentAssemblyExtendedItem.Should().BeNull();
    }
コード例 #3
0
        public void TestEnumComparer()
        {
            var c1 = EnumComparer <EmptyEnum> .Comparer;

            c1.Compare((EmptyEnum)(-1), (EmptyEnum)1);
            var d1 = Comparer <EmptyEnum> .Default;
            var e1 = EqualityComparer <EmptyEnum> .Default;
            var v1 = new EmptyEnum[] { (EmptyEnum)(-1), (EmptyEnum)1 };

            Assert.AreEqual(d1.Compare(v1[0], v1[1]), c1.Compare(v1[0], v1[1]));
            Assert.AreEqual(d1.Compare(v1[1], v1[0]), c1.Compare(v1[1], v1[0]));
            Assert.AreEqual(d1.Compare(v1[1], v1[1]), c1.Compare(v1[1], v1[1]));
            Assert.AreEqual(e1.Equals(v1[0], v1[1]), c1.Equals(v1[0], v1[1]));
            Assert.AreEqual(e1.Equals(v1[1], v1[1]), c1.Equals(v1[1], v1[1]));
            Assert.AreEqual(e1.GetHashCode(v1[0]), c1.GetHashCode(v1[0]));
            Assert.AreNotEqual(c1.GetHashCode(v1[0]), c1.GetHashCode(v1[1]));

            var c2 = EnumComparer <TestLongEnum> .Comparer;
            var d2 = Comparer <TestLongEnum> .Default;
            var e2 = EqualityComparer <TestLongEnum> .Default;
            var v2 = new TestLongEnum[] { TestLongEnum.Min, TestLongEnum.Max };

            Assert.AreEqual(d2.Compare(v2[0], v2[1]), c2.Compare(v2[0], v2[1]));
            Assert.AreEqual(d2.Compare(v2[1], v2[0]), c2.Compare(v2[1], v2[0]));
            Assert.AreEqual(d2.Compare(v2[1], v2[1]), c2.Compare(v2[1], v2[1]));
            Assert.AreEqual(e2.Equals(v2[0], v2[1]), c2.Equals(v2[0], v2[1]));
            Assert.AreEqual(e2.Equals(v2[1], v2[1]), c2.Equals(v2[1], v2[1]));

            var c3 = EnumComparer <TestUlongEnum> .Comparer;
            var d3 = Comparer <TestUlongEnum> .Default;
            var e3 = EqualityComparer <TestUlongEnum> .Default;
            var v3 = new TestUlongEnum[] { TestUlongEnum.Max, (TestUlongEnum)1 };

            Assert.AreEqual(d3.Compare(v3[0], v3[1]), c3.Compare(v3[0], v3[1]));
            Assert.AreEqual(d3.Compare(v3[1], v3[0]), c3.Compare(v3[1], v3[0]));
            Assert.AreEqual(d3.Compare(v3[1], v3[1]), c3.Compare(v3[1], v3[1]));
            Assert.AreEqual(e3.Equals(v3[0], v3[1]), c3.Equals(v3[0], v3[1]));
            Assert.AreEqual(e3.Equals(v3[1], v3[1]), c3.Equals(v3[1], v3[1]));
            Assert.AreNotEqual(c3.GetHashCode(v3[0]), c3.GetHashCode(v3[1]));

            var clone = c1.DeepClone();

            Assert.AreSame(c1, clone);
        }
コード例 #4
0
 public Case2()
 {
     EmptyEnum a1 = 0;
     // EmptyEnum a2 = 1;
 }
コード例 #5
0
 public void Should_return_false_if_enum_dont_have_any_items()
 {
     EmptyEnum.TryGet("unknown", out var item).Should().BeFalse();
     item.Should().BeNull();
 }