public void TestMethodCtor_EmptyMethodName_ThrowsArgumentException()
        {
            // Arrange
            string methodName = String.Empty;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName);
        }
        public void TestMethodCtor_NullMethodName_ThrowsArgumentNullException()
        {
            // Arrange
            string methodName = null;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName);
        }
        public void TestAddEmptyGeneric_ThrowsArgumentException()
        {
            // Arrange
            string methodName      = "Method";
            string genericTypeName = String.Empty;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName).WithGenericTypeNames(genericTypeName);
        }
        public void TestAddNullArgument_ThrowsArgumentException()
        {
            // Arrange
            string     methodName = "Method";
            SGArgument arg        = null;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName).WithArguments(arg);
        }
        public void TestAccessibilityLevelSetNull_FluentAPI_ThrowsArgumentNullException()
        {
            // Arrange
            string methodName = "Method";
            SGAccessibilityLevel accessibilityLevel = null;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName).WithAccessibilityLevel(accessibilityLevel);
        }
        public void TestMethodNameSetEmpty_ThrowsArgumentException()
        {
            // Arrange
            string            methodName    = "Method";
            string            newMethodName = String.Empty;
            SGMethodSignature method        = new SGMethodSignature(methodName);

            // Act
            method.MethodName = newMethodName;
        }
        public void TestMethodNameSetNull_ThrowsArgumentNullException()
        {
            // Arrange
            string            methodName    = "Method";
            string            newMethodName = null;
            SGMethodSignature method        = new SGMethodSignature(methodName);

            // Act
            method.MethodName = newMethodName;
        }
        public void TestMethodCtor_NameWithSpaces_ReplacedWithUnderscores()
        {
            // Arrange
            string methodName = "Some Method Name";

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName);

            // Assert
            Assert.AreEqual(methodName.Replace(" ", "_"), method.MethodName);
        }
        public void TestAccessibilityLevelSetNull_Property_ThrowsArgumentNullException()
        {
            // Arrange
            string methodName = "Method";
            SGAccessibilityLevel accessibilityLevel    = SGAccessibilityLevel.Public;
            SGAccessibilityLevel newAccessibilityLevel = null;
            SGMethodSignature    method = new SGMethodSignature(methodName, accessibilityLevel);

            // Act
            method.AccessibilityLevel = newAccessibilityLevel;
        }
        public void TestIsGenericFlag_FalseWhenNotGeneric()
        {
            // Arrange
            string methodName = "Method";

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName);

            // Assert
            Assert.IsFalse(method.IsGeneric);
        }
        public void TestSetOverrideFlag_PropertySetter()
        {
            // Arrange
            string            methodName = "Method";
            SGMethodSignature method     = new SGMethodSignature(methodName);

            // Act
            method.IsOverride = true;

            // Assert
            Assert.IsTrue(method.IsOverride);
        }
        public void TestMethodCtor_TypedReturnType_InitsFields()
        {
            // Arrange
            string methodName = "Method";
            Type   returnType = typeof(int);

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName, returnType: returnType);

            // Assert
            Assert.AreEqual(returnType.Name, method.ReturnType);
        }
        public void TestMethodCtor_EmptyStringReturnType_SetsToDefault()
        {
            // Arrange
            string methodName = "Method";
            string returnType = String.Empty;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName, returnType: returnType);

            // Assert
            Assert.AreEqual("void", method.ReturnType);
        }
        public void TestIsGenericFlag_TrueWhenGeneric()
        {
            // Arrange
            string methodName      = "Method";
            string genericTypeName = "T";

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName).WithGenericTypeNames(genericTypeName);

            // Assert
            Assert.IsTrue(method.IsGeneric);
        }
        public void TestAccessibilityLevelSet_FluentAPI()
        {
            // Arrange
            string methodName = "Method";
            SGAccessibilityLevel accessibilityLevel = SGAccessibilityLevel.Public;

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName).WithAccessibilityLevel(accessibilityLevel);

            // Assert
            Assert.AreEqual(accessibilityLevel, method.AccessibilityLevel);
        }
        public void TestSetOverrideFlag_FluentAPI()
        {
            // Arrange
            string            methodName = "Method";
            SGMethodSignature method     = new SGMethodSignature(methodName);

            // Act
            method = method.WithIsOverride(true);

            // Assert
            Assert.IsTrue(method.IsOverride);
        }
        public void TestReturnTypeSet_FluentAPI_SystemType()
        {
            // Arrange
            string            methodName    = "Method";
            Type              newReturnType = typeof(int);
            SGMethodSignature method        = new SGMethodSignature(methodName);

            // Act
            method = method.WithReturnType(newReturnType);

            // Assert
            Assert.AreEqual(newReturnType.Name, method.ReturnType);
        }
        public void TestMethodNameSet()
        {
            // Arrange
            string            methodName    = "Method";
            string            newMethodName = "NewMethod";
            SGMethodSignature method        = new SGMethodSignature(methodName);

            // Act
            method.MethodName = newMethodName;

            // Assert
            Assert.AreEqual(newMethodName, method.MethodName);
        }
        public void TestMethodNameSet_WithSpaces_ReplacedWithUnderscores()
        {
            // Arrange
            string            methodName    = "Method";
            string            newMethodName = "New Method Name";
            SGMethodSignature method        = new SGMethodSignature(methodName);

            // Act
            method.MethodName = newMethodName;

            // Assert
            Assert.AreEqual(newMethodName.Replace(" ", "_"), method.MethodName);
        }
        public void TestIsGenericFlag_FalseWhenSetNull()
        {
            // Arrange
            string            methodName      = "Method";
            string            genericTypeName = "T";
            SGMethodSignature method          = new SGMethodSignature(methodName).WithGenericTypeNames(genericTypeName);

            // Act
            method.GenericTypeNames = null;

            // Assert
            Assert.IsFalse(method.IsGeneric);
        }
        public void TestAddGeneric_FluentAPI()
        {
            // Arrange
            string methodName       = "Method";
            string genericTypeName1 = "T";
            string genericTypeName2 = "U";

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName).WithGenericTypeNames(genericTypeName1, genericTypeName2);

            // Assert
            Assert.IsTrue(method.GenericTypeNames.ContainsAll(genericTypeName1, genericTypeName2));
        }
        public void TestReturnTypeSet_FluentAPI()
        {
            // Arrange
            string            methodName    = "Method";
            string            returnType    = "void";
            string            newReturnType = "int";
            SGMethodSignature method        = new SGMethodSignature(methodName, returnType: returnType);

            // Act
            method = method.WithReturnType(newReturnType);

            // Assert
            Assert.AreEqual(newReturnType, method.ReturnType);
        }
        public void TestAccessibilityLevelSet_Property()
        {
            // Arrange
            string methodName = "Method";
            SGAccessibilityLevel accessibilityLevel    = SGAccessibilityLevel.Public;
            SGAccessibilityLevel newAccessibilityLevel = SGAccessibilityLevel.Protected;
            SGMethodSignature    method = new SGMethodSignature(methodName, accessibilityLevel);

            // Act
            method.AccessibilityLevel = newAccessibilityLevel;

            // Assert
            Assert.AreEqual(newAccessibilityLevel, method.AccessibilityLevel);
        }
        public void TestReturnTypeSetNull_Property_DefaultsToVoid()
        {
            // Arrange
            string            methodName    = "Method";
            string            returnType    = "int";
            string            newReturnType = null;
            SGMethodSignature method        = new SGMethodSignature(methodName, returnType: returnType);

            // Act
            method.ReturnType = newReturnType;

            // Assert
            Assert.AreEqual("void", method.ReturnType);
        }
        public void TestAddArguments_FluentAPI()
        {
            // Arrange
            string            methodName = "Method";
            SGArgument        arg1       = new SGArgument("int", "arg1");
            SGArgument        arg2       = new SGArgument("bool", "arg2");
            SGMethodSignature method     = new SGMethodSignature(methodName);

            // Act
            method = method.WithArguments(arg1, arg2);

            // Assert
            Assert.IsTrue(method.Arguments.ContainsAll(arg1, arg2));
        }
        public void TestSetOverrideFlag_PropertyInitializer()
        {
            // Arrange
            string methodName = "Method";

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName)
            {
                IsOverride = true
            };

            // Assert
            Assert.IsTrue(method.IsOverride);
        }
        public void TestReturnTypeSetEmpty_FluentAPI_DefaultsToVoid()
        {
            // Arrange
            string            methodName    = "Method";
            string            returnType    = "int";
            string            newReturnType = String.Empty;
            SGMethodSignature method        = new SGMethodSignature(methodName, returnType: returnType);

            // Act
            method = method.WithReturnType(newReturnType);

            // Assert
            Assert.AreEqual("void", method.ReturnType);
        }
