/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { var elem = XElement.Parse(Text); Command cmd; var files = elem.DescendantsAndSelf("Item") .Where(e => e.Attributes("type").Any(a => a.Value == "File") && e.Elements("actual_filename").Any(p => !string.IsNullOrEmpty(p.Value)) && e.Attributes("id").Any(p => !string.IsNullOrEmpty(p.Value)) && e.Attributes("action").Any(p => !string.IsNullOrEmpty(p.Value))); if (files.Any()) { var upload = context.Connection.CreateUploadCommand(); upload.AddFileQuery(Text); upload.WithAction(CommandAction.ApplyItem); cmd = upload; } else { cmd = new Command().WithAml(this.Text); cmd.Action = CommandAction.ApplyItem; if (this.Text.StartsWith("<sql") || this.Text.StartsWith("<SQL")) cmd.Action = CommandAction.ApplySQL; else if (this.Text.StartsWith("<GetNextSequence")) cmd.Action = CommandAction.GetNextSequence; } foreach (var kvp in context.Parameters) { cmd.WithParam(kvp.Key, kvp.Value); } var stream = await context.Connection.Process(cmd, true).ToTask(); context.LastResult = XElement.Load(stream); }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { var cmd = new Command().WithAml(this.Text); cmd.Action = CommandAction.DownloadFile; foreach (var kvp in context.Parameters) { cmd.WithParam(kvp.Key, kvp.Value); } try { var stream = await context.Connection.Process(cmd, true).ToTask(); var memStream = await stream.ToMemoryStream(); var start = await memStream.ReadStart(500); memStream.Position = 0; if (start.IndexOf("http://www.aras.com/InnovatorFault") > 0) { context.LastResult = XElement.Load(stream); } else { context.LastResult = new XElement("Result", new XElement("Item", Convert.ToBase64String(memStream.ToArray()))); } } catch (ServerException se) { context.LastResult = XElement.Parse(se.AsAmlString()); } }
public async Task<TestRun> Run(TestContext context) { var start = DateTime.Now; var st = Stopwatch.StartNew(); int i = 0; try { TestRun result = null; for (i = 0; i < _commands.Count; i++) { try { await _commands[i].Run(context); } catch (AssertionFailedException ex) { if (result == null) result = new TestRun() { Name = this.Name, Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }; } } if (result == null) return new TestRun() { Name = this.Name, Result = TestResult.Pass, ElapsedMilliseconds = st.ElapsedMilliseconds, Start = start }; result.ElapsedMilliseconds = st.ElapsedMilliseconds; return result; } catch (Exception ex) { return new TestRun() { Name = this.Name, Result = TestResult.Fail, ElapsedMilliseconds = st.ElapsedMilliseconds, Start = start, ErrorLine = i + 1, Message = ex.Message }; } finally { context.LastResult = null; } }
public async Task Run(TestContext context) { var cmd = new Command().WithAml(this.Text); cmd.Action = CommandAction.ApplyItem; if (this.Text.StartsWith("<sql") || this.Text.StartsWith("<SQL")) cmd.Action = CommandAction.ApplySQL; foreach (var kvp in context.Parameters) { cmd.WithParam(kvp.Key, kvp.Value); } var stream = await context.Connection.Process(cmd, true).ToTask(); context.LastResult = XElement.Load(stream); }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { var conn = context.PopConnection(); if (context.Connection == null) { context.PushConnection(conn); } else { var remote = conn as IRemoteConnection; if (remote != null) remote.Logout(false, true); } }
public async Task Run(TestContext context) { if (!string.IsNullOrWhiteSpace(this.Select)) { this.ActualValue = XPathResult.Evaluate(context.LastResult, this.Select, context.Connection).ToString(); context.Parameters[this.Name] = this.ActualValue; } else if (string.IsNullOrEmpty(this.Value)) { context.Parameters.Remove(this.Name); } else { context.Parameters[this.Name] = this.Value; } }
public async Task Run(TestContext context) { if (!string.IsNullOrWhiteSpace(this.Select)) { if (context.LastResult == null) throw new InvalidOperationException("Cannot assert a match when no query has been run"); context.Parameters[this.Name] = XPathResult.Evaluate(context.LastResult, this.Select).ToString(); } else if (string.IsNullOrEmpty(this.Value)) { context.Parameters.Remove(this.Name); } else { context.Parameters[this.Name] = this.Value; } }
public async Task Run(TestContext context) { if (context.LastResult == null) throw new InvalidOperationException("Cannot assert a match when no query has been run"); if (string.IsNullOrWhiteSpace(this.Match)) throw new ArgumentException("No match pattern is specified"); var res = XPathResult.Evaluate(context.LastResult, this.Match); var elemRes = res as ElementsXpathResult; if (elemRes != null) { var elem = elemRes.Elements; // Remove properties from the actual as needed if (RemoveSystemProperties) { foreach (var sysProp in elem.Descendants("created_on").Concat(elem.Descendants("modified_on")).ToArray()) { sysProp.Remove(); } } foreach (var remove in _removes) { foreach (var e in elem) { foreach (var toRemove in e.XPathSelectElements(remove).ToArray()) { toRemove.Remove(); } } } if (!elemRes.EqualsString(this.Expected)) { this.Expected = elemRes.ToString(); throw new AssertionFailedException(GetFaultString(context.LastResult, res)); } } else if (!res.EqualsString(this.Expected)) { this.Expected = res.ToString(); throw new AssertionFailedException(GetFaultString(context.LastResult, res)); } }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { var start = DateTime.UtcNow; string fromDate; if (!string.IsNullOrEmpty(From) && (DateTime.TryParse(From, out start) || (context.Parameters.TryGetValue(From, out fromDate) && DateTime.TryParse(fromDate, out start)))) { start = start.ToUniversalTime(); } int offset; if (!int.TryParse(BySeconds, out offset)) return; var delay = (int)(start.AddSeconds(offset) - DateTime.UtcNow).TotalMilliseconds; if (delay > 0) await Task.Delay(delay); }
public async Task Run(TestContext context) { var url = this.Url; var db = this.Database; var remoteConn = context.Connection as IRemoteConnection; if (string.IsNullOrEmpty(url) && remoteConn != null) url = remoteConn.Url.ToString(); if (string.IsNullOrEmpty(db)) db = context.Connection.Database; var prefs = new ConnectionPreferences() { UserAgent = "InnovatorAdmin UnitTest" }; var conn = await Factory.GetConnection(url, prefs, true).ToTask(); ICredentials cred; switch (this.Type) { case CredentialType.Anonymous: cred = new AnonymousCredentials(db); break; case CredentialType.Windows: cred = new WindowsCredentials(db); break; default: if (_password.IsNullOrEmpty()) { cred = context.CredentialStore.OfType<ExplicitCredentials>() .FirstOrDefault(c => string.Equals(c.Database, db) && string.Equals(c.Username, this.UserName)); } else { cred = new ExplicitCredentials(db, this.UserName, _password); } break; } if (cred == null) throw new InvalidOperationException("Could not create credentials for this login type"); await conn.Login(cred, true).ToTask(); context.PushConnection(conn); }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { _errorNode = GetPrimaryPath(context.LastResult) .FirstOrDefault(e => e.Name.LocalName == "Fault" && e.Name.NamespaceName == "http://schemas.xmlsoap.org/soap/envelope/"); }
public async Task Run(TestContext context) { _results.Clear(); _output.Clear(); using (context.StartSubProgress()) { var start = DateTime.Now; var i = 0; var pos = 0; var totalCount = _init.Count + _tests.Count + _cleanup.Count; try { for (i = 0; i < _init.Count; i++) { context.ReportProgress(pos, totalCount, "Running initialization..."); await _init[i].Run(context); pos += 1; } } catch (Exception ex) { _results.Add(new TestRun() { Name = "* Init", Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }); return; } for (i = 0; i < _tests.Count; i++) { context.ReportProgress(pos, totalCount, "Running test " + (i + 1) + "..."); _results.Add(await _tests[i].Run(context)); pos += 1; } try { for (i = 0; i < _cleanup.Count; i++) { context.ReportProgress(pos, totalCount, "Running cleanup..."); await _cleanup[i].Run(context); pos += 1; } } catch (Exception ex) { _results.Add(new TestRun() { Name = "* Cleanup", Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }); return; } foreach (var kvp in context.Parameters) { _output.Add(new ParamAssign() { Name = kvp.Key, Value = kvp.Value }); } } }
private async Task<IResultObject> ProcessTestSuite(string commands) { TestSuite suite; using (var reader = new StringReader(commands)) { suite = TestSerializer.ReadTestSuite(reader); } var context = new TestContext(_conn); await suite.Run(context); return new ResultObject(suite, _conn); }
public async Task Run(TestContext context) { _results.Clear(); _output.Clear(); var start = DateTime.Now; var i = 0; try { for (i = 0; i < _init.Count; i++) { await _init[i].Run(context); } } catch (Exception ex) { _results.Add(new TestRun() { Name = "* Init", Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }); return; } foreach (var test in _tests) { _results.Add(await test.Run(context)); } try { for (i = 0; i < _cleanup.Count; i++) { await _cleanup[i].Run(context); } } catch (Exception ex) { _results.Add(new TestRun() { Name = "* Cleanup", Result = TestResult.Fail, Start = start, ErrorLine = i + 1, Message = ex.Message }); return; } foreach (var kvp in context.Parameters) { _output.Add(new ParamAssign() { Name = kvp.Key, Value = kvp.Value }); } }
/// <summary> /// Code for executing the command /// </summary> public async Task Run(TestContext context) { if (context.LastResult == null) throw new InvalidOperationException("Cannot assert a match when no query has been run"); if (string.IsNullOrWhiteSpace(this.Match)) throw new ArgumentException("No match pattern is specified"); this.Actual = context.LastResult.ToString(); var res = XPathResult.Evaluate(context.LastResult, this.Match, context.Connection); var elemRes = res as ElementsXpathResult; if (elemRes != null) { this.IsXml = true; elemRes.Elements = elemRes.Elements.Select(e => new XElement(e)).ToArray(); var elems = elemRes.Elements; // Remove properties from the actual as needed if (RemoveSystemProperties) { // Remove system properties defined above foreach (var sysProp in elems.Descendants().Where(e => _systemProps.Contains(e.Name.LocalName)).ToArray()) { sysProp.Remove(); } // Remote item ID attributes foreach (var item in elems.DescendantsAndSelf().Where(e => e.Name.LocalName == "Item")) { var idAttr = item.Attribute("id"); if (idAttr != null) idAttr.Remove(); } // Remove source_id properties that aren't necessary foreach (var sourceId in elems.Descendants().Where(e => e.Name.LocalName == "source_id" && e.Parent != null && e.Parent.Name.LocalName == "Item" && e.Parent.Parent != null && e.Parent.Parent.Name.LocalName == "Relationships").ToArray()) { sourceId.Remove(); } // Remove redundant itemtype properties to save space foreach (var itemtype in elems.Descendants().Where(e => e.Name.LocalName == "itemtype" && e.Parent != null && e.Parent.Name.LocalName == "Item" && e.Parent.Attribute("typeId") != null && string.Equals(e.Value, e.Parent.Attribute("typeId").Value)).ToArray()) { itemtype.Remove(); } } foreach (var remove in _removes) { foreach (var e in elems) { foreach (var toRemove in e.XPathSelectElements(remove).ToArray()) { toRemove.Remove(); } } } if (!elemRes.EqualsString(this.Expected)) { this.Expected = elemRes.ToString(); throw new AssertionFailedException(GetFaultString(context.LastResult, res)); } } else if (!res.EqualsString(this.Expected)) { this.Expected = res.ToString(); throw new AssertionFailedException(GetFaultString(context.LastResult, res)); } }