Example #1
0
        public static void Main()
        {
            try
            {
                MyEnum?e   = MyEnum.A;
                byte?  b   = 255;
                MyEnum?res = e + b;
                Console.WriteLine(res != 0);

                e   = null;
                b   = 255;
                res = e + b;
                Console.WriteLine(res != null);

                MyEnum e2   = MyEnum.A;
                byte   b2   = 1;
                MyEnum res2 = e2 + b2;
                Console.WriteLine(res2 != MyEnum.B);
            }
            catch (Exception exc)
            {
                Console.WriteLine("Unexpected exception: " + exc);
            }
            Console.WriteLine("<%END%>");
        }
Example #2
0
        public void Nullable_Enum_variable_comparison_is_rewritten()
        {
            MyEnum?a = MyEnum.A;
            MyEnum?b = MyEnum.B;

            ShouldEqual(() => a == b, "a == b");
        }
Example #3
0
    public static int Main()
    {
        MyEnum?e   = MyEnum.A;
        byte?  b   = 255;
        MyEnum?res = e + b;

        if (res != 0)
        {
            return(1);
        }

        e   = null;
        b   = 255;
        res = e + b;
        if (res != null)
        {
            return(2);
        }

        MyEnum e2   = MyEnum.A;
        byte   b2   = 1;
        MyEnum res2 = e2 + b2;

        if (res2 != MyEnum.B)
        {
            return(3);
        }

        Console.WriteLine("OK");
        return(0);
    }
        public void When_nullable_enums_are_unequal_it_should_succeed(MyEnum?subject, MyEnum?expected)
        {
            // Act
            Action act = () => subject.Should().NotBe(expected);

            // Assert
            act.Should().NotThrow();
        }
Example #5
0
        public void PackNullableEnumAsNull()
        {
            MyEnum?value = null;

            byte[] data = Pack <MyEnum?>(value);
            Assert.AreEqual(Format.Nil, data[0]);
            Assert.AreEqual(1, data.Length);
        }
Example #6
0
        public void PackNullableEnum()
        {
            MyEnum?value = MyEnum.Foo;

            byte[] data = Pack <MyEnum?>(value);
            Assert.AreEqual(Format.PositiveFixIntMin + 1, data[0]);
            Assert.AreEqual(1, data.Length);
        }
        public void When_nullable_enums_have_unequal_names_it_should_succeed(MyEnum?subject, MyEnumOtherValue expected)
        {
            // Act
            Action act = () => subject.Should().NotHaveSameNameAs(expected);

            // Assert
            act.Should().NotThrow();
        }
Example #8
0
        public void TestParse_ValueBlank_NullReturned()
        {
            EnumColumn <MyEnum> column = new EnumColumn <MyEnum>("count");
            MyEnum?actual   = (MyEnum?)column.Parse(null, "    ");
            MyEnum?expected = null;

            Assert.AreEqual(expected, actual);
        }
        public void When_nullable_enums_are_unequal_it_should_throw(MyEnum?subject, MyEnum?expected)
        {
            // Act
            Action act = () => subject.Should().NotBe(expected, "we want to test the failure {0}", "message");

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("*because we want to test the failure message*");
        }
        public void When_nullable_enums_have_equal_names_it_should_throw(MyEnum?subject, MyEnumOtherValue expected)
        {
            // Act
            Action act = () => subject.Should().HaveSameNameAs(expected, "we want to test the failure {0}", "message");

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("*because we want to test the failure message*");
        }
Example #11
0
    public void SerializeNullableEnum()
    {
        MyEnum?input = MyEnum.b;

        _serializer.Save(Call, input);
        MyEnum?output = _serializer.Load <MyEnum?>(Call);

        Assert.AreEqual(output, input);
    }
