Exemple #1
0
        public void TestEmpty()
        {
            var dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "EmptyDir"));

            if (dir.Exists)
            {
                dir.Delete(true);
            }

            dir.Create();

            var f = new WorldFactory()
            {
                ResourcesDirectory = dir.FullName
            };

            f.Create();

            var v = new WorldValidator();

            v.Validate(f);
            Assert.IsEmpty(v.Errors.ToString());
            Assert.IsEmpty(v.Warnings.ToString());
            Assert.AreEqual(0, v.ErrorCount);
            Assert.AreEqual(0, v.WarningCount);
        }
        public void TestWorldValidator_BadYaml()
        {
            var dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "BadYamlDir"));

            if (dir.Exists)
            {
                dir.Delete(true);
            }

            dir.Create();

            var f = new WorldFactory()
            {
                ResourcesDirectory = dir.FullName
            };

            File.WriteAllText(Path.Combine(dir.FullName, "rooms.yaml"), "ffffff");

            var v = new WorldValidator();

            v.Validate(f);
            StringAssert.Contains("Error Creating World", v.Errors.ToString());
            StringAssert.Contains("Error loading RoomBlueprint in file", v.Errors.ToString());
            StringAssert.Contains("rooms.yaml", v.Errors.ToString());


            Assert.IsEmpty(v.Warnings.ToString());
            Assert.AreEqual(1, v.ErrorCount);
            Assert.AreEqual(0, v.WarningCount);
        }
        public void TestWorldValidator_Success()
        {
            var v = new WorldValidator();

            v.IncludeStackTraces = true;
            v.Validate(new WorldFactory()
            {
                ResourcesDirectory = NormalResourcesDirectory
            });

            Assert.IsEmpty(v.Errors.ToString());
            Assert.IsEmpty(v.Warnings.ToString());

            Assert.AreEqual(0, v.WarningCount);
            Assert.AreEqual(0, v.ErrorCount);
        }
        public void TestValidate_BadPlanCondition()
        {
            WorldValidator v = new WorldValidator();

            var plan = new Plan()
            {
                Condition =
                {
                    new ConditionCode("this is bat country")
                }
            };

            v.Validate(Mock.Of <IWorld>(), plan, Mock.Of <IActor>());

            StringAssert.Contains("Error executing 'ConditionCode' script code 'return this is bat country'.", v.Warnings.ToString());
        }
        public void TestValidate_BadPlanMissingDoFrame()
        {
            WorldValidator v = new WorldValidator();

            var plan = new Plan()
            {
                Name      = "Do something nefarious",
                Condition =
                {
                    new ConditionCode("true")
                }
            };

            v.Validate(Mock.Of <IWorld>(), plan, Mock.Of <IActor>());

            StringAssert.Contains("Plan 'Do something nefarious' has no DoFrame", v.Errors.ToString());
        }
        public void TestValidate_BadPlanBadDoFrame()
        {
            WorldValidator v = new WorldValidator();

            var plan = new Plan()
            {
                Name      = "Do something nefarious",
                Condition =
                {
                    new ConditionCode("true")
                },
                Do = new FrameSourceCode("fffff")
            };

            v.Validate(Mock.Of <IWorld>(), plan, Mock.Of <IActor>());

            StringAssert.Contains(@"Failed to validate DoFrame of Plan 'Do something nefarious'", v.Warnings.ToString());
        }
        public async Task Validate_Type_Privacy(bool valid, AccountType type, WorldPrivacy privacy)
        {
            using (var provider = await CreateProvider())
            {
                var worlds = provider.GetRequiredService <IWorldRepository>();

                IValidator <World> validator = new WorldValidator(worlds);

                var world = new World {
                    Account = new Account {
                        Type = type,
                    },
                    Privacy = privacy
                };

                var target = new ValidationTarget <World>(world);
                validator.Validate(target);
                Assert.Equal(valid, !target.GetResult().HasErrors);
            }
        }
