Exemple #1
0
        public void An_EnumModel_WithId_CanBeConvertedTo_Any_Enum()
        {
            var firstModel = new EnumModel {
                Id = "0"
            };
            var secondModel = new EnumModel {
                Id = "second-option"
            };
            var thirdModel = new EnumModel {
                Id = nameof(MyEnum.ThirdOption)
            };
            var emptyModel = new EnumModel {
                Id = ((int)MyEnum.EmptyOption).ToString()
            };

            Assert.Equal(MyEnum.FirstOption, firstModel.ToEnum <MyEnum>());
            Assert.Equal(MyEnum.SecondOption, secondModel.ToEnum <MyEnum>());
            Assert.Equal(MyEnum.ThirdOption, thirdModel.ToEnum <MyEnum>());
            Assert.Equal(MyEnum.EmptyOption, emptyModel.ToEnum <MyEnum>());
        }