コード例 #1
0
        public void ShouldRegisterScreenshotWriterFromReference(string stepText, string expected)
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();

            var mockOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                             classInstanceManager,
                                                             new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                             new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                mockOrchestrator, new TableFormatter(assemblyLoader, activatorWrapper));

            var message = new ExecuteStepRequest
            {
                ParsedStepText = stepText,
                ActualStepText = stepText
            };

            var result = executeStepProcessor.Process(message);
            var protoExecutionResult = result.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Assert.AreEqual(protoExecutionResult.ScreenshotFiles[0], expected);
        }
コード例 #2
0
        public void ShouldRegisterScreenshotWriterFromReference(string referenceType, string stepText, string expected)
        {
            Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", TestUtils.GetIntegrationTestSampleDirectory(referenceType));
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var path                  = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var assemblyLoader        = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager  = new ThreadLocal <object>(() => assemblyLoader.GetClassInstanceManager()).Value;
            var executionInfoMapper   = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                  new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                executionOrchestrator, new TableFormatter(assemblyLoader, activatorWrapper));

            var message = new ExecuteStepRequest
            {
                ParsedStepText = stepText,
                ActualStepText = stepText
            };

            var result = executeStepProcessor.Process(message);
            var protoExecutionResult = result.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Console.WriteLine(protoExecutionResult.ScreenshotFiles[0]);
            Assert.AreEqual(protoExecutionResult.ScreenshotFiles[0], expected);
        }
コード例 #3
0
        public void ShouldCaptureScreenshotOnFailure()
        {
            const string parameterizedStepText = "I throw a serializable exception";
            const string stepText          = "I throw a serializable exception";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                                new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper);
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();

            var mockOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                             classInstanceManager,
                                                             new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                             new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                mockOrchestrator, new TableFormatter(assemblyLoader, activatorWrapper));


            var message = new ExecuteStepRequest
            {
                ParsedStepText = parameterizedStepText,
                ActualStepText = stepText
            };

            var result = executeStepProcessor.Process(message);
            var protoExecutionResult = result.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Assert.IsTrue(protoExecutionResult.Failed);
            Assert.AreEqual(protoExecutionResult.FailureScreenshotFile, "screenshot.png");
        }
コード例 #4
0
        public void ShouldCreateTableFromTargetType()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper, activatorWrapper, new StepRegistry());
            var classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                 new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
            var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Step that takes a table {}");
            var table       = new Table(new List <string> {
                "foo", "bar"
            });

            table.AddRow(new List <string> {
                "foorow1", "barrow1"
            });
            table.AddRow(new List <string> {
                "foorow2", "barrow2"
            });

            var executionResult = orchestrator.ExecuteStep(gaugeMethod, SerializeTable(table));

            Assert.False(executionResult.Failed);
        }
コード例 #5
0
        public void ShouldCaptureScreenshotOnFailure()
        {
            const string stepText          = "I throw a serializable exception";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          path                 = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var          assemblyLoader       = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var          classInstanceManager = new ThreadLocal <object>(() => assemblyLoader.GetClassInstanceManager());
            var          executionInfoMapper  = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var          orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                          classInstanceManager,
                                                                          new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                          new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                orchestrator, new TableFormatter(assemblyLoader, activatorWrapper));


            var message = new ExecuteStepRequest
            {
                ParsedStepText = stepText,
                ActualStepText = stepText
            };

            var result = executeStepProcessor.Process(message);
            var protoExecutionResult = result.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Assert.IsTrue(protoExecutionResult.Failed);
            Assert.AreEqual("screenshot.png", protoExecutionResult.FailureScreenshotFile);
        }
