From 8430275c5503008470cc734c0202316d413ebe49 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 3 Mar 2020 00:28:43 +0000 Subject: [PATCH] --- DataList/DataListFiltering.cs | 346 +++++++++++++++++++++++++++++++++- 1 file changed, 345 insertions(+), 1 deletion(-) diff --git a/DataList/DataListFiltering.cs b/DataList/DataListFiltering.cs index 62f1419..88c340f 100644 --- a/DataList/DataListFiltering.cs +++ b/DataList/DataListFiltering.cs @@ -2803,7 +2803,7 @@ same as the server does but in a central location here for all tests to use. { JObject o = ja[0] as JObject; - + if (ActiveWidgetIdList.Contains(o["i"].Value())) nActiveMatches++; //if (NotActiveWidgetIdList.Contains(o["i"].Value())) @@ -3759,6 +3759,350 @@ same as the server does but in a central location here for all tests to use. #endregion ID filter tests + + + + /////////////////////////////////////////////////////////////////////////////// + //*NULL* TESTS + // + + #region *NULL* TESTS + + /// + /// + /// + [Fact] + public async void NullEqualityFilterWorks() + { + //OPS: equal to, not equal to + //values: null + + var WidgetNameStart = "NullEqualityFilterWorks"; + + List NullInCountWidgetIdList = new List(); + List NotNullInCountWidgetIdList = new List(); + + //CREATE 4 TEST WIDGETS + //two null count and two non null count + + //first null count widget + dynamic w = new JObject(); + w.name = Util.Uniquify(WidgetNameStart); + w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); + w.notes = "blah"; + w.active = true; + w.usertype = 1; + + ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + //second null count widget + w.name = Util.Uniquify(WidgetNameStart); + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + //first NON null in count widget + w.name = Util.Uniquify(WidgetNameStart); + w.count = 22; + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NotNullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + //second NON null in count field widget + w.name = Util.Uniquify(WidgetNameStart); + w.count = 33; + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NotNullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + //CREATE LISTVIEW + dynamic dListView = new JArray(); + + //name starts with filter to constrict to widgets that this test block created only + dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart)); + + //FILTER + // dynamic DataFilterActive = new JObject(); + // DataFilterActive.fld = "widgetactive"; + // DataFilterActive.op = Util.OpEquality; + // DataFilterActive.value = true; + dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetcount", Util.OpEquality, "*NULL*")); + + + //FETCH DATALIST + a = await Util.PostAsync($"DataList", await Util.GetTokenAsync("manager", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); + Util.ValidateDataReturnResponseOk(a); + Util.ValidateHTTPStatusCode(a, 200); + + //assert contains at least two records + ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1); + var v = ((JArray)a.ObjectResponse["data"]); + List IDInResultList = new List(); + int nNullCountMatches = 0; + int nNotNullCountMatches = 0; + + foreach (JArray ja in v) + { + JObject o = ja[0] as JObject; + + + if (NullInCountWidgetIdList.Contains(o["i"].Value())) + nNullCountMatches++; + //if (NotActiveWidgetIdList.Contains(o["i"].Value())) + if (NotNullInCountWidgetIdList.Contains(o["i"].Value())) + nNotNullCountMatches++; + } + + nNullCountMatches.Should().Be(NullInCountWidgetIdList.Count); + nNotNullCountMatches.Should().Be(0); + + //DELETE WIDGETS + foreach (long l in NullInCountWidgetIdList) + { + a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + } + + foreach (long l in NotNullInCountWidgetIdList) + { + a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + } + } + + /// + /// + /// + [Fact] + public async void NullNotEqualFilterWorks() + { + //OPS: equal to, not equal to + //values: null + + var WidgetNameStart = "NullNotEqualFilterWorks"; + + List NullInCountWidgetIdList = new List(); + List NotNullInCountWidgetIdList = new List(); + + //CREATE 4 TEST WIDGETS + //two null count and two non null count + + //first null count widget + dynamic w = new JObject(); + w.name = Util.Uniquify(WidgetNameStart); + w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); + w.notes = "blah"; + w.active = true; + w.usertype = 1; + + ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + //second null count widget + w.name = Util.Uniquify(WidgetNameStart); + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + //first NON null in count widget + w.name = Util.Uniquify(WidgetNameStart); + w.count = 22; + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NotNullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + //second NON null in count field widget + w.name = Util.Uniquify(WidgetNameStart); + w.count = 33; + + a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + Util.ValidateDataReturnResponseOk(a); + NotNullInCountWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + //CREATE LISTVIEW + dynamic dListView = new JArray(); + + //name starts with filter to constrict to widgets that this test block created only + dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart)); + + //FILTER + // dynamic DataFilterActive = new JObject(); + // DataFilterActive.fld = "widgetactive"; + // DataFilterActive.op = Util.OpEquality; + // DataFilterActive.value = true; + dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetcount", Util.OpNotEqual, "*NULL*")); + + + //FETCH DATALIST + a = await Util.PostAsync($"DataList", await Util.GetTokenAsync("manager", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); + Util.ValidateDataReturnResponseOk(a); + Util.ValidateHTTPStatusCode(a, 200); + + //assert contains at least two records + ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1); + var v = ((JArray)a.ObjectResponse["data"]); + List IDInResultList = new List(); + int nNullCountMatches = 0; + int nNotNullCountMatches = 0; + + foreach (JArray ja in v) + { + JObject o = ja[0] as JObject; + + + if (NullInCountWidgetIdList.Contains(o["i"].Value())) + nNullCountMatches++; + //if (NotActiveWidgetIdList.Contains(o["i"].Value())) + if (NotNullInCountWidgetIdList.Contains(o["i"].Value())) + nNotNullCountMatches++; + } + + nNotNullCountMatches.Should().Be(NullInCountWidgetIdList.Count); + nNullCountMatches.Should().Be(0); + + //DELETE WIDGETS + foreach (long l in NullInCountWidgetIdList) + { + a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + } + + foreach (long l in NotNullInCountWidgetIdList) + { + a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + Util.ValidateHTTPStatusCode(a, 204); + } + } + + // /// + // /// + // /// + // [Fact] + // public async void BoolOpNotEqualFilterWorks() + // { + + // //OPS: equal to, not equal to + // //values: true, false + + // var WidgetNameStart = "BoolDataFilterTest"; + + // List ActiveWidgetIdList = new List(); + // List NotActiveWidgetIdList = new List(); + + // //CREATE 4 TEST WIDGETS + // //two active and two non active + + // //first active widget + // dynamic w = new JObject(); + // w.name = Util.Uniquify(WidgetNameStart); + // w.customFields = Util.WidgetRequiredCustomFieldsJsonString(); + // w.notes = "blah"; + // w.active = true; + // w.usertype = 1; + + // ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + // Util.ValidateDataReturnResponseOk(a); + // ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + // //second active widget + // w.name = Util.Uniquify(WidgetNameStart); + + // a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + // Util.ValidateDataReturnResponseOk(a); + // ActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + // //first NON active widget + // w.name = Util.Uniquify(WidgetNameStart); + // w.active = false; + + // a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + // Util.ValidateDataReturnResponseOk(a); + // NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + // //second NON active widget + // w.name = Util.Uniquify(WidgetNameStart); + // w.active = false; + + // a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), w.ToString()); + // Util.ValidateDataReturnResponseOk(a); + // NotActiveWidgetIdList.Add(a.ObjectResponse["data"]["id"].Value()); + + + // //CREATE LISTVIEW + // dynamic dListView = new JArray(); + + // //name starts with filter to constrict to widgets that this test block created only + // dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetname", Util.OpStartsWith, WidgetNameStart)); + + // //FILTER + // // dynamic DataFilterActive = new JObject(); + // // DataFilterActive.fld = "widgetactive"; + // // DataFilterActive.op = Util.OpNotEqual; + // // DataFilterActive.value = true; + // dListView.Add(Util.BuildSimpleFilterDataListViewColumn("widgetactive", Util.OpNotEqual, true)); + + + + // //FETCH DATALIST + // a = await Util.PostAsync($"DataList", await Util.GetTokenAsync("manager", "l3tm3in"), Util.BuildDataListRequestEx(dListView)); + // Util.ValidateDataReturnResponseOk(a); + // Util.ValidateHTTPStatusCode(a, 200); + + // //assert contains at least two records + // ((JArray)a.ObjectResponse["data"]).Count.Should().BeGreaterThan(1); + // var v = ((JArray)a.ObjectResponse["data"]); + // List IDInResultList = new List(); + // int nActiveMatches = 0; + // int nInactiveMatches = 0; + + // foreach (JArray ja in v) + // { + // JObject o = ja[0] as JObject; + + // if (ActiveWidgetIdList.Contains(o["i"].Value())) + // nActiveMatches++; + // if (NotActiveWidgetIdList.Contains(o["i"].Value())) + // nInactiveMatches++; + // } + + // nInactiveMatches.Should().Be(NotActiveWidgetIdList.Count); + // nActiveMatches.Should().Be(0); + + // //DELETE WIDGETS + // foreach (long l in ActiveWidgetIdList) + // { + // a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + // Util.ValidateHTTPStatusCode(a, 204); + // } + + // foreach (long l in NotActiveWidgetIdList) + // { + // a = await Util.DeleteAsync("Widget/" + l.ToString(), await Util.GetTokenAsync("BizAdminFull")); + // Util.ValidateHTTPStatusCode(a, 204); + // } + + + // } + + #endregion *NULL* tests + + + + + //================================================== }//eoc