Ejemplo n.º 1
0
        /// <summary>
        ///     Now try to understand this scenario, to call this method we need to pass these parameters.
        ///     Now there is no way to understand what these parameters are or how these parameters needs to be passed.
        ///     To find that we need to find Invoking Expression of "BusinessMethodDependency" and detects all it's parameter
        ///     initialize recursively.
        ///     To find dependencies we need to find the method "BusinessMethod" programmatically not hard coded fashion.
        ///     To test this method, we need to 2 setup methods
        ///         1.  Setup of Parameters from "BusinessMethod".
        ///         2.  Setup of inner properties (IntThrows, IntStaticThrows, PubliceByteProp, PublicStringProp), fields,
        ///         methods (ArgumentNullException, SomethingDynamicComplex, ThrowException,
        ///         BusinessLogicExampleOfSameplemethod, BusinessLogicExampleOfSamepleMethodString,
        ///         SampleMethod, SampleMethodString, ThrowException("Needs to be covered" + intX + y))
        /// </summary>
        /// <param name="somethingComplex"></param>
        /// <param name="sample"></param>
        /// <param name="classWithProperties"></param>
        /// <param name="classWithMethods"></param>
        /// <param name="required"></param>
        /// <param name="prep"></param>
        public void BusinessMethodDependency(dynamic somethingComplex,
                                             dynamic sample,
                                             ClassWithProperties classWithProperties,
                                             ClassWithMethods classWithMethods,
                                             IRequired required,
                                             IRequiredPrep prep)
        {
            Utility.ArgumentNullException("Testing"); // this method needs to be Faked
            somethingComplex.SomethingDynamicComplex();
            var x = classWithProperties.PubliceByteProp;
            var y = classWithProperties.PublicStringProp;

            Utility.ThrowException(); // this method needs to be Faked

            var classWithBusinessLogic = new ClassWithBusinessLogic(required);

            classWithBusinessLogic.BusinessLogicExampleOfSameplemethod();
            y = classWithBusinessLogic.BusinessLogicExampleOfSamepleMethodString() + x;

            var classWithBusinessLogic2 = new ClassWithBusinessLogic2();

            classWithBusinessLogic2.SampleMethodString();

            var requiredConcrete = new Required();

            requiredConcrete.SampleMethod(prep);
            requiredConcrete.SampleMethodString(prep);

            var intX = (int)sample + 5 + IntThrows + IntStaticThrows;

            Utility.ThrowException("Needs to be covered" + intX + y); // this method needs to be Faked and covered
        }
