示例#1
0
        public void NotNullTest()
        {
            object reference = null;
            object value     = new InfoApe();

            Guard.NotNull(() => reference, value);

            value = reference;
            Assert.Throws <ArgumentException>(() => Guard.NotNull(() => reference, value));
        }
示例#2
0
        public void CreateAndInitializeMemberFieldTest()
        {
            var type        = typeof(string);
            var memberfield = "theMember";
            var actual      = CodeMethodComposer.CreateAndInitializeMemberField(type, memberfield);

            Assert.IsInstanceOfType <CodeAssignStatement>(actual);

            object expectedValue = true;
            Type   expectedType  = expectedValue.GetType();

            actual = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            var assignment = (CodePrimitiveExpression)actual.Right;

            Assert.AreEqual(true, assignment.Value);
            Assert.AreEqual(expectedType, assignment.Value.GetType());

            expectedValue = typeof(CodeMethodComposerTest);
            expectedType  = expectedValue.GetType();
            actual        = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            var assignment2 = (CodeObjectCreateExpression)actual.Right;

            Assert.AreEqual(expectedType.FullName, assignment2.CreateType.BaseType);

            expectedValue = 35;
            expectedType  = expectedValue.GetType();
            actual        = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            assignment    = (CodePrimitiveExpression)actual.Right;
            Assert.AreEqual(1234, assignment.Value);
            Assert.AreEqual(expectedType, assignment.Value.GetType());

            expectedValue = new InfoApe();
            expectedType  = expectedValue.GetType();
            actual        = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            assignment2   = (CodeObjectCreateExpression)actual.Right;
            Assert.AreEqual(expectedType.FullName, assignment2.CreateType.BaseType);

            // Todo: implement all CLR-Types.
        }
示例#3
0
        public void CreateAndInitializeMemberFieldTest()
        {
            var type = typeof(string);
            var memberfield = "theMember";
            var actual = CodeMethodComposer.CreateAndInitializeMemberField(type, memberfield);
            Assert.IsInstanceOfType<CodeAssignStatement>(actual);

            object expectedValue = true;
            Type expectedType = expectedValue.GetType();
            actual = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            var assignment = (CodePrimitiveExpression)actual.Right;
            Assert.AreEqual(true, assignment.Value);
            Assert.AreEqual(expectedType, assignment.Value.GetType());

            expectedValue = typeof(CodeMethodComposerTest);
            expectedType = expectedValue.GetType();
            actual = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            var assignment2 = (CodeObjectCreateExpression)actual.Right;
            Assert.AreEqual(expectedType.FullName, assignment2.CreateType.BaseType);

            expectedValue = 35;
            expectedType = expectedValue.GetType();
            actual = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            assignment = (CodePrimitiveExpression)actual.Right;
            Assert.AreEqual(1234, assignment.Value);
            Assert.AreEqual(expectedType, assignment.Value.GetType());

            expectedValue = new InfoApe();
            expectedType = expectedValue.GetType();
            actual = CodeMethodComposer.CreateAndInitializeMemberField(expectedType, memberfield);
            assignment2 = (CodeObjectCreateExpression)actual.Right;
            Assert.AreEqual(expectedType.FullName, assignment2.CreateType.BaseType);

            // Todo: implement all CLR-Types.
        }