public static void TestDeserializeExpression( TestContext testContext, string fileName, Expression expected) { try { var expectedString = expected.DumpString(); testContext.WriteLine( "EXPECTED:\n{0}{1}\n", expected.ToString(), expectedString); var actual = XmlExpressionSerializer.ToExpression(XDocument.Load(fileName)); var actualString = actual.DumpString(); testContext.WriteLine( "ACTUAL:\n{0}{1}\n", actual.ToString(), actualString); Assert.AreEqual(ReplaceEquivalents(expected.DumpString()), ReplaceEquivalents(actual.DumpString())); } catch (AssertFailedException) { throw; } catch (Exception x) { testContext.WriteLine("{0}", x.DumpString()); throw; } }
internal PrtgClient(string server, string username, string password, AuthMode authMode, IWebClient client, IXmlSerializer xmlSerializer = null) { if (xmlSerializer == null) { xmlSerializer = new XmlExpressionSerializer(); } if (server == null) { throw new ArgumentNullException(nameof(server)); } if (username == null) { throw new ArgumentNullException(nameof(username)); } if (password == null) { throw new ArgumentNullException(nameof(password)); } RequestEngine = new RequestEngine(this, client); ConnectionDetails = new ConnectionDetails(server, username, password); Targets = new PrtgTargetHelper(this); if (authMode == AuthMode.Password) { ConnectionDetails.PassHash = GetPassHash(password); } ObjectEngine = new ObjectEngine(this, RequestEngine, xmlSerializer); }
public static void TestSerializeExpression( TestContext testContext, Expression expression, string fileName, bool validate = true) { try { var expectedDoc = !string.IsNullOrWhiteSpace(fileName) ? XDocument.Load(fileName) : null; var expected = expectedDoc != null?expectedDoc.ToString(SaveOptions.OmitDuplicateNamespaces) : ""; testContext.WriteLine("EXPECTED:\n{0}\n", expected); var actualDoc = new XmlExpressionSerializer().ToXmlDocument(expression); var actual = actualDoc.ToString(SaveOptions.OmitDuplicateNamespaces); testContext.WriteLine("ACTUAL:\n{0}\n", actual); if (validate) { Assert.IsTrue(XmlValidator.Validate(expectedDoc, testContext)); Assert.IsTrue(XmlValidator.Validate(actualDoc, testContext)); } Assert.IsTrue( XDocument.DeepEquals(actualDoc, expectedDoc) || actual.Equals(expected)); } catch (AssertFailedException) { throw; } catch (Exception x) { testContext.WriteLine("{0}", x.DumpString()); throw; } }