Ejemplo n.º 2
0
        public void CallZeroParameterStaticMethod()
        {
            Expression <Action> lambda = () => ClassWithMethods.ZeroParameterStaticMethod();
            var methodCallExpression   = (MethodCallExpression)lambda.Body;

            QUnit.AreEqual(methodCallExpression.Method.Name, "ZeroParameterStaticMethod");
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     To test this method we need to find invocation expression of "BusinessMethod" in "BusinessMethodInitial2" and
        ///     "BusinessMethodInitial" and create two test method accordingly.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="somethingComplex"></param>
        /// <param name="required"></param>
        public void BusinessMethod(int x, dynamic somethingComplex, IRequired required)
        {
            var prep = new RequiredPrep();
            var classWithProperties = new ClassWithProperties(required);
            var classWithMethods    = new ClassWithMethods(required);

            BusinessMethodDependency(somethingComplex, x, classWithProperties, classWithMethods, required, prep);
        }
Ejemplo n.º 4
0
 public void CallZeroParameterInstanceMethod()
 {
     var instance = new ClassWithMethods();
     Expression<Action> lambda = () => instance.ZeroParameterInstanceMethod();
     var methodCallExpression = (MethodCallExpression)lambda.Body;
     AssertEquals(methodCallExpression.Method.Name, "ZeroParameterInstanceMethod");
     var target = (ConstantExpression)methodCallExpression.Object;
     AssertEquals(target.Value, instance);
 }         
Ejemplo n.º 5
0
        public void CallOneParameterStaticMethod()
        {
            Expression <Action> lambda = () => ClassWithMethods.OneParameterStaticMethod("foo");
            var methodCallExpression   = (MethodCallExpression)lambda.Body;

            QUnit.AreEqual(methodCallExpression.Method.Name, "OneParameterStaticMethod");
            var argument = (ConstantExpression)methodCallExpression.Arguments[0];

            QUnit.AreEqual(argument.Value, "foo");
        }
Ejemplo n.º 6
0
        public void CallingPublicMethodFromProjectWithoutAccess()
        {
            // Arrange
            var sut = new ClassWithMethods();

            // Act
            var greeting = sut.PublicMethod("human");

            // Assert
            Assert.AreEqual(greeting, "Hello human");
        }
Ejemplo n.º 7
0
        public void CallingInternalMethodFromProjectWithAccess()
        {
            // Arrange
            var sut = new ClassWithMethods();

            // Act
            var greeting = sut.InternalMethod("human");

            // Assert
            Assert.AreEqual(greeting, "Howdy human");
        }
Ejemplo n.º 8
0
        public void CallZeroParameterInstanceMethod()
        {
            var instance = new ClassWithMethods();
            Expression <Action> lambda = () => instance.ZeroParameterInstanceMethod();
            var methodCallExpression   = (MethodCallExpression)lambda.Body;

            QUnit.AreEqual(methodCallExpression.Method.Name, "ZeroParameterInstanceMethod");
            var target = (ConstantExpression)methodCallExpression.Object;

            QUnit.AreEqual(target.Value, instance);
        }
Ejemplo n.º 9
0
        public void Should_create_MethodAccessor_for_method()
        {
            // Arrange
            var method = new ClassWithMethods().Method("InvariantMethod");

            // Act
            IMethodAccessor accessor = sut.Create(method);

            // Assert
            accessor.Should().NotBeNull();
        }
        public void GetString_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classWithMethods = new ClassWithMethods(TODO, TODO);

            // Act
            var result = classWithMethods.GetString();

            // Assert
            Assert.Fail();
        }
        public void GetFastMethodInvoker_ForGenericMethodTwoParameters()
        {
            var instance = new ClassWithMethods();
            var invoker  = _generator.GetFastMethodInvoker(
                instance.GetType(),
                "Count", new[] { typeof(int), typeof(string) },
                new[] { typeof(IEnumerable <int>), typeof(string) }, BindingFlags.Public | BindingFlags.Instance);

            var output = invoker(instance, new object[] { new[] { 3, 1, 2 }, "asdf" });

            Assert.That(output, Is.EqualTo(7));
        }
        public void GetFastMethodInvoker_ForStaticGenericMethod()
        {
            var instance = new ClassWithMethods();
            var invoker  = _generator.GetFastMethodInvoker(
                instance.GetType(),
                "Count", new[] { typeof(int) },
                new[] { typeof(IEnumerable <int>), typeof(int) }, BindingFlags.Public | BindingFlags.Static);

            var output = invoker(instance, new object[] { new[] { 3, 1, 2 }, 1 });

            Assert.That(output, Is.EqualTo(4));
        }
        public void GetFastMethodInvoker_ForGenericMethodTwoParameters()
        {
            var instance = new ClassWithMethods ();
              var invoker = _generator.GetFastMethodInvoker (
              instance.GetType (),
              "Count", new[] { typeof (int), typeof(string) },
              new[] { typeof (IEnumerable<int>), typeof (string) }, BindingFlags.Public | BindingFlags.Instance);

              var output = invoker (instance, new object[] { new[] { 3, 1, 2 }, "asdf" });

              Assert.That (output, Is.EqualTo (7));
        }
        public void AttributedMethod_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var    classWithMethods = new ClassWithMethods(TODO, TODO);
            string test             = null;

            // Act
            classWithMethods.AttributedMethod(
                test);

            // Assert
            Assert.Fail();
        }
        public void GetMethodDelegate_NestedProtectedInterface_ExplicitInterfaceMethod()
        {
            Type declaringType = typeof(IProtectedInterfaceWithMethods);
            var  methodInfo    = declaringType.GetMethod("ExplicitInterfaceMethod", BindingFlags.Public | BindingFlags.Instance);

            var @delegate = (Func <object, string, string>)DynamicMethodBasedMethodCallerFactory.CreateMethodCallerDelegate(
                methodInfo, typeof(Func <object, string, string>));

            var obj = new ClassWithMethods();

            Assert.That(@delegate(obj, "TheValue"), Is.EqualTo("TheValue"));
            Assert.That(obj.InstanceValue, Is.EqualTo("TheValue"));
        }
        public void GetMethodDelegate_NonPublicInstanceMethod()
        {
            Type declaringType = typeof(ClassWithMethods);
            var  methodInfo    = declaringType.GetMethod("NonPublicInstanceMethod", BindingFlags.NonPublic | BindingFlags.Instance);

            var @delegate = (Func <ClassWithMethods, string, string>)DynamicMethodBasedMethodCallerFactory.CreateMethodCallerDelegate(
                methodInfo, typeof(Func <ClassWithMethods, string, string>));

            var obj = new ClassWithMethods();

            Assert.That(@delegate(obj, "TheValue"), Is.EqualTo("TheValue"));
            Assert.That(obj.InstanceValue, Is.EqualTo("TheValue"));
        }
        public void GetIntMultipleSignatures_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var    classWithMethods = new ClassWithMethods(TODO, TODO);
            string bla = null;

            // Act
            var result = classWithMethods.GetIntMultipleSignatures(
                bla);

            // Assert
            Assert.Fail();
        }
        public void MethodWithNamespaceQualifiedArgument_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var         classWithMethods = new ClassWithMethods(TODO, TODO);
            IInterface3 myInterface      = null;

            // Act
            var result = classWithMethods.MethodWithNamespaceQualifiedArgument(
                myInterface);

            // Assert
            Assert.Fail();
        }
        public void MethodWithNullableArgument_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classWithMethods = new ClassWithMethods(TODO, TODO);
            int?argument         = null;

            // Act
            var result = classWithMethods.MethodWithNullableArgument(
                argument);

            // Assert
            Assert.Fail();
        }
        public void DoEnum_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var  classWithMethods = new ClassWithMethods(TODO, TODO);
            Cucu cucuENum         = default(global::UnitBoilerplate.Sandbox.Classes.Cases.Cucu);

            // Act
            classWithMethods.DoEnum(
                cucuENum);

            // Assert
            Assert.Fail();
        }
        public void DoRef_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classWithMethods    = this.CreateClassWithMethods();
            ClassWithMethods refArg = null;

            // Act
            classWithMethods.DoRef(
                ref refArg);

            // Assert
            Assert.Fail();
        }
        public void GetIntMultipleSignatures_StateUnderTest_ExpectedBehavior1()
        {
            // Arrange
            var         classWithMethods = new ClassWithMethods(TODO, TODO);
            IInterface4 interface4       = null;

            // Act
            var result = classWithMethods.GetIntMultipleSignatures(
                interface4);

            // Assert
            Assert.Fail();
        }
        public void DoRef_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest       = this.CreateClassWithMethods();
            ClassWithMethods refArg = TODO;

            // Act
            unitUnderTest.DoRef(
                ref refArg);

            // Assert
            Assert.Fail();
        }
