示例#1
0
        public void FormatFlags_UsesDefaultDelimiter_WhenUsingValidValueWithEmptyDelimiter()
        {
            var value = ColorFlagEnum.Red | ColorFlagEnum.Green;

            AssertTryFormatFlags(value, FlagEnums.FormatFlags(value));

            void AssertTryFormatFlags(ColorFlagEnum value, string expected)
            {
                Assert.AreEqual(expected, FlagEnums.FormatFlags(value, string.Empty));
#if SPAN
                var dest = new char[expected.Length];
                Assert.True(FlagEnums.TryFormatFlags(value, dest, out var charsWritten, string.Empty));
                Assert.AreEqual(expected.Length, charsWritten);
                Assert.AreEqual(expected, new string(dest));

                dest = new char[expected.Length - 1];
                Assert.False(FlagEnums.TryFormatFlags(value, dest, out charsWritten, string.Empty));
                Assert.AreEqual(0, charsWritten);
                CollectionAssert.AreEqual(new char[dest.Length], dest);
#endif
            }
        }
示例#2
0
        public void FormatFlags_UsesDefaultDelimiter_WhenUsingValidValueWithNullDelimiter()
        {
            var value = ColorFlagEnum.Red | ColorFlagEnum.Green;

            Assert.AreEqual(FlagEnums.FormatFlags(value), FlagEnums.FormatFlags(value, (string)null));
        }
示例#3
0
 public void FormatFlags_ReturnsValidString_WhenUsingInvalidValue()
 {
     Assert.AreEqual("16", FlagEnums.FormatFlags((ColorFlagEnum)16));
 }