public void NotNullTest() { object reference = null; object value = new InfoApe(); Guard.NotNull(() => reference, value); value = reference; Assert.Throws <ArgumentException>(() => Guard.NotNull(() => reference, value)); }
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. }
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. }