This commit is contained in:
2020-03-03 00:28:43 +00:00
parent 3d39945368
commit 8430275c55

View File

@@ -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<long>()))
nActiveMatches++;
//if (NotActiveWidgetIdList.Contains(o["i"].Value<long>()))
@@ -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
/// <summary>
///
/// </summary>
[Fact]
public async void NullEqualityFilterWorks()
{
//OPS: equal to, not equal to
//values: null
var WidgetNameStart = "NullEqualityFilterWorks";
List<long> NullInCountWidgetIdList = new List<long>();
List<long> NotNullInCountWidgetIdList = new List<long>();
//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<long>());
//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<long>());
//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<long>());
//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<long>());
//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<long> IDInResultList = new List<long>();
int nNullCountMatches = 0;
int nNotNullCountMatches = 0;
foreach (JArray ja in v)
{
JObject o = ja[0] as JObject;
if (NullInCountWidgetIdList.Contains(o["i"].Value<long>()))
nNullCountMatches++;
//if (NotActiveWidgetIdList.Contains(o["i"].Value<long>()))
if (NotNullInCountWidgetIdList.Contains(o["i"].Value<long>()))
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);
}
}
/// <summary>
///
/// </summary>
[Fact]
public async void NullNotEqualFilterWorks()
{
//OPS: equal to, not equal to
//values: null
var WidgetNameStart = "NullNotEqualFilterWorks";
List<long> NullInCountWidgetIdList = new List<long>();
List<long> NotNullInCountWidgetIdList = new List<long>();
//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<long>());
//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<long>());
//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<long>());
//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<long>());
//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<long> IDInResultList = new List<long>();
int nNullCountMatches = 0;
int nNotNullCountMatches = 0;
foreach (JArray ja in v)
{
JObject o = ja[0] as JObject;
if (NullInCountWidgetIdList.Contains(o["i"].Value<long>()))
nNullCountMatches++;
//if (NotActiveWidgetIdList.Contains(o["i"].Value<long>()))
if (NotNullInCountWidgetIdList.Contains(o["i"].Value<long>()))
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);
}
}
// /// <summary>
// ///
// /// </summary>
// [Fact]
// public async void BoolOpNotEqualFilterWorks()
// {
// //OPS: equal to, not equal to
// //values: true, false
// var WidgetNameStart = "BoolDataFilterTest";
// List<long> ActiveWidgetIdList = new List<long>();
// List<long> NotActiveWidgetIdList = new List<long>();
// //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<long>());
// //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<long>());
// //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<long>());
// //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<long>());
// //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<long> IDInResultList = new List<long>();
// int nActiveMatches = 0;
// int nInactiveMatches = 0;
// foreach (JArray ja in v)
// {
// JObject o = ja[0] as JObject;
// if (ActiveWidgetIdList.Contains(o["i"].Value<long>()))
// nActiveMatches++;
// if (NotActiveWidgetIdList.Contains(o["i"].Value<long>()))
// 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