Exemplo n.º 1
0
        /// <summary>
        /// Returns a debugging check list from an xml formatted input string
        /// </summary>
        /// <param name="input">The xml to parse into debugging checks</param>
        /// <returns></returns>
        public static CheckDefinition[] ParseDebuggingChecklist(string input)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(input);
            List <CheckDefinition> checks = new List <CheckDefinition>();

            foreach (XmlNode node in doc.GetElementsByTagName("check"))
            {
                try
                {
                    Enum.TryParse(node["key"].InnerText, true, out CheckTypes checktype);
                    string[] args = new string[node["arguments"].ChildNodes.Count];
                    for (int i = 0; i < args.Length; i++)
                    {
                        args[i] = node["arguments"].ChildNodes[i].InnerText;
                    }
                    CheckDefinition d = CheckDefinition.DebugCheck(checktype, Convert.ToUInt16(node["id"].InnerText), Convert.ToInt16(node["points"].InnerText), Convert.ToByte(node["flags"].InnerText), uint.Parse(node["answer"].InnerText, System.Globalization.NumberStyles.HexNumber), args);
                    if (d != null)
                    {
                        checks.Add(d);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace.ToString());
                    Console.WriteLine(e.Message);
                }
            }
            return(checks.ToArray());
        }
        public void Use_CheckFactory_for_creating_checks()
        {
            var behaviorFactory = Substitute.For <INZazuWpfFieldBehaviorFactory>();
            var serializer      = Substitute.For <INZazuTableDataSerializer>();
            var checkFactory    = Substitute.For <ICheckFactory>();

            var checkDefinition = new CheckDefinition {
                Type = "required"
            };
            var fieldDefinition = new FieldDefinition {
                Key = "test", Type = "string", Checks = new[] { checkDefinition }
            };
            var check = new RequiredCheck(checkDefinition.Settings, null, null, 0, fieldDefinition);

            checkFactory.CreateCheck(checkDefinition, fieldDefinition, Arg.Any <Func <FormData> >(),
                                     Arg.Any <INZazuTableDataSerializer>(), Arg.Any <int>()).Returns(check);

            var sut = new NZazuFieldFactory();

            sut.Use(behaviorFactory);
            sut.Use(checkFactory);
            sut.Use(serializer);

            var field = (NZazuField)sut.CreateField(fieldDefinition);

            checkFactory.Received(1).CreateCheck(checkDefinition, fieldDefinition, Arg.Any <Func <FormData> >(),
                                                 Arg.Any <INZazuTableDataSerializer>(), Arg.Any <int>());

            field.Should().NotBeNull();
            field.Check.Should().Be(check);
        }
        public void Use_AggregateCheck_for_multiple_checks()
        {
            var behaviorFactory = Substitute.For <INZazuWpfFieldBehaviorFactory>();
            var serializer      = Substitute.For <INZazuTableDataSerializer>();
            var checkFactory    = Substitute.For <ICheckFactory>();

            var checkDefinition1 = new CheckDefinition {
                Type = "required"
            };
            var checkDefinition2 = new CheckDefinition
            {
                Type = "length", Settings = new Dictionary <string, string> {
                    { "Min", "4" }, { "Max", "6" }
                }
            };
            var fieldDefinition = new FieldDefinition
            {
                Key    = "test",
                Type   = "string",
                Checks = new[] { checkDefinition1, checkDefinition2 }
            };
            var check1 = new RequiredCheck(checkDefinition1.Settings, null, null, 0, fieldDefinition);
            var check2 = new StringLengthCheck(checkDefinition2.Settings, null, null, 0, fieldDefinition);

            checkFactory.CreateCheck(checkDefinition1, fieldDefinition, Arg.Any <Func <FormData> >(),
                                     Arg.Any <INZazuTableDataSerializer>(), Arg.Any <int>()).Returns(check1);
            checkFactory.CreateCheck(checkDefinition2, fieldDefinition, Arg.Any <Func <FormData> >(),
                                     Arg.Any <INZazuTableDataSerializer>(), Arg.Any <int>()).Returns(check2);

            var sut = new NZazuFieldFactory();

            sut.Use(behaviorFactory);
            sut.Use(checkFactory);
            sut.Use(serializer);

            var field = (NZazuField)sut.CreateField(fieldDefinition);

            checkFactory.Received(1).CreateCheck(checkDefinition1, fieldDefinition, Arg.Any <Func <FormData> >(),
                                                 Arg.Any <INZazuTableDataSerializer>(), Arg.Any <int>());
            checkFactory.Received(1).CreateCheck(checkDefinition2, fieldDefinition, Arg.Any <Func <FormData> >(),
                                                 Arg.Any <INZazuTableDataSerializer>(), Arg.Any <int>());

            var aggregateCheck = (AggregateCheck)field.Check;

            aggregateCheck.Should().NotBeNull();
            aggregateCheck.Checks.Should().BeEquivalentTo(check1, check2);
        }
Exemplo n.º 4
0
        public void Registered_At_CheckFactory()
        {
            var checkType = typeof(RequiredCheck);
            var settings  = new Dictionary <string, string>();

            var sut = new CheckFactory();

            var checkDefinition = new CheckDefinition {
                Type = "required", Settings = settings
            };

            var check = sut.CreateCheck(checkDefinition, new FieldDefinition {
                Key = "key1"
            });

            check.Should().NotBeNull();
            check.Should().BeOfType(checkType);
        }
        public void Registered_At_CheckFactory()
        {
            var settings = new Dictionary <string, string> {
                { "Min", "2" }, { "Max", "6" }
            } as IDictionary <string, string>;
            var checkType = typeof(StringLengthCheck);

            var sut = new CheckFactory();

            var checkDefinition = new CheckDefinition {
                Type = "length", Settings = settings
            };
            var check = sut.CreateCheck(checkDefinition, new FieldDefinition {
                Key = "key1"
            });

            check.Should().NotBeNull();
            check.Should().BeOfType(checkType);
        }
Exemplo n.º 6
0
        public void Registered_At_CheckFactory()
        {
            var settings =
                new Dictionary <string, string>
            {
                { "Hint", "this is the hint" }, { "RegEx", "false|true" }
            } as IDictionary <string, string>;
            var checkType = typeof(StringRegExCheck);

            var sut = new CheckFactory();

            var checkDefinition = new CheckDefinition {
                Type = "regex", Settings = settings
            };
            var check = sut.CreateCheck(checkDefinition, new FieldDefinition {
                Key = "key1"
            });

            check.Should().NotBeNull();
            check.Should().BeOfType(checkType);
        }