Beispiel #28
0
        public void TestAddMethodSignatures_FluentAPI()
        {
            // Arrange
            string            interfaceName = "IInterface";
            string            methodName1   = "Method1";
            string            methodName2   = "Method2";
            SGInterface       @interface    = new SGInterface(interfaceName);
            SGMethodSignature method1       = new SGMethodSignature(methodName1);
            SGMethodSignature method2       = new SGMethodSignature(methodName2);

            // Act
            @interface = @interface.WithMethodSignatures(method1, method2);

            // Assert
            Assert.IsTrue(@interface.MethodSignatures.ContainsAll(method1, method2));
        }
        public void TestMethodCtor_Defaults_InitsFields()
        {
            // Arrange
            string methodName = "Method";

            // Act
            SGMethodSignature method = new SGMethodSignature(methodName);

            // Assert
            Assert.AreEqual(methodName, method.MethodName);
            Assert.AreEqual(SGAccessibilityLevel.Private, method.AccessibilityLevel);
            Assert.AreEqual("void", method.ReturnType);
            Assert.AreEqual(false, method.IsStatic);
            Assert.AreEqual(false, method.IsAsync);
            Assert.AreEqual(false, method.IsOverride);
        }
        public void TestSetArgumentsNull_EmptyList()
        {
            // Arrange
            string            methodName = "Method";
            SGArgument        arg1       = new SGArgument("int", "arg1");
            SGArgument        arg2       = new SGArgument("bool", "arg2");
            SGMethodSignature method     = new SGMethodSignature(methodName)
            {
                Arguments = { arg1, arg2 }
            };


            // Act
            method.Arguments = null;

            // Assert
            Assert.IsNotNull(method.Arguments);
            Assert.AreEqual(0, method.Arguments.Count);
        }