コード例 #6
0
        public IMessageProcessor GetProcessor(Message.Types.MessageType messageType, bool scan = false)
        {
            if (!scan)
            {
                return(!_messageProcessorsDictionary.ContainsKey(messageType)
                    ? new DefaultProcessor()
                    : _messageProcessorsDictionary[messageType]);
            }
            var activatorWrapper  = new ActivatorWrapper();
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(),
                                                       reflectionWrapper);

            _stepRegistry = assemblyLoader.GetStepRegistry();
            var tableFormatter       = new TableFormatter(assemblyLoader, activatorWrapper);
            var classInstanceManager = assemblyLoader.GetClassInstanceManager(activatorWrapper);

            InitializeExecutionMessageHandlers(reflectionWrapper, assemblyLoader, activatorWrapper, tableFormatter,
                                               classInstanceManager);

            return(!_messageProcessorsDictionary.ContainsKey(messageType)
                ? new DefaultProcessor()
                : _messageProcessorsDictionary[messageType]);
        }
コード例 #7
0
        private void InitializeExecutionMessageHandlers()
        {
            var activatorWrapper  = new ActivatorWrapper();
            var reflectionWrapper = new ReflectionWrapper();
            var assemblies        = new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), assemblies, reflectionWrapper, activatorWrapper);

            _stepRegistry = assemblyLoader.GetStepRegistry();
            var tableFormatter        = new TableFormatter(assemblyLoader, activatorWrapper);
            var classInstanceManager  = assemblyLoader.GetClassInstanceManager();
            var executionOrchestrator = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                  classInstanceManager,
                                                                  new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                  new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            this.executionStartingProcessor         = new ExecutionStartingProcessor(executionOrchestrator);
            this.executionEndingProcessor           = new ExecutionEndingProcessor(executionOrchestrator);
            this.specExecutionStartingProcessor     = new SpecExecutionStartingProcessor(executionOrchestrator);
            this.specExecutionEndingProcessor       = new SpecExecutionEndingProcessor(executionOrchestrator);
            this.scenarioExecutionStartingProcessor = new ScenarioExecutionStartingProcessor(executionOrchestrator);
            this.scenarioExecutionEndingProcessor   = new ScenarioExecutionEndingProcessor(executionOrchestrator);
            this.stepExecutionStartingProcessor     = new StepExecutionStartingProcessor(executionOrchestrator);
            this.stepExecutionEndingProcessor       = new StepExecutionEndingProcessor(executionOrchestrator);
            this.executeStepProcessor           = new ExecuteStepProcessor(_stepRegistry, executionOrchestrator, tableFormatter);
            this.scenarioDataStoreInitProcessor = new ScenarioDataStoreInitProcessor(assemblyLoader);
            this.specDataStoreInitProcessor     = new SpecDataStoreInitProcessor(assemblyLoader);
            this.suiteDataStoreInitProcessor    = new SuiteDataStoreInitProcessor(assemblyLoader);
        }
コード例 #8
0
        public void MonoNamingConventionTests()
        {
            // check that mono naming strategy is recognized
            var name = ReflectionWrapper.BuildFromField(string.Empty, "<autofield>", typeof(int), 2, new ClassMemberCriteria(BindingFlags.Public));

            Check.That(name.MemberLongName).IsEqualTo("autofield");
        }
