コード例 #1
0
        public void ShouldGetAllStepMethods()
        {
            var sandbox     = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var stepMethods = sandbox.GetStepMethods();

            Assert.AreEqual(9, stepMethods.Count);
        }
コード例 #2
0
        public void ShouldLoadTargetLibAssemblyInSandbox()
        {
            var sandbox = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);

            // 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
            Assert.AreEqual(FileVersionInfo.GetVersionInfo(sandbox.TargetLibAssembly.Location).ProductVersion, "0.0.0");
        }
コード例 #3
0
        public void ShouldNotLoadTargetLibAssemblyInRunnersDomain()
        {
            SandboxFactory.Create(SetupInformation());

            // 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();
        }
コード例 #4
0
        public void ShouldGetAllStepMethods()
        {
            var sandbox = SandboxFactory.Create(SetupInformation());

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

            Assert.AreEqual(9, stepMethods.Count);
        }
コード例 #5
0
        public void ShouldRefactorAttributeText()
        {
            var sandbox    = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringContext");

            RefactorHelper.Refactor(methodInfo, new List <ParameterPosition>(), new List <string>(), "foo");

            AssertStepAttributeWithTextExists(methodInfo.Name, "foo");
        }
コード例 #6
0
        public void CreateSandboxSimpleTest()
        {
            PermissionSet sandboxSet = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, new Url(Path.GetTempPath()));
            AppDomain     sandbox    = SandboxFactory.CreateSandbox(Path.GetTempPath(), sandboxSet);

            Assert.IsTrue(sandbox.IsSandboxed());
            Assert.IsTrue(sandbox.GetPermissionSet().IsSubsetOf(sandboxSet));
            Assert.IsTrue(sandboxSet.IsSubsetOf(sandbox.GetPermissionSet()));
            Assert.AreEqual(Path.GetTempPath(), sandbox.BaseDirectory);
        }
コード例 #7
0
        public void ShouldExecuteMethodAndReturnResult()
        {
            var sandbox     = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var stepMethods = sandbox.GetStepMethods();
            var methodInfo  = stepMethods.First(info => string.CompareOrdinal(info.Name, "Context") == 0);

            var executionResult = sandbox.ExecuteMethod(methodInfo);

            Assert.True(executionResult.Success);
        }
コード例 #8
0
        public void ShouldRefactorAndReturnFilesChanged()
        {
            var sandbox      = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var methodInfo   = sandbox.GetStepMethods().First(info => info.Name == "RefactoringContext");
            var expectedPath = Path.GetFullPath(Path.Combine(_testProjectPath, "RefactoringSample.cs"));

            var filesChanged = RefactorHelper.Refactor(methodInfo, new List <ParameterPosition>(), new List <string>(), "foo").ToList();

            Assert.AreEqual(1, filesChanged.Count);
            Assert.AreEqual(expectedPath, filesChanged.First());
        }
コード例 #9
0
        public void ShouldGetAfterSuiteHooks()
        {
            var sandbox      = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var hookRegistry = sandbox.GetHookRegistry();

            Assert.AreEqual(1, hookRegistry.AfterSuiteHooks.Count);

            var hookMethod = hookRegistry.AfterSuiteHooks.First();

            Assert.AreEqual("AfterSuite", hookMethod.Method.Name);
        }
コード例 #10
0
        public void ShouldExecuteMethodAndReturnResult()
        {
            var sandbox     = SandboxFactory.Create(SetupInformation());
            var stepMethods = sandbox.GetStepMethods();

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

            var executionResult = sandbox.ExecuteMethod(methodInfo);

            Assert.True(executionResult.Success);
        }
コード例 #11
0
        public void ShouldRemoveParametersInAnyOrder()
        {
            var sandbox    = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var methodInfo = sandbox.GetStepMethods().First(info => info.Name == "RefactoringSaySomething");

            var parameterPosition = ParameterPosition.CreateBuilder().SetNewPosition(0).SetOldPosition(1).Build();

            RefactorHelper.Refactor(methodInfo, new List <ParameterPosition> {
                parameterPosition
            }, new List <string>(), "Refactoring Say something to <who>");

            AssertParametersExist(methodInfo.Name, new[] { "who" });
        }
コード例 #12
0
        public void SuccessIsFalseOnSerializableExceptionThrown()
        {
            const string expectedMessage = "I am a custom serializable exception";
            var          sandbox         = SandboxFactory.Create(SetupInformation());
            var          stepMethods     = sandbox.GetStepMethods();
            var          methodInfo      = stepMethods.First(info => string.CompareOrdinal(info.Name, "ThrowSerializableException") == 0);

            var executionResult = sandbox.ExecuteMethod(methodInfo);

            Assert.False(executionResult.Success);
            Assert.AreEqual(expectedMessage, executionResult.ExceptionMessage);
            StringAssert.Contains("IntegrationTestSample.StepImplementation.ThrowSerializableException", executionResult.StackTrace);
        }
