Beispiel #1
0
        public async Task Guid_Arg()
        {
            var     db   = new MightyOrm(TestConstants.ReadWriteTestConnection);
            var     guid = Guid.NewGuid();
            dynamic item;

            using (var command = db.CreateCommand("SELECT @0 AS val", null, guid))
            {
#if NETCOREAPP
                // For some reason .NET Core provider doesn't have DbType.Guid support even though .NET Framework provider does
                Assert.AreEqual(DbType.String, command.Parameters[0].DbType);
#else
                Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType);
#endif
                item = await db.SingleAsync(command);
            }
            // The output from the provider is a bunch of bytes either way, so we stick with the provider
            // default here (especially since it is the same in both cases).
#if NETCOREAPP2_0 || NETCOREAPP3_0 || NETCOREAPP3_1
            // This changed from `byte[]` to `string` somewhere between System.Data.SQLite 1.0.105 and 1.0.111
            Assert.AreEqual(typeof(string), item.val.GetType());
#else
            Assert.AreEqual(typeof(byte[]), item.val.GetType());
#endif
            Assert.AreEqual(guid, new Guid(item.val));
        }
Beispiel #2
0
        public async Task Use_GlobalConnectionString()
        {
            MightyOrm.GlobalConnectionString = WhenDevart.AddLicenseKey(ProviderName, string.Format(TestConstants.ReadTestConnection, ProviderName));
            dynamic film           = new MightyOrm(tableName: "sakila.film");
            var     singleInstance = await film.SingleAsync(new { film_id = 43 });

            Assert.AreEqual(43, singleInstance.film_id);
        }
Beispiel #3
0
        public async Task Guid_Arg()
        {
            // PostgreSQL has true Guid type support
            var     db   = new MightyOrm(TestConstants.ReadWriteTestConnection);
            var     guid = Guid.NewGuid();
            dynamic item;

            using (var command = db.CreateCommand("SELECT @0 AS val", null, guid))
            {
                Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType);
                item = await db.SingleAsync(command);
            }
            Assert.AreEqual(guid, item.val);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public async Task Guid_Arg()
        {
            // MySQL has native Guid parameter support, but the SELECT output is a string
            var     db   = new MightyOrm(WhenDevart.AddLicenseKey(ProviderName, string.Format(TestConstants.ReadTestConnection, ProviderName)));
            var     guid = Guid.NewGuid();
            dynamic item;

            using (var command = db.CreateCommand("SELECT @0 AS val", null, guid))
            {
                Assert.AreEqual(DbType.Guid, command.Parameters[0].DbType);
                item = await db.SingleAsync(command);
            }
            Assert.AreEqual(typeof(string), item.val.GetType());
            Assert.AreEqual(guid, new Guid(item.val));
        }