コード例 #9
0
        /// <summary>
        /// Checks if an object is an instance of a specified type.
        /// </summary>
        /// <param name="check">checker logic object</param>
        /// <param name="type">expected type</param>
        /// <typeparam name="T">type of checked object</typeparam>
        /// <returns>A check link</returns>
        public static ICheckLink <ICheck <T> > IsInstanceOfType <T>(this ICheck <T> check, Type type)
        {
            ExtensibilityHelper.BeginCheck(check)
            .Analyze((sut, test) =>
            {
                var reflectionSut = sut as ReflectionWrapper;
                if (reflectionSut != null)
                {
                    var expectedWrapper = ReflectionWrapper.BuildFromType(type, reflectionSut.Criteria);
                    expectedWrapper.MapFields(reflectionSut, 1, (expected, actual, depth) =>
                    {
                        if (actual != null && expected != null && actual.ValueType != expected.ValueType)
                        {
                            if (actual.ValueType.IsPrimitive() || expected.ValueType.IsPrimitive())
                            {
                                test.GetSutProperty(_ => actual.Value, actual.MemberLabel)
                                .Fails("The {0} is of a different type than the {1}.")
                                .ExpectingType(expected.ValueType, "", "");
                                return(false);
                            }

                            return(true);
                        }

                        if (actual != null && expected != null && expected.ValueType == actual.ValueType)
                        {
                            return(false);
                        }

                        if (actual == null)
                        {
                            test.GetSutProperty(_ => expectedWrapper.Value, expected.MemberLabel)
                            .Expecting(expected)
                            .Fails("The {1} is absent from the {0}.", MessageOption.NoCheckedBlock);
                        }
                        else
                        {
                            test.GetSutProperty(_ => actual, actual.MemberLabel.DoubleCurlyBraces())
                            .Fails("The {0} is absent from the {1}.");
                        }
                        return(false);
                    });
                }
                else if (typeof(T).IsNullable())
                {
                    test.FailsIf(sut2 => typeof(T) != type || (sut2 == null && !typeof(T).IsNullable()),
                                 $"The {{0}} is not an instance of [{type.ToStringProperlyFormatted()}].", MessageOption.WithType);
                }
                else
                {
                    test.FailsIf(sut2 => sut2.GetTypeWithoutThrowingException() != type,
                                 $"The {{0}} is not an instance of [{type.ToStringProperlyFormatted()}].", sut != null ? MessageOption.WithType : MessageOption.None);
                }
            })
            .ExpectingType(type, "", "different from")
            .Negates($"The {{0}} is an instance of [{type.ToStringProperlyFormatted()}] whereas it must not.", MessageOption.WithType)
            .EndCheck();
            return(ExtensibilityHelper.BuildCheckLink(check));
        }
コード例 #10
0
        public void HashCodeIsConsistent()
        {
            var toto = new { entier = 2, lettre = 'b', sub = new { sub = (object)null } };
            var sut  = ReflectionWrapper.BuildFromInstance(toto.GetType(), toto,
                                                           new Criteria(BindingFlags.Instance | BindingFlags.NonPublic, true, true));

            Check.That(sut.GetHashCode()).IsEqualTo(147721457);
        }
コード例 #11
0
        public void ShouldExecuteMethodFromRequest()
        {
            const string parameterizedStepText = "Step that takes a table {}";
            const string stepText          = "Step that takes a table <table>";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                                new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var classInstanceManager = assemblyLoader.GetClassInstanceManager(activatorWrapper);
            var mockOrchestrator     = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader, activatorWrapper,
                                                                 classInstanceManager,
                                                                 new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager),
                                                                 new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                mockOrchestrator, new TableFormatter(assemblyLoader, activatorWrapper));

            var protoTable = new ProtoTable
            {
                Headers = new ProtoTableRow
                {
                    Cells = { "foo", "bar" }
                },
                Rows =
                {
                    new ProtoTableRow
                    {
                        Cells ={ "foorow1",             "foorow2" }
                    }
                }
            };
            var message = new Message
            {
                MessageId          = 1234,
                MessageType        = Message.Types.MessageType.ExecuteStep,
                ExecuteStepRequest = new ExecuteStepRequest
                {
                    ParsedStepText = parameterizedStepText,
                    ActualStepText = stepText,
                    Parameters     =
                    {
                        new Parameter
                        {
                            Name          = "table",
                            ParameterType = Parameter.Types.ParameterType.Table,
                            Table         = protoTable
                        }
                    }
                }
            };
            var result = executeStepProcessor.Process(message);

            AssertRunnerDomainDidNotLoadUsersAssembly();
            var protoExecutionResult = result.ExecutionStatusResponse.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Assert.IsFalse(protoExecutionResult.Failed);
        }