Exemple #8
0
        protected IWorld Setup(params string[] pairs)
        {
            List <WorldFactoryResource> resources = new List <WorldFactoryResource>();

            for (int i = 0; i < pairs.Length; i += 2)
            {
                resources.Add(new WorldFactoryResource(pairs[i], pairs[i + 1]));
            }

            var wf = new CookBookWorldFactory(resources);

            //make sure that the directory setup passes validation
            var validator = new WorldValidator();

            validator.Validate(wf);

            Assert.AreEqual(0, validator.Warnings.Length, "Recipe resulted in warnings during world validation: " + validator.Warnings);
            Assert.AreEqual(0, validator.Errors.Length, "Recipe resulted in errors during world validation: " + validator.Errors);

            return(wf.Create());
        }
        public void TestWorldValidator_MissingDialogue()
        {
            var v = new WorldValidator();
            var f = new WorldFactory
            {
                ResourcesDirectory = NormalResourcesDirectory
            };

            var w = f.Create();

            w.Dialogue.AllDialogues.Clear();
            w.RoomFactory.Blueprints.Add(new RoomBlueprint()
            {
                Dialogue = new DialogueInitiation()
                {
                    Next = Guid.NewGuid()
                }
            });
            v.Validate(w);

            Assert.AreEqual(v.ErrorCount, 1);

            StringAssert.Contains("Could not find Dialogue", v.Errors.ToString());
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments<Options>(args)
                   .WithParsed<Options>(o =>
                   {

                       if(!string.IsNullOrWhiteSpace(o.CompileDialogue))
                       {
                           var b = new DialogueBuilder();
                           try
                           {
                                var result = b.BuildAndSerialize(new FileInfo(o.CompileDialogue));
                                
                                if(result == null)
                                    Console.WriteLine("No file created");
                                else
                                    Console.WriteLine("Created " + result.FullName);
                           }
                           catch(Exception ex)
                           {
                               Console.WriteLine(ex.Message);
                           }
                           return;
                       }

                       var f = new WorldFactory();
                       if(o.ResourcesDirectory != null)
                            f.ResourcesDirectory = o.ResourcesDirectory;

                       if (o.Validate)
                       {
                           var validator = new WorldValidator();
                            validator.IncludeStackTraces = o.StackTraces;
                            validator.Validate(f);
                            

                            if(validator.Warnings.Length > 0)
                            {
                                Console.WriteLine("WARNINGS:");
                                Console.WriteLine(validator.Warnings);
                            }

                            if(validator.Errors.Length > 0)
                            {
                                Console.WriteLine("ERRORS:");
                                Console.WriteLine(validator.Errors);
                            }


                            Console.WriteLine("Finished Validation:");
                            Console.WriteLine(validator.ErrorCount + " Errors");
                            Console.WriteLine(validator.WarningCount + " Warnings");
                       }
                       else
                       {
                            //Don't log to the console when Console Gui is running 
                            LogManager.Configuration.RemoveTarget("logconsole");

                            Application.Init();
                            var mainWindow = new MainWindow(f);
                            Application.Top.Add(mainWindow);
                            Application.Run();                
                       }
                   });
        }
        private static Dictionary <string, Breed> BuildBreedDefinitions()
        {
            string worldDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/StandingData");

            string pathToWorld = worldDirectory + "/Monsters.xml";

            if (!File.Exists(pathToWorld))
            {
                throw new ArgumentOutOfRangeException(pathToWorld);
            }

            var xmlDoc = new XmlDocument();

            xmlDoc.Load(pathToWorld);

            var validator = new WorldValidator();
            var pathToXsd = worldDirectory + "/MonstersSchema.xsd";

            validator.Validate(xmlDoc.OuterXml, pathToXsd);

            var xmlRoot = xmlDoc.DocumentElement;

            if (xmlRoot == null)
            {
                throw new InvalidOperationException("Empty xml document.");
            }
            var xnm = new XmlNamespaceManager(xmlDoc.NameTable);

            xnm.AddNamespace("ns", "http://JonSaffron/Labyrinth/Monsters");

            var result = new Dictionary <string, Breed>();

            foreach (XmlElement breedElement in xmlRoot.SelectNodesEx("ns:Breed", xnm))
            {
                var breed = new Breed
                {
                    Name    = breedElement.GetAttribute(nameof(Breed.Name)),
                    Texture = breedElement.GetAttribute(nameof(Breed.Texture)),
                    BaseMovesDuringAnimation = int.Parse(breedElement.GetAttribute(nameof(Breed.BaseMovesDuringAnimation)))
                };

                XmlElement inherentBehaviours = (XmlElement)breedElement.SelectSingleNode("ns:InherentBehaviours", xnm);
                if (inherentBehaviours != null)
                {
                    foreach (XmlElement behaviour in inherentBehaviours.ChildNodes)
                    {
                        breed.InherentBehaviours.Add(behaviour.LocalName);
                    }
                }

                XmlElement inherentProperties = (XmlElement)breedElement.SelectSingleNode("ns:InherentProperties", xnm);
                if (inherentProperties != null)
                {
                    foreach (XmlElement property in inherentProperties.ChildNodes)
                    {
                        var propertyValue = property.GetAttribute("value");
                        breed.InherentProperties.Add(property.Name, propertyValue);
                    }
                }

                XmlElement movement = (XmlElement)breedElement.SelectSingleNode("ns:Movement", xnm);
                if (movement != null)
                {
                    var defaultMobility = movement.GetAttribute("Default");
                    if (!string.IsNullOrWhiteSpace(defaultMobility))
                    {
                        breed.BreedMovement.DefaultMobility = (MonsterMobility)Enum.Parse(typeof(MonsterMobility), defaultMobility);
                    }
                    var changeRooms = movement.GetAttribute("ChangeRooms");
                    if (!string.IsNullOrWhiteSpace(changeRooms))
                    {
                        breed.BreedMovement.ChangeRooms = (ChangeRooms)Enum.Parse(typeof(ChangeRooms), changeRooms);
                    }
                    var speed = movement.GetAttribute("Speed");
                    if (!string.IsNullOrWhiteSpace(speed))
                    {
                        breed.BreedMovement.Speed = decimal.Parse(speed);
                    }

                    foreach (XmlElement moveElement in movement.SelectNodesEx("ns:Move", xnm))
                    {
                        var type           = (MonsterMobility)Enum.Parse(typeof(MonsterMobility), moveElement.GetAttribute("Type"));
                        var implementation = moveElement.GetAttribute("Implementation");
                        breed.BreedMovement.Moves.Add(type, implementation);
                    }
                }

                result.Add(breed.Name, breed);
            }

            return(result);
        }