Esempio n. 1
0
        public void Test_DW_Delete()
        {
            InitSamples();
            var before = GetCountOfSamples();

            Assert.AreNotEqual(0, before);
            var dw         = GetDataWorker();
            var testobject = new SampleClass {
                ID = 1
            };

            Assert.AreNotEqual(0, testobject.ID);
            var result        = dw.Delete <SampleClass>(testobject);
            var after         = GetCountOfSamples();
            var expectedAfter = before - 1;

            Assert.IsTrue(result);
            Assert.AreEqual(expectedAfter, after);
            Assert.AreNotEqual(0, testobject.ID);
        }
Esempio n. 2
0
        public void Test_DW_Insert()
        {
            InitSamples();
            var before = GetCountOfSamples();

            Assert.AreNotEqual(0, before);
            var dw         = GetDataWorker();
            var testobject = new SampleClass {
                Name = "Test Object"
            };

            Assert.AreEqual(0, testobject.ID);
            var result        = dw.Insert <SampleClass>(testobject);
            var after         = GetCountOfSamples();
            var expectedAfter = before + 1;

            Assert.IsTrue(result);
            Assert.AreEqual(expectedAfter, after);
            Assert.AreNotEqual(0, testobject.ID);
        }
Esempio n. 3
0
        public void TestSelectFilteredFromDataObject()
        {
            var dw  = GetDataWorker();
            var dwt = new DataWorkerTask();

            dwt.CommandText = "select * from samples where id <= @ID";
            dwt.CommandType = CommandType.Text;
            dwt.ReadResults = true;
            dwt.Mode        = DataWorkerMode.DataFields;
            var dataObject = new SampleClass {
                ID = 2
            };
            var result = dw.DoWorkDirect <SampleClass>(dwt, dataObject);

            Assert.AreNotEqual(0, result.Count);
            foreach (var item in result)
            {
                Assert.IsTrue(item.ID <= 2);
            }
        }
Esempio n. 4
0
        public void TestOptionalParamsPopulated()
        {
            var dw  = GetDataWorker();
            var dwt = new DataWorkerTask();

            dwt.CommandText = "TestMissingAndNullInput";
            dwt.ReadResults = true;
            dwt.Mode        = DataWorkerMode.AllProperties;
            var obj = new SampleClass {
                RequiredParam  = 42,                // required
                OptionalParam1 = 43,
                OptionalParam2 = null,
            };
            var result = dw.DoWorkDirect <SampleClass>(dwt, obj);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(obj.RequiredParam, result[0].RequiredParamOut);
            Assert.AreEqual(obj.OptionalParam1, result[0].OptionalParam1Out);
            Assert.AreEqual(obj.OptionalParam2, result[0].OptionalParam2Out);
        }
Esempio n. 5
0
        public void Test_DW_Fetch_NoResult()
        {
            InitSamples();
            var before = GetCountOfSamples();

            Assert.AreNotEqual(0, before);
            var dw         = GetDataWorker();
            int loadID     = -1;
            var testobject = new SampleClass {
                ID = loadID
            };

            Assert.AreNotEqual(0, testobject.ID);
            Assert.IsNullOrEmpty(testobject.Name);
            var result        = dw.Fetch <SampleClass>(testobject);
            var after         = GetCountOfSamples();
            var expectedAfter = before;

            Assert.IsNull(result);
            Assert.AreEqual(expectedAfter, after);
            Assert.AreEqual(loadID, testobject.ID);
        }
Esempio n. 6
0
        public void TestSelectColumnNameRemapping()
        {
            var dw  = GetDataWorker();
            var dwt = new DataWorkerTask();

            dwt.CommandText = "ListNotSimple";
            dwt.CommandType = CommandType.StoredProcedure;
            dwt.ReadResults = true;
            dwt.Mode        = DataWorkerMode.DataFields;
            var msg        = "any message";
            var dataobject = new SampleClass {
                SimpleColumnIn = msg
            };
            var result = dw.DoWorkDirect <SampleClass>(dwt, dataobject);

            Assert.AreNotEqual(0, result.Count);
            foreach (var item in result)
            {
                Assert.IsTrue(item.ID != 0);
                Assert.IsNotNullOrEmpty(item.Name);
                Assert.AreEqual(msg, item.SimpleColumnOut);
            }
        }
Esempio n. 7
0
        public void Test_DW_Fetch_InferredType()
        {
            InitSamples();
            var before = GetCountOfSamples();

            Assert.AreNotEqual(0, before);
            var dw         = GetDataWorker();
            int loadID     = 3;
            var testobject = new SampleClass {
                ID = loadID
            };

            Assert.AreNotEqual(0, testobject.ID);
            Assert.IsNullOrEmpty(testobject.Name);
            var result        = dw.Fetch(testobject);
            var after         = GetCountOfSamples();
            var expectedAfter = before;
            var expectedName  = "three";

            Assert.IsNotNull(result);
            Assert.AreEqual(expectedAfter, after);
            Assert.AreEqual(expectedName, result.Name);
            Assert.AreEqual(loadID, result.ID);
        }