public void TestValidate() { // Arrange var header = new Header { Name = "Root", Depth = -1, From = 0, To = 1, Children = new List <Header> { new Header { Name = "Arrange", Depth = 0, From = 0, To = 0, Children = new List <Header> { new Header { Name = "HttpRequest Actual", Depth = 1, From = 0, To = 0, Children = new List <Header> { new Header { Depth = 2, From = 0, To = 0, Name = "BaseUri" } } } } }, new Header { Name = "Assertion", Depth = 0, From = 1, To = 1, Children = new List <Header> { new Header { Name = "Uri", Depth = 1, From = 1, To = 1, } } } } }; // Act HeaderValidator.Validate(header); }
/// <summary> /// Parses csv to TestCases /// </summary> /// <param name="data">data parameter</param> /// <param name="resources">resources parameter</param> /// <returns>TestCase list</returns> public static TestCases Parse(List <List <string> > data, ResourceManager resources = null) { if (data == null || !data.Any()) { throw new ArgumentNullException("data"); } var rootHeader = HeaderParser.Parse(data); HeaderValidator.Validate(rootHeader); var cases = new TestCases(); var lastStartIndex = 0; for (var i = HeaderParser.HeaderRowCount; i < data.Count; i++) { var row = data[i]; if (!string.IsNullOrWhiteSpace(row[0])) { if (i != HeaderParser.HeaderRowCount) { cases.Add(TestCaseParser.Parse(rootHeader, data.GetRange(lastStartIndex, i - lastStartIndex), resources)); } lastStartIndex = i; } } cases.Add(TestCaseParser.Parse(rootHeader, data.GetRange(lastStartIndex, data.Count - lastStartIndex), resources)); return(cases); }
public void TestValidateWithInvalidName() { // Arrange var header = new Header { Name = "AA", }; // Act HeaderValidator.Validate(header); }
public void TestValidateWithInvalidNumberOfChildren() { // Arrange var header = new Header { Name = "Root", Children = new List <Header> { new Header(), new Header(), new Header(), } }; // Act HeaderValidator.Validate(header); }
private void Simpan_Click(object sender, EventArgs e) { if (!HeaderValidator.Validate()) { return; } UnitPurchaseModel unitPurchase = (UnitPurchaseModel)PembelianBindingSource.Current; unitPurchase.updated_by = Login.User.username; unitPurchase.updated_at = DateTime.Now; PembelianUnitOfWork.CommitChanges(); string kode = "PB/" + DateTime.Now.Year.ToString() + "/" + AutoDealer.Additional.DB.GetColumnName((int)Login.User.current_branch.id) + "/"; kode_pembelian.Text = AutoDealer.Additional.DB.AutoIncrement(kode, unitPurchase.id); PembelianBindingSource.EndEdit(); PembelianUnitOfWork.CommitChanges(); DetailXtraTabControl.Visible = true; }
public void TestParse() { // Arrange const string Csv = ",Arrange,,,,,,,,,,,Assertion,,,,,,,,,,,,,,,,,,,,\r\n" + ",HttpRequest Expected,,HttpRequest Actual,,,,,,,,,Uri,StatusCode,Headers,,Cookies,,Contents,,,,,,,,,,,,,,\r\n" + ",BaseUri,PathInfos,BaseUri,Headers,Cookies,,PathInfos,,QueryStrings,,Fragment,,,Content-Type,Last-Modified,Location,Degree,Name,IsList,IsDateTime,IsTime,Expected,,,,,,Actual,,,,\r\n" + ",,,,User-Agent,Location,Degree,,,locations,type,,,,,,,,,,,,Value,Query,Attribute,Pattern,Format,FormatCulture,Query,Attribute,Pattern,Format,FormatCulture"; // Act var root = HeaderParser.Parse(new CsvParser().Parse(Csv)); HeaderValidator.Validate(root); // Assert // depth=-1 (root) Assert.AreEqual("Root", root.Name); Assert.AreEqual(2, root.Children.Count); Assert.AreEqual(-1, root.Depth); Assert.AreEqual(0, root.From); Assert.AreEqual(32, root.To); // depth=0 (Arrange) var arrange = root.Children.ElementAt(0); Assert.AreEqual("Arrange", arrange.Name); Assert.AreEqual(0, arrange.Depth); Assert.AreEqual(1, arrange.From); Assert.AreEqual(11, arrange.To); Assert.AreEqual(2, arrange.Children.Count); // depth=0 (Assertion) var assertion = root.Children.ElementAt(1); Assert.AreEqual("Assertion", assertion.Name); Assert.AreEqual(0, assertion.Depth); Assert.AreEqual(12, assertion.From); Assert.AreEqual(32, assertion.To); Assert.AreEqual(5, assertion.Children.Count); // depth=1 (HttpRequest expected) var expected = arrange.Children.ElementAt(0); Assert.AreEqual("HttpRequest Expected", expected.Name); Assert.AreEqual(1, expected.Depth); Assert.AreEqual(1, expected.From); Assert.AreEqual(2, expected.To); Assert.AreEqual(2, expected.Children.Count); // depth=1 (HttpRequest actual) var actual = arrange.Children.ElementAt(1); Assert.AreEqual("HttpRequest Actual", actual.Name); Assert.AreEqual(1, actual.Depth); Assert.AreEqual(3, actual.From); Assert.AreEqual(11, actual.To); Assert.AreEqual(6, actual.Children.Count); // depth=1 (Uri) var uri = assertion.Children.ElementAt(0); Assert.AreEqual("Uri", uri.Name); Assert.AreEqual(1, uri.Depth); Assert.AreEqual(12, uri.From); Assert.AreEqual(12, uri.To); Assert.AreEqual(0, uri.Children.Count); // depth=1 (StatusCode) var statusCode = assertion.Children.ElementAt(1); Assert.AreEqual("StatusCode", statusCode.Name); Assert.AreEqual(1, statusCode.Depth); Assert.AreEqual(13, statusCode.From); Assert.AreEqual(13, statusCode.To); Assert.AreEqual(0, uri.Children.Count); // depth=1 (Headers) var headersA = assertion.Children.ElementAt(2); Assert.AreEqual("Headers", headersA.Name); Assert.AreEqual(1, headersA.Depth); Assert.AreEqual(14, headersA.From); Assert.AreEqual(15, headersA.To); Assert.AreEqual(2, headersA.Children.Count); // depth=1 (Cookies) var cookiesA = assertion.Children.ElementAt(3); Assert.AreEqual("Cookies", cookiesA.Name); Assert.AreEqual(1, cookiesA.Depth); Assert.AreEqual(16, cookiesA.From); Assert.AreEqual(17, cookiesA.To); Assert.AreEqual(2, cookiesA.Children.Count); // depth=1 (Contents) var contents = assertion.Children.ElementAt(4); Assert.AreEqual("Contents", contents.Name); Assert.AreEqual(1, contents.Depth); Assert.AreEqual(18, contents.From); Assert.AreEqual(32, contents.To); Assert.AreEqual(6, contents.Children.Count); // depth=2 (expected BaseUri) var baseUriArrange = expected.Children.ElementAt(0); Assert.AreEqual("BaseUri", baseUriArrange.Name); Assert.AreEqual(2, baseUriArrange.Depth); Assert.AreEqual(1, baseUriArrange.From); Assert.AreEqual(1, baseUriArrange.To); Assert.AreEqual(0, baseUriArrange.Children.Count); }