コード例 #12
0
        /// <summary>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public static IMembersSelection Considering <T>(this ICheck <T> check)
        {
            var checker       = ExtensibilityHelper.ExtractChecker(check);
            var fieldsWrapper = ReflectionWrapper.BuildFromInstance(checker.Value?.GetType() ?? typeof(T), checker.Value,
                                                                    new Criteria(BindingFlags.Instance));
            var checkWithConsidering = new CheckWithConsidering(fieldsWrapper, checker.Negated);

            return(checkWithConsidering);
        }
コード例 #13
0
        /// <summary>
        ///     Checks that the actual actualValue doesn't have all fields equal to the expected actualValue ones.
        /// </summary>
        /// <typeparam name="T">
        ///     Type of the checked actualValue.
        /// </typeparam>
        /// <param name="check">
        ///     The fluent check to be extended.
        /// </param>
        /// <param name="expected">
        ///     The expected actualValue.
        /// </param>
        /// <returns>
        ///     A check link.
        /// </returns>
        /// <exception cref="FluentCheckException">
        ///     The actual actualValue has all fields equal to the expected actualValue ones.
        /// </exception>
        /// <remarks>
        ///     The comparison is done field by field.
        /// </remarks>
        public static ICheckLink <ICheck <T> > HasNotFieldsWithSameValues <T>(this ICheck <T> check, object expected)
        {
            var checker       = ExtensibilityHelper.ExtractChecker(check);
            var fieldsWrapper = ReflectionWrapper.BuildFromInstance(typeof(T), checker.Value,
                                                                    new Criteria(BindingFlags.Instance));
            var checkWithConsidering = new CheckWithConsidering(fieldsWrapper, checker.Negated).All.Fields;

            ReflectionWrapperChecks.FieldEqualTest(checkWithConsidering, expected, false);
            return(ExtensibilityHelper.BuildCheckLink(check));
        }
コード例 #14
0
        public void ReflectionWrapper_Should_Construct()
        {
            // Arrange

            // Act
            var objectUnderTest = new ReflectionWrapper();

            // Assert
            Assert.IsInstanceOf <ReflectionWrapper>(objectUnderTest);
        }
コード例 #15
0
ファイル: ShellHelper.cs プロジェクト: zaksnet/zip
            /// <summary>
            /// Copies specified items (single file or collection) into current folder or ZIP archive.
            /// </summary>
            public void Copy(ReflectionWrapper items)
            {
                const int NoProgressDialog       = 4;
                const int RespondYesToAllDialogs = 16;
                const int NoUiOnError            = 1024;

                // HINT: somehow flags about UI are ignored and if operation takes a bit more time (from several seconds up)
                //       shell will display the progress with option to cancel
                // HINT: this call is asynchronous and starts another thread without any way to easily monitor progress
                InvokeMethod("CopyHere", items.WrappedObject, NoProgressDialog | RespondYesToAllDialogs | NoUiOnError);
            }
コード例 #16
0
        public void ShouldGetAllStepMethods()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);

            AssertRunnerDomainDidNotLoadUsersAssembly();
            var stepMethods = sandbox.GetStepMethods();

            Assert.AreEqual(13, stepMethods.Count);
        }
コード例 #17
0
        public void ShouldNotLoadTargetLibAssemblyInRunnersDomain()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);

            // The sample project uses a special version of Gauge Lib, versioned 0.0.0 for testing.
            // The actual Gauge CSharp runner uses a different version of Lib
            // used by runner
            AssertRunnerDomainDidNotLoadUsersAssembly();
        }
