示例#1
0
        public ScenarioWrapper LoadScenario(XDocument doc)
        {
            //XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScenarioWrapper));

            //using (var reader = doc.Root.CreateReader())
            //    return (ScenarioWrapper)xmlSerializer.Deserialize(reader);

            ScenarioWrapper output = new ScenarioWrapper()
            {
                Title       = doc.Root.Element("Title").Value,
                Author      = doc.Root.Element("Author").Value,
                DateCreated = DateTime.Parse(doc.Root.Element("DateCreated").Value)
            };

            List <XElement> rows = (from t in doc.Root.Descendants("Row")
                                    select t).ToList();

            List <string> data = new List <string>();

            foreach (var item in rows)
            {
                data.Add(item.Value);
            }

            output.Data = data;

            return(output);
        }
        public void ExceptionThrownIfMethodNotFound()
        {
            ScenarioWrapper scenarioWrapper = new ScenarioWrapper(typeof(MethodSearchTestsClass));

            Action action = () =>
            {
                scenarioWrapper.Given("NonExistingGivenMethod");
            };

            action.ShouldThrow <TestMethodNotFoundException>();

            action = () =>
            {
                scenarioWrapper.When("NonExistingWhenMethod");
            };

            action.ShouldThrow <TestMethodNotFoundException>();

            action = () =>
            {
                scenarioWrapper.Then("NonExistingThenMethod");
            };

            action.ShouldThrow <TestMethodNotFoundException>();
        }
        public void IntBoolDoubleTableStringParametersHavePassedCorrectly()
        {
            ScenarioWrapper scenarioWrapper = new ScenarioWrapper(typeof(MethodSearchTestsClass));

            int    expectedIntParam    = 100;
            bool   expectedBoolParam   = true;
            double expectedDoubleParam = 10.10;
            string expectedStringParam = "testString";
            string expectedTableValue  = "Value";

            Action action = () =>
            {
                scenarioWrapper
                .Given(
                    $"Int={expectedIntParam};Bool={expectedBoolParam};" +
                    $"Double={expectedDoubleParam};Table;String={expectedStringParam};ParametersMethod",
                    new Table(
                        new [] { "Column" },
                        new object[][]
                {
                    new [] { expectedTableValue }
                }
                        ))
                .Run();
            };

            action.ShouldNotThrow();
            GetResult <bool>("IntBoolDoubleTableStringParametersMethod").Should().BeTrue();
            GetResult <int>("intParam").Should().Be(expectedIntParam);
            GetResult <bool>("boolParam").Should().Be(expectedBoolParam);
            GetResult <double>("doubleParam").Should().Be(expectedDoubleParam);
            GetResult <string>("stringParam").Should().Be(expectedStringParam);
            GetResult <string>("tableColumnValue").Should().Be(expectedTableValue);
        }
        public void ExceptionThrownWhenAmbiguousThenMethodFound()
        {
            ScenarioWrapper scenarioWrapper = new ScenarioWrapper(typeof(MethodSearchTestsClass));

            Action action = () =>
            {
                scenarioWrapper.Then("ThenStaticMethodSearchTestsClassDuplicate");
            };

            action.ShouldThrow <AmbiguousTestMethodFoundException>();
        }
        public void WhenMethodFoundForRegExPattern()
        {
            ScenarioWrapper scenarioWrapper = new ScenarioWrapper(typeof(MethodSearchTestsClass));

            Action action = () =>
            {
                scenarioWrapper.When("WhenStaticMethodSearchTestsClass");
            };

            action.ShouldNotThrow();
        }