コード例 #13
0
        public void ShouldGetAfterStepHooks()
        {
            var sandbox      = SandboxFactory.Create(SetupInformation());
            var hookRegistry = sandbox.GetHookRegistry();

            AssertRunnerDomainDidNotLoadUsersAssembly();

            Assert.AreEqual(1, hookRegistry.AfterStepHooks.Count);

            var hookMethod = hookRegistry.AfterStepHooks.First();

            Assert.AreEqual("AfterStep", hookMethod.Method.Name);
        }
コード例 #14
0
        public void ShouldGetAllStepTexts()
        {
            var sandbox   = SandboxFactory.Create(SetupInformation());
            var stepTexts = sandbox.GetAllStepTexts().ToList();

            new List <string>
            {
                "Say <what> to <who>",
                "A context step which gets executed before every scenario",
                "Step that takes a table <table>",
                "Refactoring Say <what> to <who>",
                "Refactoring A context step which gets executed before every scenario",
                "Refactoring Step that takes a table <table>"
            }.ForEach(s => Assert.Contains(s, stepTexts));
        }
コード例 #15
0
        public void ShouldAddParametersWithReservedKeywordName()
        {
            const string newStepValue       = "Refactoring this is a test step <class>";
            var          sandbox            = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var          methodInfo         = sandbox.GetStepMethods().First(info => info.Name == "RefactoringSampleTest");
            var          parameterPositions = new List <ParameterPosition>
            {
                ParameterPosition.CreateBuilder().SetNewPosition(0).SetOldPosition(-1).Build()
            };

            RefactorHelper.Refactor(methodInfo, parameterPositions, new List <string> {
                "class"
            }, newStepValue);

            AssertStepAttributeWithTextExists(methodInfo.Name, newStepValue);
            AssertParametersExist(methodInfo.Name, new[] { "@class" });
        }
コード例 #16
0
        public void ShouldReorderParameters()
        {
            const string newStepValue = "Refactoring Say <who> to <what>";
            var          sandbox      = SandboxFactory.Create(AppDomain.CurrentDomain.SetupInformation);
            var          methodInfo   = sandbox.GetStepMethods().First(info => info.Name == "RefactoringSaySomething");

            var parameterPosition  = ParameterPosition.CreateBuilder().SetNewPosition(1).SetOldPosition(0).Build();
            var parameterPosition1 = ParameterPosition.CreateBuilder().SetNewPosition(0).SetOldPosition(1).Build();
            var parameterPositions = new List <ParameterPosition> {
                parameterPosition, parameterPosition1
            };

            RefactorHelper.Refactor(methodInfo, parameterPositions, new List <string> {
                "who", "what"
            }, newStepValue);

            AssertStepAttributeWithTextExists(methodInfo.Name, newStepValue);
            AssertParametersExist(methodInfo.Name, new[] { "who", "what" });
        }
コード例 #17
0
        public void CreateSandboxFullTrustListTest()
        {
            PermissionSet sandboxSet = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, new Url(Path.GetTempPath()));

            // Yes, both mscorlib and System.dll are in the GAC and would therefore be fully trusted anyway,
            // without needing this list.  However, by adding them here we can ensure that the strong names
            // are flowing properly.
            AppDomain sandbox = SandboxFactory.CreateSandbox(Path.GetTempPath(),
                                                             sandboxSet,
                                                             typeof(object).Assembly,
                                                             typeof(System.Diagnostics.Debug).Assembly);

            Assert.IsTrue(sandbox.IsSandboxed());
            Assert.IsTrue(sandbox.GetPermissionSet().IsSubsetOf(sandboxSet));
            Assert.IsTrue(sandboxSet.IsSubsetOf(sandbox.GetPermissionSet()));
            Assert.AreEqual(Path.GetTempPath(), sandbox.BaseDirectory);

            IList <StrongName> fullTrustList = sandbox.ApplicationTrust.GetFullTrustAssemblies();

            Assert.AreEqual(2, fullTrustList.Count);

            Assert.IsTrue(fullTrustList.Contains(typeof(object).Assembly.GetStrongName()));
            Assert.IsTrue(fullTrustList.Contains(typeof(System.Diagnostics.Debug).Assembly.GetStrongName()));
        }
コード例 #18
0
 public void CreateSandboxNullAppBaseTest()
 {
     SandboxFactory.CreateSandbox(null, PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.Internet));
 }
コード例 #19
0
 public void CreateSandboxNullGrantTest()
 {
     SandboxFactory.CreateSandbox(Path.GetTempPath(), null);
 }