Ejemplo n.º 24
0
        public void DoEnum_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var  unitUnderTest = new ClassWithMethods(TODO, TODO);
            Cucu cucuENum      = TODO;

            // Act
            unitUnderTest.DoEnum(
                cucuENum);

            // Assert
            Assert.Fail();
        }
        public void DoRef_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classWithMethods    = this.CreateClassWithMethods();
            ClassWithMethods refArg = null;

            // Act
            classWithMethods.DoRef(
                ref refArg);

            // Assert
            Assert.True(false);
            this.mockRepository.VerifyAll();
        }
Ejemplo n.º 26
0
        public async Task GetParamsClass2D_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var unitUnderTest = new ClassWithMethods(TODO, TODO);

            ClassWithMethods[][] values = TODO;

            // Act
            var result = await unitUnderTest.GetParamsClass2D(
                values);

            // Assert
            Assert.Fail();
        }
Ejemplo n.º 27
0
        public void DoRef_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var mocker              = new AutoMoqer();
            var classWithMethods    = mocker.Create <ClassWithMethods>();
            ClassWithMethods refArg = null;

            // Act
            classWithMethods.DoRef(
                ref refArg);

            // Assert
            Assert.Fail();
        }
        public async Task GetWithClass4D_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classWithMethods = new ClassWithMethods(TODO, TODO);

            ClassWithMethods[][][][] values = null;

            // Act
            var result = await classWithMethods.GetWithClass4D(
                values);

            // Assert
            Assert.Fail();
        }
        public void GetOut_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var  classWithMethods = new ClassWithMethods(TODO, TODO);
            bool fufu             = false;
            int  bubu             = 0;

            // Act
            var result = classWithMethods.GetOut(
                fufu,
                out bubu);

            // Assert
            Assert.Fail();
        }
Ejemplo n.º 30
0
        public async Task GetTaskNoAsync_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var         unitUnderTest = new ClassWithMethods(TODO, TODO);
            IInterface3 interface3    = TODO;
            DateTime    time          = TODO;

            // Act
            await unitUnderTest.GetTaskNoAsync(
                interface3,
                time);

            // Assert
            Assert.Fail();
        }
        public async Task GetTaskNoAsync_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var         classWithMethods = new ClassWithMethods(TODO, TODO);
            IInterface3 interface3       = null;
            DateTime    time             = default(global::System.DateTime);

            // Act
            await classWithMethods.GetTaskNoAsync(
                interface3,
                time);

            // Assert
            Assert.Fail();
        }
        public void EmitMethodBody_ForReferenceTypeInstance_InstanceTypesMatch()
        {
            Type declaringType = typeof(ClassWithMethods);
            var  methodInfo    = declaringType.GetMethod("InstanceMethodWithReferenceTypeReturnValue", BindingFlags.Public | BindingFlags.Instance);

            Type returnType = typeof(object);

            Type[] parameterTypes = new[] { typeof(ClassWithMethods) };
            var    method         = GetWrapperMethodFromEmitter(MethodInfo.GetCurrentMethod(), parameterTypes, returnType, methodInfo);

            var obj = new ClassWithMethods {
                InstanceReferenceTypeValue = new SimpleReferenceType()
            };

            Assert.That(BuildTypeAndInvokeMethod(method, obj), Is.SameAs(obj.InstanceReferenceTypeValue));
        }
        public void GetFastMethodInvoker_ForStaticGenericMethod()
        {
            var instance = new ClassWithMethods();
              var invoker = _generator.GetFastMethodInvoker (
              instance.GetType(),
              "Count", new[] { typeof(int) },
              new[] { typeof (IEnumerable<int>), typeof(int) }, BindingFlags.Public | BindingFlags.Static);

              var output = invoker(instance, new object[] { new[] { 3, 1, 2 }, 1 });

              Assert.That (output, Is.EqualTo (4));
        }
Ejemplo n.º 34
0
 public void Method(ClassWithMethods a) {}