示例#6
0
        public void LoadPreview(ScenarioWrapper scenario)
        {
            Scenario = scenario;

            PreviewLabel.IsVisible = false;
            Tuple <bool, Rectangle> previewInfo = Tuple.Create(true, new Rectangle(Area.X + PreviewMargin,
                                                                                   Area.Y + PreviewMargin,
                                                                                   Area.Width - PreviewMargin * 2,
                                                                                   Area.Height - PreviewMargin * 2 - MarginBottom));

            PreviewedGrid = new Grid(previewInfo, 30, scenario);
        }
        public void ScenarioCollectsTestMethodsFromPassedAssembly()
        {
            ScenarioWrapper scenarioWrapper =
                new ScenarioWrapper(
                    typeof(AbstractClassOtherAssembly).GetTypeInfo().Assembly
                    );

            string[] shouldContainMethods =
            {
                "GivenStaticClassOtherAssembly",
                "WhenStaticClassOtherAssembly",
                "ThenStaticClassOtherAssembly",
                "GivenClassOtherAssemblyStaticMethod",
                "WhenClassOtherAssemblyStaticMethod",
                "ThenClassOtherAssemblyStaticMethod",
                "GivenClassOtherAssemblyProtectedStaticMethod",
                "WhenClassOtherAssemblyProtectedStaticMethod",
                "ThenClassOtherAssemblyProtectedStaticMethod",
                "GivenClassOtherAssemblyPrivateStaticMethod",
                "WhenClassOtherAssemblyPrivateStaticMethod",
                "ThenClassOtherAssemblyPrivateStaticMethod"
            };

            foreach (string shouldContainMethod in shouldContainMethods)
            {
                scenarioWrapper.TestMethodList.Should().Contain(method =>
                                                                MethodCheck(method, GetMethodTypeFromName(shouldContainMethod), shouldContainMethod));
            }

            string[] shouldNotContainMethods =
            {
                "GivenClassOtherAssembly",
                "WhenClassOtherAssembly",
                "ThenClassOtherAssembly",
                "GivenClassOtherAssemblyProtectedMethod",
                "WhenClassOtherAssemblyProtectedMethod",
                "ThenClassOtherAssemblyProtectedMethod",
                "GivenClassOtherAssemblyPrivateMethod",
                "WhenClassOtherAssemblyPrivateMethod",
                "ThenClassOtherAssemblyPrivateMethod",
                "GivenAbstractClassOtherAssemblyAbstractMethod",
                "WhenAbstractClassOtherAssemblyAbstractMethod",
                "ThenAbstractClassOtherAssemblyAbstractMethod"
            };

            foreach (string shouldNotContainMethod in shouldNotContainMethods)
            {
                scenarioWrapper.TestMethodList.Should().NotContain(method =>
                                                                   MethodCheck(method, GetMethodTypeFromName(shouldNotContainMethod), shouldNotContainMethod));
            }
        }
        public void ScenarioCollectsTestMethodsFromAssemblyHolder()
        {
            ScenarioWrapper scenarioWrapper = new ScenarioWrapper(this);

            string[] shouldContainMethods =
            {
                "GivenStaticClass",
                "WhenStaticClass",
                "ThenStaticClass",
                "GivenClassStaticMethod",
                "WhenClassStaticMethod",
                "ThenClassStaticMethod",
                "GivenClassProtectedStaticMethod",
                "WhenClassProtectedStaticMethod",
                "ThenClassProtectedStaticMethod",
                "GivenClassPrivateStaticMethod",
                "WhenClassPrivateStaticMethod",
                "ThenClassPrivateStaticMethod"
            };

            foreach (string shouldContainMethod in shouldContainMethods)
            {
                scenarioWrapper.TestMethodList.Should().Contain(method =>
                                                                MethodCheck(method, GetMethodTypeFromName(shouldContainMethod), shouldContainMethod));
            }

            string[] shouldNotContainMethods =
            {
                "GivenClass",
                "WhenClass",
                "ThenClass",
                "GivenClassProtectedMethod",
                "WhenClassProtectedMethod",
                "ThenClassProtectedMethod",
                "GivenClassPrivateMethod",
                "WhenClassPrivateMethod",
                "ThenClassPrivateMethod"
            };

            foreach (string shouldNotContainMethod in shouldNotContainMethods)
            {
                scenarioWrapper.TestMethodList.Should().NotContain(method =>
                                                                   MethodCheck(method, GetMethodTypeFromName(shouldNotContainMethod), shouldNotContainMethod));
            }
        }
示例#9
0
        public ScenarioState(GameRoot game, GraphicsDevice graphicsDevice, ScenarioWrapper scenario)
            : base(game, graphicsDevice)
        {
            // Load grid
            Tuple <bool, Rectangle> previewInfo = Tuple.Create(false, Rectangle.Empty);

            scenarioGrid = new Grid(previewInfo, 50, scenario);

            // Load pathfinder class
            pathfinder = new AStarPathfinder(scenarioGrid);
            AStarPathfinder.AllowDiagonalMovement = true;
            AStarPathfinder.InstantPathing        = false;
            pathfinder.PathfindingFinished       += PathfindingFinished;

            // Configure grid
            scenarioGrid.AssignNewAlgorithm(pathfinder);
            scenarioGrid.NodeHovered += ScenarioGrid_NodeHovered;
            scenarioGrid.NodeLeft    += ScenarioGrid_NodeLeft;

            // Load UI (ScenarioStateUI partial class)
            LoadUI();
        }