示例#1
0
        public void ToDescriptionTest()
        {
            TestEnum value = TestEnum.EnumItemA;

            Assert.AreEqual(value.ToDescription(), "枚举项A");

            value = TestEnum.EnumItemB;
            Assert.AreEqual(value.ToDescription(), "EnumItemB");
        }
示例#2
0
        public void ToDescriptionTest()
        {
            TestEnum value = TestEnum.EnumItemA;

            Assert.Equal("枚举项A", value.ToDescription());

            value = TestEnum.EnumItemB;
            Assert.Equal("EnumItemB", value.ToDescription());
        }
        public void ToDescription()
        {
            var val1 = (Int32)TestEnum.TestNoDescription;

            var testNoDescription = TestEnum.TestNoDescription.ToDescription();

            Assert.AreEqual("TestNoDescription", testNoDescription, "TestEnum with no description, and no value, returned unexpected result.");
            var testNoDescriptionWithValue = TestEnum.TestNoDescriptionWithValue.ToDescription();

            Assert.AreEqual("TestNoDescriptionWithValue", testNoDescriptionWithValue, "TestEnum with no description, and a value, returned an unexpected result.");

            var testDescription = TestEnum.TestDescription.ToDescription();

            Assert.AreEqual("Test Description", testDescription, "TestEnum with a description, and no value, returned an unexpected result.");
            var testDescriptionWithValue = TestEnum.TestDescriptionWithValue.ToDescription();

            Assert.AreEqual("Test Description With Value", testDescriptionWithValue, "TestEnum with a description, and a value, returned an unexpected result.");

            var flagsNoDescription = TestFlags.FlagsNoDescription.ToDescription();

            Assert.AreEqual("FlagsNoDescription", flagsNoDescription);
            var flagsNoDescriptionWithValue = TestFlags.FlagsNoDescriptionWithValue.ToDescription();

            Assert.AreEqual("FlagsNoDescriptionWithValue", flagsNoDescriptionWithValue);

            var flagsDescription = TestFlags.FlagsDescription.ToDescription();

            Assert.AreEqual("Flags Description, FlagsNoDescriptionWithValue", flagsDescription);
            var flagsDescriptionWithValue = TestFlags.FlagsDescriptionWithValue.ToDescription();

            Assert.AreEqual("Flags Description With Value", flagsDescriptionWithValue);

            var multiFlagsDescription = TestFlags.MultiFlagsDescription.ToDescription(false);

            Assert.AreEqual("Multi Flags Description", multiFlagsDescription);
            var multiFlagsNoDescription = TestFlags.MultiFlagsNoDescription.ToDescription(false);

            Assert.AreEqual("MultiFlagsNoDescription", multiFlagsNoDescription);

            var otherFlagsDescription = (TestFlags.FlagsNoDescriptionWithValue | TestFlags.OtherValue).ToDescription();

            Assert.AreEqual("OtherValue, FlagsNoDescriptionWithValue", otherFlagsDescription);

            TestEnum badTest            = (TestEnum)10;
            var      badTestDescription = badTest.ToDescription();

            Assert.AreEqual("10", badTestDescription);

            TestFlags badTestFlags            = (TestFlags)6;
            var       badTestFlagsDescription = badTestFlags.ToDescription();

            Assert.AreEqual("FlagsNoDescriptionWithValue, 6", badTestFlagsDescription);
        }