Example #12
0
    public static void Main(string[] args)
    {
        int?   one = 1, two = 2, three = 3;
        int?   nul = null;
        MyEnum?a = MyEnum.A, b = MyEnum.B;

        PrintNullables(a, b, null);
        PrintNullables(a + one, a - one);
        PrintNullables(a + nul, a - nul);
    }
        public void TestNullableEnumToIntConvertExpression()
        {
            MyEnum?value = MyEnum.Second;
            Expression <Func <int?> > expression = () => (int)value;

            Assert.AreEqual(expected: 1, actual: evaluator.Evaluate(expression.Body));

            value = null;
            Assert.Catch(() => evaluator.Evaluate(expression.Body));
        }
        public void When_nullable_enum_does_not_have_value_it_should_succeed()
        {
            // Arrange
            MyEnum?subject = null;

            // Act
            Action act = () => subject.Should().NotHaveValue();

            // Assert
            act.Should().NotThrow();
        }
        public void When_nullable_enum_is_null_it_should_succeed()
        {
            // Arrange
            MyEnum?subject = null;

            // Act
            Action act = () => subject.Should().BeNull();

            // Assert
            act.Should().NotThrow();
        }
Example #16
0
 public static MyEnum?f(MyEnum?x)
 {
     if (x.HasValue)
     {
         return(x);
     }
     else
     {
         return(null);
     }
 }
        public void When_a_null_enum_and_an_enum_are_unequal_it_should_succeed()
        {
            // Arrange
            MyEnum?subject  = null;
            MyEnum expected = MyEnum.Two;

            // Act
            Action act = () => subject.Should().NotBe(expected);

            // Assert
            act.Should().NotThrow();
        }
        public void When_a_null_enum_and_an_enum_are_unequal_it_should_throw()
        {
            // Arrange
            MyEnum?subject  = null;
            MyEnum expected = MyEnum.Two;

            // Act
            Action act = () => subject.Should().Be(expected);

            // Assert
            act.Should().Throw <XunitException>();
        }
            public void A_null_entry_of_an_enum_throws()
            {
                // Arrange
                MyEnum?subject = null;

                // Act
                Action act = () => subject.Should().BeDefined();

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage("Expected *to be defined in*, but found <null>.");
            }
        public void When_nullable_enums_have_equal_names_it_should_succeed()
        {
            // Arrange
            MyEnum?          subject  = MyEnum.One;
            MyEnumOtherValue expected = MyEnumOtherValue.One;

            // Act
            Action act = () => subject.Should().HaveSameNameAs(expected);

            // Assert
            act.Should().NotThrow();
        }
        public void When_nullable_enum_does_not_have_value_it_should_throw()
        {
            // Arrange
            MyEnum?subject = null;

            // Act
            Action act = () => subject.Should().HaveValue("we want to test the failure {0}", "message");

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("*because we want to test the failure message*");
        }
        public void When_nullable_enum_is_not_null_it_should_throw()
        {
            // Arrange
            MyEnum?subject = MyEnum.One;

            // Act
            Action act = () => subject.Should().BeNull("we want to test the failure {0}", "message");

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("*because we want to test the failure message*");
        }
        public void When_nullable_enum_has_value_it_should_be_chainable()
        {
            // Arrange
            MyEnum?subject = MyEnum.One;

            // Act
            Action act = () => subject.Should().HaveValue()
                         .Which.Should().Be(MyEnum.One);

            // Assert
            act.Should().NotThrow();
        }
        public void When_nullable_enum_is_not_null_it_should_be_chainable()
        {
            // Arrange
            MyEnum?subject = MyEnum.One;

            // Act
            Action act = () => subject.Should().NotBeNull()
                         .Which.Should().Be(MyEnum.One);

            // Assert
            act.Should().NotThrow();
        }
            public void A_null_value_of_an_enum_is_not_defined_and_throws()
            {
                // Arrange
                MyEnum?subject = null;

                // Act
                Action act = () => subject.Should().NotBeDefined();

                // Assert
                act.Should().Throw <XunitException>()
                .WithMessage("Did not expect *to be defined in*, but found <null>.");
            }
        public void When_nullable_enums_have_unequal_values_it_should_throw()
        {
            // Arrange
            MyEnum?         subject  = MyEnum.One;
            MyEnumOtherName expected = MyEnumOtherName.OtherOne;

            // Act
            Action act = () => subject.Should().NotHaveSameValueAs(expected, "we want to test the failure {0}", "message");

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("*because we want to test the failure message*");
        }
