Skip to content

Instantly share code, notes, and snippets.

@arielmagbanua
Created February 20, 2020 15:00
Show Gist options
  • Save arielmagbanua/d4836c83b03f91ca4e90c71187bce2be to your computer and use it in GitHub Desktop.
Save arielmagbanua/d4836c83b03f91ca4e90c71187bce2be to your computer and use it in GitHub Desktop.
Test Class for IbsQueryBuilder.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ConsoleNancySelfHostedNetTest
{
[TestClass]
public class TestIbsQueryBuilder
{
public class MyModel : IbsQueryBuilder
{
}
[TestMethod]
public void TestQueryBuilder()
{
MyModel model = new MyModel();
string query1 = model.Where("name", "Ariel Magbanua")
.Where("age", ">", "28")
.Where("gender", "M")
.ToQuery();
string query2 = model.WhereRaw("foo=[bar] and max=3 or status=[active]")
.Where("age", ">", "30")
.ToQuery();
string query3 = model.WhereRaw("foo=[bar] and max=3 or status=[active]")
.Where("age", ">", "30")
.OrWhere("role", "!=", "1")
.OrWhere("company", "Zeald")
.ToQuery();
string query4 = model.Where("id", ">", "1")
.OrWhere("post_code", "8000")
.OrWhereRaw("city=[DAVAO] and bday=[1988-04-23]")
.ToQuery();
Assert.AreEqual("name=[Ariel Magbanua] and age>28 and gender=[M]", query1);
Assert.AreEqual("foo=[bar] and max=3 or status=[active] and age>30", query2);
Assert.AreEqual("foo=[bar] and max=3 or status=[active] and age>30 or role!=1 or company=[Zeald]", query3);
Assert.AreEqual("id>1 or post_code=8000 or city=[DAVAO] and bday=[1988-04-23]", query4);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment