public void EnumValueTest() { EnumValue <M.BooleanValues> onoffEnum = new EnumValue <M.BooleanValues>(); Assert.False(onoffEnum.HasValue); Assert.Null(onoffEnum.InnerText); Assert.Null(onoffEnum.ToString()); onoffEnum.InnerText = "error value"; Assert.False(onoffEnum.HasValue); Assert.Equal("error value", onoffEnum.InnerText); Assert.Equal("error value", onoffEnum.ToString()); onoffEnum.InnerText = string.Empty; Assert.False(onoffEnum.HasValue); Assert.Equal(string.Empty, onoffEnum.InnerText); Assert.Equal(string.Empty, onoffEnum.ToString()); onoffEnum.InnerText = "on"; Assert.True(onoffEnum.HasValue); Assert.Equal("on", onoffEnum.InnerText); Assert.Equal(M.BooleanValues.On, onoffEnum.Value); Assert.Equal(M.BooleanValues.On, (M.BooleanValues)onoffEnum); Assert.Equal("on", onoffEnum.ToString()); var newEnum = new EnumValue <M.BooleanValues>(onoffEnum); Assert.True(newEnum.HasValue); newEnum.Value = M.BooleanValues.Off; Assert.True(newEnum.HasValue); Assert.Equal("off", newEnum.InnerText); Assert.Equal(M.BooleanValues.Off, newEnum.Value); Assert.Equal(M.BooleanValues.Off, (M.BooleanValues)newEnum); Assert.Equal("off", newEnum.ToString()); // the onoffEnum should not be changed. Assert.True(onoffEnum.HasValue); Assert.Equal("on", onoffEnum.InnerText); Assert.Equal(M.BooleanValues.On, onoffEnum.Value); Assert.Equal(M.BooleanValues.On, (M.BooleanValues)onoffEnum); Assert.Equal("on", onoffEnum.ToString()); // test special case - the enum can be empty string "" var truefalseEmpty = new EnumValue <xvml.BooleanEntryWithBlankValues>(xvml.BooleanEntryWithBlankValues.Empty); Assert.True(truefalseEmpty.HasValue); Assert.Equal(string.Empty, truefalseEmpty.InnerText); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, truefalseEmpty.Value); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, (xvml.BooleanEntryWithBlankValues)truefalseEmpty); Assert.Equal(string.Empty, truefalseEmpty.ToString()); truefalseEmpty = xvml.BooleanEntryWithBlankValues.T; Assert.True(truefalseEmpty.HasValue); Assert.Equal("t", truefalseEmpty.InnerText); Assert.Equal(xvml.BooleanEntryWithBlankValues.T, truefalseEmpty.Value); Assert.Equal(xvml.BooleanEntryWithBlankValues.T, (xvml.BooleanEntryWithBlankValues)truefalseEmpty); Assert.Equal("t", truefalseEmpty.ToString()); truefalseEmpty.InnerText = string.Empty; Assert.True(truefalseEmpty.HasValue); Assert.Equal(string.Empty, truefalseEmpty.InnerText); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, truefalseEmpty.Value); Assert.Equal(xvml.BooleanEntryWithBlankValues.Empty, (xvml.BooleanEntryWithBlankValues)truefalseEmpty); Assert.Equal(string.Empty, truefalseEmpty.ToString()); // Clone constructor for EnumValue HeaderFooterValues validValue0 = HeaderFooterValues.Default; var objA = new EnumValue <HeaderFooterValues>(validValue0); var objB = new EnumValue <HeaderFooterValues>(objA); Assert.True(objA.HasValue); Assert.True(objB.HasValue); Assert.Equal("default", objA.InnerText); Assert.Equal("default", objB.InnerText); // Clone() for EnumValue. objA = new EnumValue <HeaderFooterValues>(validValue0); objB = (EnumValue <HeaderFooterValues>)objA.Clone(); Assert.True(objA.HasValue); Assert.True(objB.HasValue); Assert.Equal("default", objA.InnerText); Assert.Equal("default", objB.InnerText); }