Example #27
0
        public void When_a_nullable_enum_is_asserted_on_is_should_use_object_assertions()
        {
            // Arrange
            MyEnum?myEnum = MyEnum.Dummy;
            string expectedAssertionType = "FluentAssertions.Primitives.ObjectAssertions";

            // Act
            string assertionType = myEnum.Should().GetType().FullName;

            // Assert
            assertionType.Should().Be(expectedAssertionType,
                                      "it is a breaking change, if nullable enums do not end up in ObjectAssertions");
        }
Example #28
0
        public void ToStringWithEnumName()
        {
            var value = MyEnum.non;

            if (value.ToStringWithEnumName().IsNullOrEmpty())
            {
                throw new Exception();
            }

            MyEnum?value2 = null;

            if (value2.ToStringWithEnumName().IsNullOrEmpty())
            {
                throw new Exception();
            }
        }
Example #29
0
    public static void Main (string[] args) {
        MyEnum? e1 = MyEnum.A;
        MyEnum? e2 = null;

        Console.WriteLine(e1.Value.ToString());
        Console.WriteLine(e2.GetValueOrDefault(MyEnum.B).ToString());

        NE = e2;
        E = e1.Value;

        Console.WriteLine((int)(E));

        NE = e1;
        E = e2.GetValueOrDefault(MyEnum.C);

        Console.WriteLine((int)(NE.Value));
        Console.WriteLine((int)(E));
    }
Example #30
0
    public static void Main(string[] args)
    {
        MyEnum?e1 = MyEnum.A;
        MyEnum?e2 = null;

        Console.WriteLine(e1.Value.ToString());
        Console.WriteLine(e2.GetValueOrDefault(MyEnum.B).ToString());

        NE = e2;
        E  = e1.Value;

        Console.WriteLine((int)(E));

        NE = e1;
        E  = e2.GetValueOrDefault(MyEnum.C);

        Console.WriteLine((int)(NE.Value));
        Console.WriteLine((int)(E));
    }
Example #31
0
        public void EnumMethod()
        {
            Console.WriteLine(MyEnum.luni);
            int?   n      = null;
            MyEnum?myEnum = (MyEnum?)n ?? (MyEnum.joi | (MyEnum)3);

            //Enum is not impliment IEnumerable
            //foreach ( var item in myEnum ) {   }
            for (int i = 2; i < Enum.GetNames(typeof(MyEnum)).Length + 2; i++)
            {
                Console.WriteLine((MyEnum)i);
            }
            foreach (var item in Enum.GetValues(typeof(MyEnum)))
            {
                Console.WriteLine((int)item);
            }
            Console.WriteLine(Enum.GetNames(typeof(MyEnum)).Count());

            Console.WriteLine(myEnum);
        }
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
         field = iprot.ReadFieldBegin();
         if (field.Type == TType.Stop) { 
             break;
         }
         switch (field.ID)
         {
             case 1:
                 if (field.Type == TType.Bool) {
                     MBool = iprot.ReadBool();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 2:
                 if (field.Type == TType.Byte) {
                     MByte = iprot.ReadByte();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 3:
                 if (field.Type == TType.I16) {
                     MShort = iprot.ReadI16();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 4:
                 if (field.Type == TType.I32) {
                     MInt = iprot.ReadI32();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 5:
                 if (field.Type == TType.I64) {
                     MLong = iprot.ReadI64();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 6:
                 if (field.Type == TType.Double) {
                     MDouble = iprot.ReadDouble();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             case 7:
                 if (field.Type == TType.I32) {
                     MEnum = (MyEnum?)iprot.ReadI32();
                 } else {
                     TProtocolUtil.Skip(iprot, field.Type);
                 }
                 break;
             default:
                 TProtocolUtil.Skip(iprot, field.Type);
                 break;
         }
         iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }