public void TestOutputParameters() { using (var connection = Connection().OpenWithTransaction()) { var i = connection.As<ITestOutputParameters>(); // test execute with output parameter int original = 2; int p = original; i.ExecuteWithOutputParameter(out p); Assert.AreEqual(original + 1, p); // test executescalar with output parameter p = original; var scalar = i.ExecuteScalarWithOutputParameter(out p); Assert.AreEqual(original + 1, p); Assert.AreEqual(7, scalar); // test query with output parameters p = original; var results = i.QueryWithOutputParameter(out p); Assert.AreEqual(original + 1, p); Assert.AreEqual(1, results.Count); Assert.AreEqual(5, results[0]); // test query results with output parameters p = original; i.QueryResultsWithOutputParameter(out p); Assert.AreEqual(original + 1, p); // test insert with output parameters TestData data = new TestData() { Z = 4 }; var list = new List<TestData>() { data }; p = original; i.InsertWithOutputParameter(list, out p); Assert.AreEqual(original + 1, p); } }
public void TestMergeOutputAttribute() { var data = new TestData(); var i = Connection().As<IMergeOutputs>(); i.DoAMerge(data); Assert.AreEqual(4, data.X); Assert.AreEqual(6, data.Z); }
public void TestInsert() { using (var connection = Connection().OpenWithTransaction()) { var i = connection.As<ITestInsertUpdate>(); connection.Execute("ResetTestDataTable"); // single insert TestData data = new TestData() { Z = 4 }; i.InsertTestData(data); Assert.AreEqual(1, data.X, "ID should be returned"); // single update i.UpdateTestData(data); Assert.AreEqual(0, data.X, "ID should be reset"); // single upsert data = new TestData() { Z = 4 }; i.InsertTestData(data); Assert.AreEqual(2, data.X, "ID should be returned"); i.UpsertTestData(data); Assert.AreEqual(0, data.X, "ID should be reset"); // multiple insert var list = new[] { new TestData() { Z = 5 }, new TestData() { Z = 6 } }; i.InsertMultipleTestData(list); Assert.AreEqual(3, list[0].X, "ID should be returned"); Assert.AreEqual(4, list[1].X, "ID should be returned"); // multiple update i.UpsertMultipleTestData(list); Assert.AreEqual(0, list[0].X, "ID should be reset"); Assert.AreEqual(0, list[1].X, "ID should be reset"); // single insert data = new TestData() { Z = 4 }; i.InsertTestDataAsync(data).Wait(); Assert.AreEqual(5, data.X, "ID should be returned"); // single update i.UpsertTestDataAsync(data).Wait(); Assert.AreEqual(0, data.X, "ID should be reset"); // multiple insert list = new[] { new TestData() { Z = 5 }, new TestData() { Z = 6 } }; i.InsertMultipleTestDataAsync(list).Wait(); Assert.AreEqual(6, list[0].X, "ID should be returned"); Assert.AreEqual(7, list[1].X, "ID should be returned"); // multiple update i.UpsertMultipleTestDataAsync(list).Wait(); Assert.AreEqual(0, list[0].X, "ID should be reset"); Assert.AreEqual(0, list[1].X, "ID should be reset"); } }