コード例 #18
0
        public void ShouldExecuteMethodFromRequest()
        {
            const string parameterizedStepText = "Step that takes a table {}";
            const string stepText          = "Step that takes a table <table>";
            var          reflectionWrapper = new ReflectionWrapper();
            var          activatorWrapper  = new ActivatorWrapper();
            var          path                 = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var          assemblyLoader       = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var          executionInfoMapper  = new ExecutionInfoMapper(assemblyLoader, activatorWrapper);
            var          classInstanceManager = assemblyLoader.GetClassInstanceManager();
            var          orchestrator         = new ExecutionOrchestrator(reflectionWrapper, assemblyLoader,
                                                                          classInstanceManager,
                                                                          new HookExecutor(assemblyLoader, reflectionWrapper, classInstanceManager, executionInfoMapper),
                                                                          new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

            var executeStepProcessor = new ExecuteStepProcessor(assemblyLoader.GetStepRegistry(),
                                                                orchestrator, new TableFormatter(assemblyLoader, activatorWrapper));

            var protoTable = new ProtoTable
            {
                Headers = new ProtoTableRow
                {
                    Cells = { "foo", "bar" }
                },
                Rows =
                {
                    new ProtoTableRow
                    {
                        Cells ={ "foorow1",             "foorow2" }
                    }
                }
            };
            var message = new ExecuteStepRequest
            {
                ParsedStepText = parameterizedStepText,
                ActualStepText = stepText,
                Parameters     =
                {
                    new Parameter
                    {
                        Name          = "table",
                        ParameterType = Parameter.Types.ParameterType.Table,
                        Table         = protoTable
                    }
                }
            };
            var result = executeStepProcessor.Process(message);

            var protoExecutionResult = result.ExecutionResult;

            Assert.IsNotNull(protoExecutionResult);
            Assert.IsFalse(protoExecutionResult.Failed);
        }
コード例 #19
0
        public void ShouldGetStepTextsForMethod()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(),
                                                       new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var registry    = assemblyLoader.GetStepRegistry();
            var gaugeMethod = registry.MethodFor("and an alias");
            var stepTexts   = gaugeMethod.Aliases.ToList();

            Assert.Contains("Step with text", stepTexts);
            Assert.Contains("and an alias", stepTexts);
        }
コード例 #20
0
        public void ShouldRefactorAttributeText()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), activatorWrapper, reflectionWrapper);
            var gaugeMethod       = sandbox.GetStepMethods().First(info =>
                                                                   info.Name == "IntegrationTestSample.RefactoringSample.RefactoringContext");

            sandbox.Refactor(gaugeMethod, new List <Tuple <int, int> >(), new List <string>(), "foo");

            AssertStepAttributeWithTextExists(gaugeMethod.Name, "foo");
        }
コード例 #21
0
        public void ShouldGetStepTextsForMethod()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var path           = new AssemblyLocater(new DirectoryWrapper()).GetTestAssembly();
            var assemblyLoader = new AssemblyLoader(path, new GaugeLoadContext(path), reflectionWrapper, activatorWrapper, new StepRegistry());
            var registry       = assemblyLoader.GetStepRegistry();
            var gaugeMethod    = registry.MethodFor("and an alias");
            var stepTexts      = gaugeMethod.Aliases.ToList();

            Assert.Contains("Step with text", stepTexts);
            Assert.Contains("and an alias", stepTexts);
        }
コード例 #22
0
        public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);
            var stepMethods       = sandbox.GetStepMethods();
            var gaugeMethod       = stepMethods.First(info =>
                                                      string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.ContinueOnFailure") == 0);

            var executionResult = sandbox.ExecuteMethod(gaugeMethod);

            Assert.IsFalse(executionResult.Success);
            Assert.IsTrue(executionResult.Recoverable);
        }
