예제 #1
0
        public async Task PrtgClient_ParsesInvalidXml_RetainsDirtyAsync()
        {
            var xml = "<property><value>\01</value></property>";

            var client = BaseTest.Initialize_Client(new BasicResponse(xml.ToString()));

            var validator = new EventValidator <string>(new[]
            {
                //First - retry a dirty response
                "https://prtg.example.com/api/table.xml?content=objects&columns=objid,name,tags,type,active,basetype&count=*&username=username&passhash=12345678",
                "XmlSerializer encountered exception ''.', hexadecimal value 0x00, is an invalid character. Line 1, position 18.' while processing request. Retrying request and flagging engine as dirty.",
                "https://prtg.example.com/api/table.xml?content=objects&columns=objid,name,tags,type,active,basetype&count=*&username=username&passhash=12345678",

                //Second - engine should be already marked as dirty
                "https://prtg.example.com/api/table.xml?content=objects&columns=objid,name,tags,type,active,basetype&count=*&username=username&passhash=12345678"
            });

            client.LogVerbose += (s, e) =>
            {
                var message = e.Message;

                if (message.StartsWith("Synchronously") || message.StartsWith("Asynchronously"))
                {
                    message = Regex.Replace(e.Message, "(.+ request )(.+)", "$2");
                }

                Assert.AreEqual(validator.Get(message), message);
            };

            validator.MoveNext(3);
            var result = await client.ObjectEngine.GetObjectAsync <DummyElementRoot>(new PrtgObjectParameters());

            validator.MoveNext();
            result = await client.ObjectEngine.GetObjectAsync <DummyElementRoot>(new PrtgObjectParameters());

            Assert.IsTrue(validator.Finished, "Did not process all requests");
        }