Beispiel #1
0
        /// <summary>
        /// Runs a test cycle.
        /// </summary>
        /// <param name="businessLogic">The business logic.</param>
        /// <param name="methodsDescription">The methods description.</param>
        /// <param name="indexToRun">The index to run.</param>
        /// <returns>The index of the next method to run.</returns>
        public int RunCycle(ExtensionRunnerBusinessLogic businessLogic, List <FullMethodDescription> methodsDescription, int indexToRun)
        {
            int runningIndex = indexToRun;

            if (runningIndex == -1)
            {
                runningIndex++;
                businessLogic.StartDelayTime = businessLogic.DateTimeNow();
            }

            if (runningIndex < methodsDescription.Count)
            {
                bool performed = businessLogic.InvokeMethod(businessLogic, methodsDescription[runningIndex], businessLogic.IntegrationTestGameObject);
                if (performed)
                {
                    runningIndex++;
                    businessLogic.StartDelayTime = businessLogic.DateTimeNow();
                }
            }
            else
            {
                businessLogic.InvokeAssertionSuccessful(businessLogic.IntegrationTestGameObject);
            }

            return(runningIndex);
        }
        public void InvokeMethod_Should_ReturnTrue_Given_TheInvokedMethodReturnsAAssertionResultSuccessfulObject()
        {
            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);

            Component  component                   = Substitute.For <Component>();
            MethodInfo mockedMethodInfo            = Substitute.For <MethodInfo>();
            object     methodInvokeAssertionResult = new AssertionResultSuccessful();

            object[] parameters = new object[0];
            mockedMethodInfo.Invoke(component, parameters).Returns(methodInvokeAssertionResult);
            FullMethodDescription methodDescription = Substitute.For <FullMethodDescription>();

            methodDescription.Method = mockedMethodInfo;
            methodDescription.GetFullName().Returns <string>("component.method");

            ExtensionRunnerBusinessLogic mockedBusinessLogic = Substitute.For <ExtensionRunnerBusinessLogic>(gameObject);

            DateTime firstNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.StartDelayTime = firstNowDatetime;
            DateTime secondNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.DateTimeNow().Returns <DateTime>(secondNowDatetime);
            mockedBusinessLogic.GetParametersValues(methodDescription).Returns <object[]>(parameters);
            mockedMethodInfo.Invoke(component, parameters).Returns(methodInvokeAssertionResult);
            methodDescription.Method = mockedMethodInfo;
            bool result = businessLogic.InvokeMethod(mockedBusinessLogic, methodDescription, gameObject);

            Assert.IsTrue(result, "The method InvokeMethod doesn't return the right state");
        }
        public void RunCycle_ShouldPerFormTheExpectedCalls_Given_ItIsInvokedAfterTheLastMethodInTheList()
        {
            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);

            ExtensionRunnerBusinessLogicTestFirstStaticComponent component = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestFirstStaticComponent>();

            Component[] components = new Component[1] {
                component
            };

            List <FullMethodDescription> methodsDescription = businessLogic.GetAllMethodsDescriptions(components, null, null, null, null, null, null);

            ExtensionRunnerBusinessLogic mockedBusinessLogic = Substitute.For <ExtensionRunnerBusinessLogic>(gameObject);

            mockedBusinessLogic.InvokeMethod(businessLogic, methodsDescription[0], gameObject).Returns <bool>(true);

            int indexToRun = 8;

            businessLogic.RunCycle(mockedBusinessLogic, methodsDescription, indexToRun);
            Received.InOrder(() =>
            {
                businessLogic.InvokeAssertionSuccessful(gameObject);
            });
        }
        public void RunCycle_Should_PerformTheExpectedCallsForTheFirstMethodInTheListAndReturnTheIndexForTheNextMethod_Given_TheMethodHasNotAConfiguredDelay()
        {
            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);

            Component  component                   = Substitute.For <Component>();
            MethodInfo mockedMethodInfo            = Substitute.For <MethodInfo>();
            object     methodInvokeAssertionResult = new AssertionResultSuccessful();

            object[] parameters = new object[0];
            mockedMethodInfo.Invoke(component, parameters).Returns(methodInvokeAssertionResult);
            FullMethodDescription methodDescription = Substitute.For <FullMethodDescription>();

            methodDescription.Method = mockedMethodInfo;
            methodDescription.GetFullName().Returns <string>("component.method");

            ExtensionRunnerBusinessLogic mockedBusinessLogic = Substitute.For <ExtensionRunnerBusinessLogic>(gameObject);

            mockedBusinessLogic.IntegrationTestGameObject = gameObject;

            List <FullMethodDescription> methodsDescription = new List <FullMethodDescription>();

            methodsDescription.Add(methodDescription);
            methodsDescription.Add(Substitute.For <FullMethodDescription>());

            DateTime firstNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.DateTimeNow().Returns <DateTime>(firstNowDatetime);
            mockedBusinessLogic.InvokeMethod(mockedBusinessLogic, methodDescription, gameObject).Returns <bool>(true);

            int indexToRun    = -1;
            int newIndexToRun = businessLogic.RunCycle(mockedBusinessLogic, methodsDescription, indexToRun);

            Received.InOrder(() =>
            {
                mockedBusinessLogic.DateTimeNow();
                mockedBusinessLogic.InvokeMethod(mockedBusinessLogic, methodDescription, gameObject);
                mockedBusinessLogic.DateTimeNow();
            });
            Assert.AreEqual(1, newIndexToRun, "The method RunCycle doesn't return the right value");
        }
        public void InvokeMethod_Should_PerformTheExpectedCallsAndReturnFalse_Given_TheInvokedMethodReturnsAAssertionResultRetryObject()
        {
            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);

            Component        component                   = Substitute.For <Component>();
            MethodInfo       mockedMethodInfo            = Substitute.For <MethodInfo>();
            string           errorText                   = "message";
            IAssertionResult methodInvokeAssertionResult = new AssertionResultRetry(errorText);

            object[] parameters = new object[0];
            mockedMethodInfo.Invoke(component, parameters).Returns(methodInvokeAssertionResult);
            FullMethodDescription methodDescription = Substitute.For <FullMethodDescription>();

            methodDescription.Method = mockedMethodInfo;
            methodDescription.GetFullName().Returns <string>("component.method");
            ExtensionRunnerBusinessLogic mockedBusinessLogic = Substitute.For <ExtensionRunnerBusinessLogic>(gameObject);

            DateTime firstNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.StartDelayTime = firstNowDatetime;
            DateTime secondNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.DateTimeNow().Returns <DateTime>(secondNowDatetime);

            mockedBusinessLogic.GetParametersValues(methodDescription).Returns <object[]>(parameters);
            string scenarioText                  = "scenarioText";
            string bddMethodLocation             = "bddMethodLocation";
            List <FullMethodDescription> methods = new List <FullMethodDescription>();

            methods.Add(methodDescription);

            mockedBusinessLogic.MethodsDescription = methods;
            mockedBusinessLogic.GetScenarioTextForErrorInSpecificMethod(methods, methodDescription).Returns(scenarioText);
            mockedBusinessLogic.GetbddMethodLocationForSpecificMethod(methods, methodDescription).Returns(bddMethodLocation);

            bool result = businessLogic.InvokeMethod(mockedBusinessLogic, methodDescription, gameObject);

            Received.InOrder(() =>
            {
                mockedBusinessLogic.DateTimeNow();
                mockedBusinessLogic.DateTimeNow();
                mockedBusinessLogic.GetParametersValues(methodDescription);
                mockedMethodInfo.Invoke(component, parameters);
                mockedBusinessLogic.DateTimeNow();

                mockedBusinessLogic.InvokeAssertionFailed(errorText, scenarioText, bddMethodLocation, gameObject);
            });
            Assert.IsFalse(result, "The method InvokeMethod doesn't return the right state");
        }
        public void InvokeMethod_Should_PerformTheExpectedCallsAndReturnFalse_Given_TheInvokedMethodHasAReachedDelayAndReturnsAAssertionResultRetryObject()
        {
            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);

            Component  component                   = Substitute.For <Component>();
            MethodInfo mockedMethodInfo            = Substitute.For <MethodInfo>();
            object     methodInvokeAssertionResult = new AssertionResultRetry("message");

            object[] parameters = new object[0];
            mockedMethodInfo.Invoke(component, parameters).Returns(methodInvokeAssertionResult);
            FullMethodDescription methodDescription = Substitute.For <FullMethodDescription>();

            methodDescription.Method = mockedMethodInfo;
            methodDescription.GetFullName().Returns <string>("component.method");
            methodDescription.TimeOut = 1000;
            ExtensionRunnerBusinessLogic mockedBusinessLogic = Substitute.For <ExtensionRunnerBusinessLogic>(gameObject);

            DateTime firstNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.StartDelayTime = firstNowDatetime;
            DateTime secondNowDatetime = new DateTime(2017, 05, 01, 00, 00, 00, 000);

            mockedBusinessLogic.DateTimeNow().Returns <DateTime>(secondNowDatetime);

            mockedBusinessLogic.GetParametersValues(methodDescription).Returns <object[]>(parameters);

            bool result = businessLogic.InvokeMethod(mockedBusinessLogic, methodDescription, gameObject);

            Received.InOrder(() =>
            {
                mockedBusinessLogic.DateTimeNow();
                mockedBusinessLogic.DateTimeNow();
                mockedBusinessLogic.GetParametersValues(methodDescription);
                mockedMethodInfo.Invoke(component, parameters);
                mockedBusinessLogic.DateTimeNow();
            });
            Assert.IsFalse(result, "The method InvokeMethod doesn't return the right state");
        }