コード例 #23
0
        /// <summary>
        /// Checks if an object is an instance of a specified type.
        /// </summary>
        /// <param name="check">checker logic object</param>
        /// <param name="type">expected type</param>
        /// <typeparam name="T">type of checked object</typeparam>
        /// <returns>A check link</returns>
        public static ICheckLink <ICheck <T> > IsInstanceOfType <T>(this ICheck <T> check, Type type)
        {
            ExtensibilityHelper.BeginCheck(check).
            FailWhen(sut => sut == null && typeof(T) == type && typeof(T).IsNullable(), $"The {{checked}} does not have a value.").
            FailWhen(sut => sut == null, $"The {{checked}} is not an instance of [{type.ToStringProperlyFormatted()}].").
            Analyze((sut, test) =>
            {
                if (sut is ReflectionWrapper reflectionSut)
                {
                    var expectedWrapper = ReflectionWrapper.BuildFromType(type, reflectionSut.Criteria);
                    expectedWrapper.MapFields(reflectionSut, 1, (expected, actual, depth) =>
                    {
                        if (actual == null)
                        {
                            test.CheckSutAttributes(_ => expectedWrapper.Value, expected.MemberLabel)
                            .DefineExpectedValue(expected)
                            .Fail("The {1} is absent from the {0}.", MessageOption.NoCheckedBlock);
                        }
                        else if (expected == null)
                        {
                            test.CheckSutAttributes(_ => actual, actual.MemberLabel.DoubleCurlyBraces())
                            .Fail("The {0} is absent from the {1}.");
                        }
                        else if (actual.ValueType != expected.ValueType)
                        {
                            if (!actual.ValueType.IsPrimitive() && !expected.ValueType.IsPrimitive())
                            {
                                return(true);
                            }

                            test.CheckSutAttributes(_ => actual.Value, actual.MemberLabel)
                            .Fail("The {0} is of a different type than the {1}.")
                            .DefineExpectedType(expected.ValueType);
                        }

                        return(false);
                    });
                }
                else
                {
                    test.FailWhen(sut2 => sut2.GetTypeWithoutThrowingException() != type,
                                  $"The {{0}} is not an instance of [{type.ToStringProperlyFormatted()}].",
                                  MessageOption.WithType);
                }
            })
            .DefineExpectedType(type)
            .OnNegate($"The {{0}} is an instance of [{type.ToStringProperlyFormatted()}] whereas it must not.", MessageOption.WithType)
            .EndCheck();
            return(ExtensibilityHelper.BuildCheckLink(check));
        }
コード例 #24
0
        public void ShouldGetStepTextsForMethod()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);

            var stepMethods = sandbox.GetStepMethods();
            var gaugeMethod = stepMethods.First(info =>
                                                string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.StepWithAliases") == 0);

            var stepTexts = sandbox.GetStepTexts(gaugeMethod).ToList();

            Assert.Contains("Step with text", stepTexts);
            Assert.Contains("and an alias", stepTexts);
        }
コード例 #25
0
        public void ShouldRemoveParametersInAnyOrder()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), activatorWrapper, reflectionWrapper);
            var gaugeMethod       = sandbox.GetStepMethods().First(info =>
                                                                   info.Name == "IntegrationTestSample.RefactoringSample.RefactoringSaySomething-StringwhatStringwho");

            var parameterPositions = new[] { new Tuple <int, int>(1, 0) };

            sandbox.Refactor(gaugeMethod, parameterPositions, new List <string>(), "Refactoring Say something to <who>");

            AssertParametersExist(gaugeMethod.Name, new[] { "who" });
        }
コード例 #26
0
        public void ShouldExecuteMethodAndReturnResult()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);
            var stepMethods       = sandbox.GetStepMethods();

            AssertRunnerDomainDidNotLoadUsersAssembly();
            var gaugeMethod = stepMethods.First(info =>
                                                string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.Context") == 0);

            var executionResult = sandbox.ExecuteMethod(gaugeMethod);

            Assert.True(executionResult.Success);
        }
コード例 #27
0
        public void ShouldRefactorAndReturnFilesChanged()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var activatorWrapper  = new ActivatorWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), activatorWrapper, reflectionWrapper);
            var gaugeMethod       = sandbox.GetStepMethods().First(info =>
                                                                   info.Name == "IntegrationTestSample.RefactoringSample.RefactoringContext");
            var expectedPath = Path.GetFullPath(Path.Combine(_testProjectPath, "RefactoringSample.cs"));

            var changedFile =
                sandbox.Refactor(gaugeMethod, new List <Tuple <int, int> >(), new List <string>(), "foo").ToList();

            Assert.AreEqual(expectedPath, changedFile);
        }
