Example #1
0
        public async Task Save_NoSequenceWithPk_CanInsert()
        {
            dynamic toSave = new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando();
            {
                var depts  = new Department(ProviderName);
                var result = await depts.SaveAsync(toSave);

                Assert.AreEqual(1, result);
                Assert.IsTrue(toSave.DEPTNO > 0);
                Assert.AreEqual(1, await depts.DeleteAsync(toSave.DEPTNO));
            }
            {
                // re-insert at the previous, deleted therefore valid, PK value but without using sequence to generate it;
                // actually tests that Oracle can insert user-managed PKs with no sequence
                var depts  = new MightyOrm(string.Format(TestConstants.ReadWriteTestConnection, ProviderName), "SCOTT.DEPT", "DEPTNO");
                int oldId  = toSave.DEPTNO;
                var result = await depts.InsertAsync(toSave);

                Assert.AreEqual(oldId, result.DEPTNO);
                Assert.AreEqual(1, await depts.DeleteAsync(toSave.DEPTNO));
            }
        }
Example #2
0
        public async Task Update_SingleRow_MappedExpando()
        {
            // Apply some quick crazy-ass mapping... to an ExpandoObject :-)
            // Remember, we're mapping from crazy fake 'class' names to the sensible underlying column names
            var categories = new MightyOrm(
                string.Format(TestConstants.WriteTestConnection, ProviderName),
                "MassiveWriteTests.Categories",
                primaryKeys: "MYCATEGORYID",
                columns: "MYCATEGORYID, TheName, ItsADescription",
                mapper: new SqlNamingMapper(columnNameMapping: (t, c) => c
                                            // 'class' names come first
                                            .Map("MYCATEGORYID", "CategoryID")
                                            .Map("TheName", "CategoryName")
                                            .Map("ItsADescription", "Description")));
            // insert something to update first.
            var inserted = await categories.InsertAsync(new { TheName = "Cool stuff", ItsADescription = "You know... cool stuff! Cool. n. stuff." });

            int insertedCategoryID = inserted.MYCATEGORYID;

            Assert.IsTrue(insertedCategoryID > 0);
            // update it, with a better description
            inserted.ItsADescription = "This is all jolly marvellous";
            Assert.AreEqual(1, await categories.UpdateAsync(inserted), "Update should have affected 1 row");
            var updatedRow = await categories.SingleAsync(new { inserted.MYCATEGORYID });

            Assert.IsNotNull(updatedRow);
            Assert.AreEqual(inserted.MYCATEGORYID, Convert.ToInt32(updatedRow.MYCATEGORYID)); // convert from uint
            Assert.AreEqual(inserted.ItsADescription, updatedRow.ItsADescription);
            // reset description to NULL
            updatedRow.ItsADescription = null;
            Assert.AreEqual(1, await categories.UpdateAsync(updatedRow), "Update should have affected 1 row");
            var newUpdatedRow = await categories.SingleAsync(new { updatedRow.MYCATEGORYID });

            Assert.IsNotNull(newUpdatedRow);
            Assert.AreEqual(updatedRow.MYCATEGORYID, newUpdatedRow.MYCATEGORYID);
            Assert.AreEqual(updatedRow.ItsADescription, newUpdatedRow.ItsADescription);
        }
Example #3
0
        //public Tuple<List<WorkOrder>,List<Product>> GetWorkOrdersAndProducts()
        //{
        //    var db = new MightyOrm("AdventureWorks2014");

        //    using (var db = new Database("AdventureWorks2014"))
        //    {
        //        return db.FetchMultiple<WorkOrder, Product>("SELECT TOP 500 * FROM[AdventureWorks2014].[Production].[WorkOrder];SELECT * FROM [Production].[Product];");
        //    }
        //}

        public async Task Add(WorkOrder workOrder)
        {
            var db = new MightyOrm <WorkOrder>("AdventureWorks2014");
            await db.InsertAsync(workOrder);
        }