public void TestMapperQuery() { var queryRunner = new MockQueryRunner(new QueryMapper()) { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } }, new Dictionary <string, object> { { "Id", 2 }, { "Name", "Test 2" } } } }; var result = queryRunner.Execute <SimpleDto>(new QuerySimple()).ToList(); Assert.IsNotNull(result); // ReSharper disable PossibleMultipleEnumeration Assert.AreEqual(2, result.Count()); var simpleDto = result.First(); // ReSharper restore PossibleMultipleEnumeration Assert.AreEqual(1, simpleDto.Id); Assert.AreEqual("Test", simpleDto.Name); }
public void TestPageQuery() { var queryRunner = new MockQueryRunner(new QueryMapper()) { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", (long)6 }, { "Name", "Test" } }, new Dictionary <string, object> { { "Id", 2 }, { "Name", "Test 2" } } } }; var pagedList = queryRunner.Execute <SimpleDto>(new QueryPageSpecification(page: 1, itemsPerPages: 2)); Assert.IsNotNull(pagedList); Assert.AreEqual(2, pagedList.Result.Count()); Assert.AreEqual(6, pagedList.TotalItems); Assert.AreEqual(3, pagedList.TotalPages); }
public void TestFirstOrDefaultQuery() { var queryRunner = new MockQueryRunner(new QueryMapper()) { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } }, new Dictionary <string, object> { { "Id", 2 }, { "Name", "Test 2" } } } }; var singleDto = queryRunner.Execute <SimpleDto>(new QuerySimple()).ToFirstOrDefault(); Assert.IsNotNull(singleDto); Assert.AreEqual(1, singleDto.Id); Assert.AreEqual("Test", singleDto.Name); }
public void TestParametersInQuery() { var queryRunner = new MockQueryRunner { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } } } }; queryRunner.ExecuteScalar <int>(new QueryWithParameters(1, "Test")); Assert.IsNotNull(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "id")); Assert.IsNotNull(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "name")); // ReSharper disable PossibleNullReferenceException var id = Convert.ToInt32(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "id").Value); var name = Convert.ToString(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "name").Value); // ReSharper restore PossibleNullReferenceException Assert.AreEqual(1, id); Assert.AreEqual("Test", name); }
public void TestFirstOrDefaultEmptyQuery() { var queryRunner = new MockQueryRunner(new QueryMapper()) { ReturnValues = new List <IDictionary <string, object> >() }; var singleDto = queryRunner.Execute <SimpleDto>(new QuerySimple()).ToFirstOrDefault(); Assert.IsNull(singleDto); }
public void TestScalarQuery() { var queryRunner = new MockQueryRunner { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } } } }; var id = queryRunner.ExecuteScalar <int>(new QuerySimple()); Assert.AreEqual(1, id); }
public void TestPageFailureCountQuery() { var queryRunner = new MockQueryRunner(new QueryMapper()) { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", "Execute scalar to return count, is not numeric" }, { "Name", "Test" } }, new Dictionary <string, object> { { "Id", "Other" }, { "Name", "Test 2" } } } }; queryRunner.Execute <SimpleDto>(new QueryPageSpecification(page: 1, itemsPerPages: 2)); }
public void TestSingleMapperFailureWithMorethanOneElementQuery() { var queryRunner = new MockQueryRunner(new QueryMapper()) { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } }, new Dictionary <string, object> { { "Id", 2 }, { "Name", "Test 2" } } } }; queryRunner.Execute <SimpleDto>(new QuerySimple()).ToSingle(); }
public void TestDataReaderQuery() { var queryRunner = new MockQueryRunner { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } } } }; var dr = queryRunner.ExecuteReader(new QuerySimple()); Assert.IsNotNull(dr); Assert.IsTrue(dr.Read()); Assert.AreEqual(1, Convert.ToInt32(dr["Id"])); Assert.AreEqual("Test", Convert.ToString(dr["Name"])); }
public void TestDataTableQuery() { var queryRunner = new MockQueryRunner { ReturnValues = new List <IDictionary <string, object> > { new Dictionary <string, object> { { "Id", 1 }, { "Name", "Test" } } } }; var dt = queryRunner.ExecuteDataTable(new QuerySimple()); Assert.IsNotNull(dt); Assert.IsNotNull(dt.Rows); Assert.AreEqual(1, dt.Rows.Count); Assert.AreEqual(1, Convert.ToInt32(dt.Rows[0]["Id"])); Assert.AreEqual("Test", Convert.ToString(dt.Rows[0]["Name"])); }