コード例 #28
0
        /// <inheritdoc cref="ObjectCheckExtensions.IsDistinctFrom{T,TU}" />
        public static ICheckLink <ICheck <ReflectionWrapper> > IsDistinctFrom <TU>(this ICheck <ReflectionWrapper> check,
                                                                                   TU expected)
        {
            var checker = ExtensibilityHelper.ExtractChecker(check);

            return(checker.ExecuteCheck(() =>
            {
                var expectedWrapper =
                    ReflectionWrapper.BuildFromInstance(typeof(TU), expected, checker.Value.Criteria);
                expectedWrapper.MapFields(checker.Value, 1, (scan, match, depth) =>
                {
                    if (depth > 0)
                    {
                        return true;
                    }

                    if (match == null)
                    {
                        var result = checker.BuildShortMessage(
                            $"The {{1}}'s {scan.MemberLabel.DoubleCurlyBraces()} is absent from the {{0}}.")
                                     .For("value").Expected(scan.Value)
                                     .Label($"The {{0}} {scan.MemberLabel.DoubleCurlyBraces()}:");
                        throw new FluentCheckException(result.ToString());
                    }

                    if (scan == null)
                    {
                        var result = checker.BuildShortMessage(
                            $"The {{0}}'s {match.MemberLabel.DoubleCurlyBraces()} is absent from the {{1}}.")
                                     .For("value").On(match.Value)
                                     .Label($"The {{1}} {match.MemberLabel.DoubleCurlyBraces()}:");
                        throw new FluentCheckException(result.ToString());
                    }

                    if (ReferenceEquals(scan.Value, match.Value))
                    {
                        var message =
                            checker.BuildShortMessage(
                                $"The {{0}}'s {match.MemberLabel.DoubleCurlyBraces()} does reference the reference instance, whereas it should not.")
                            .For("value").On(match);
                        throw new FluentCheckException(message.ToString());
                    }

                    return scan.Value != null;
                });
            },
                                        checker.BuildMessage("The {0} has no null member, whereas it should.").ToString()));
        }
コード例 #29
0
        public void ShouldGetPendingMessages()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);

            var stepMethods = sandbox.GetStepMethods();
            var gaugeMethod = stepMethods.First(info =>
                                                string.CompareOrdinal(info.Name,
                                                                      "IntegrationTestSample.StepImplementation.SaySomething-StringwhatStringwho") == 0);

            sandbox.ExecuteMethod(gaugeMethod, "hello", "world");
            var pendingMessages = MessageCollector.GetAllPendingMessages();

            Assert.Contains("hello, world!", pendingMessages);
        }
コード例 #30
0
        public void ShouldGetStacktraceForAggregateException()
        {
            var reflectionWrapper = new ReflectionWrapper();
            var assemblyLoader    = new AssemblyLoader(new AssemblyWrapper(), new AssemblyLocater(new DirectoryWrapper(), new FileWrapper()).GetAllAssemblies(), reflectionWrapper);
            var sandbox           = new Sandbox(assemblyLoader, new HookRegistry(assemblyLoader), new ActivatorWrapper(), reflectionWrapper);

            var stepMethods = sandbox.GetStepMethods();
            var gaugeMethod = stepMethods.First(info =>
                                                string.CompareOrdinal(info.Name, "IntegrationTestSample.StepImplementation.AsyncExeption") == 0);

            var executionResult = sandbox.ExecuteMethod(gaugeMethod);

            Assert.AreEqual(false, executionResult.Success);
            Assert.True(executionResult.StackTrace.Contains("First Exception"));
            Assert.True(executionResult.StackTrace.Contains("Second Exception"));
        }