示例#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));
        }
示例#2
0
文件: Globals.cs 项目: uolton/Mighty
        public void NpgsqlSettings_DefaultsOrdering()
        {
            var db1 = new MightyOrm();
            var db2 = new MightyOrm <Film>();
            var db3 = new MightyOrm <Category>();

            MightyOrm.GlobalNpgsqlAutoDereferenceFetchSize         = 40000;
            MightyOrm <Film> .GlobalNpgsqlAutoDereferenceFetchSize = 30000;
            var db4 = new MightyOrm();
            var db5 = new MightyOrm <Film>();
            var db6 = new MightyOrm <Category>();

            MightyOrm.GlobalNpgsqlAutoDereferenceFetchSize = null;
            var db7 = new MightyOrm <Film>();
            var db8 = new MightyOrm <Category>();

            MightyOrm <Film> .GlobalNpgsqlAutoDereferenceFetchSize = null;

            Assert.AreEqual(10000, db1.NpgsqlAutoDereferenceFetchSize);
            Assert.AreEqual(10000, db2.NpgsqlAutoDereferenceFetchSize);
            Assert.AreEqual(10000, db3.NpgsqlAutoDereferenceFetchSize);

            Assert.AreEqual(40000, db4.NpgsqlAutoDereferenceFetchSize);
            Assert.AreEqual(30000, db5.NpgsqlAutoDereferenceFetchSize);
            Assert.AreEqual(40000, db6.NpgsqlAutoDereferenceFetchSize);

            Assert.AreEqual(30000, db7.NpgsqlAutoDereferenceFetchSize);
            Assert.AreEqual(10000, db8.NpgsqlAutoDereferenceFetchSize);
        }
示例#3
0
 private Orders GetOrder(MightyOrm <Orders> db, int id)
 {
     return(db.Query(@"SELECT [WorkOrderID] AS Id, P.Name AS ProductName, [OrderQty] AS Quantity, [DueDate] AS Date
                                       FROM [AdventureWorks2014].[Production].[WorkOrder] AS WO 
                                       INNER JOIN[Production].[Product] AS P ON P.ProductID = WO.ProductID
                                       WHERE WorkOrderID = @0", id).FirstOrDefault());
 }
        private static void storeTestResult(MightyOrm db, TestResult tr, int tcID)
        {
            var insert = db.New();

            insert.TestCaseID            = tcID;
            insert.Iteration             = tr.Iteration;
            insert.Excursion             = tr.Excursion;
            insert.NumDirectionalRuns    = tr.NumDirectionalRuns;
            insert.LenDirectionalRuns    = tr.LenDirectionalRuns;
            insert.NumIncreasesDecreases = tr.NumIncreasesDecreases;
            insert.NumRunsMedian         = tr.NumRunsMedian;
            insert.LenRunsMedian         = tr.LenRunsMedian;
            insert.AvgCollision          = tr.AvgCollision;
            insert.MaxCollision          = tr.MaxCollision;
            insert.Periodicity1          = tr.Periodicity1;
            insert.Periodicity2          = tr.Periodicity2;
            insert.Periodicity8          = tr.Periodicity8;
            insert.Periodicity16         = tr.Periodicity16;
            insert.Periodicity32         = tr.Periodicity32;
            insert.Covariance1           = tr.Covariance1;
            insert.Covariance2           = tr.Covariance2;
            insert.Covariance8           = tr.Covariance8;
            insert.Covariance16          = tr.Covariance16;
            insert.Covariance32          = tr.Covariance32;
            insert.Compression           = tr.Compression;
            db.Insert(insert);

            Console.WriteLine(insert.TestResultID);
        }
        public static void storeTestRun(TestRun tr)
        {
            MightyOrm db           = DatabaseConnector.createConnectionTestRun();
            MightyOrm dbTc         = DatabaseConnector.createConnectionTestCase();
            MightyOrm dbTestResult = DatabaseConnector.createConnectionTestResult();

            var insert = db.New();

            insert.Category = tr.Category;
            insert.Sha256   = tr.Sha256;
            insert.Filename = tr.Filename;
            db.Insert(insert);

            List <TestCase> testCases = tr.TestCases;

            if (testCases != null && testCases.Count > 0)
            {
                foreach (TestCase tc in testCases)
                {
                    DatabaseConnector.storeTestCase(dbTc, dbTestResult, tc, insert.TestRunID);
                }
            }

            Console.WriteLine(insert.TestRunID);
        }
示例#6
0
        public async Task <List <WorkOrder> > GetWorkOrdersWithProduct()
        {
            new MightyOrm();
            var db = new MightyOrm <WorkOrder>("AdventureWorks2014");

            return(await GetWorkOrdersWithProduct(db));
        }
示例#7
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);
        }
示例#8
0
        public List <Orders> GetOrders()
        {
            var db = new MightyOrm <Orders>("AdventureWorks2014");

            return(db.Query(@"SELECT TOP 500 [WorkOrderID] AS Id, P.Name AS ProductName, [OrderQty] AS Quantity, [DueDate] AS Date
                            FROM [AdventureWorks2014].[Production].[WorkOrder] AS WO 
                            INNER JOIN[Production].[Product] AS P ON P.ProductID = WO.ProductID").ToList());
        }
示例#9
0
        public void OutputParamFromRawSql_IsMoreBetter()
        {
            var db     = new MightyOrm(ConnectionStrings.AdventureWorksFull);
            var result = db.ExecuteWithParams("SELECT @MyOutParam = @0 + 13 WHERE 42 = @0",
                                              outParams: new { MyOutParam = (int?)null }, args: 44);

            Assert.IsNull(result.MyOutParam);
        }
示例#10
0
#pragma warning disable CS1998
        public async Task Save_NoSequenceNoPk_ThrowsCannotInsertNull()
        {
            var     depts = new MightyOrm(string.Format(TestConstants.ReadWriteTestConnection, ProviderName), "SCOTT.DEPT", "DEPTNO");
            dynamic toSave = new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando();
            var     ex = Assert.CatchAsync <DbException>(async() => await depts.SaveAsync(toSave));

            Assert.True(ex.Message.Contains("cannot insert NULL"));
        }
        public static TaskQueueItem getNextTaskQueueItem()
        {
            MightyOrm <TaskQueueItem> db = DatabaseConnector.createConnectionTaskQueueItem();
            // TaskQueueItem tq = db.Single("SELECT * from TaskQueue");
            TaskQueueItem tq = db.Single("");

            return(tq);
        }
示例#12
0
        private async Task <List <WorkOrder> > GetWorkOrdersWithProduct(MightyOrm <WorkOrder> db)
        {
            var data = await db.QueryAsync(@"SELECT TOP 500 WO.*, P.* 
                                                  FROM [AdventureWorks2014].[Production].[WorkOrder] AS WO 
                                                  INNER JOIN[Production].[Product] AS P ON P.ProductID = WO.ProductID");

            return(await data.ToListAsync());
        }
示例#13
0
        public void ProcedureWithNameDirectionArgs_Runs()
        {
            var db     = new MightyOrm(ConnectionStrings.AdventureWorksFull);
            var result = db.ExecuteProcedure("my_add_proc",
                                             inParams: new { a = 1, b = 2 },
                                             returnParams: new { c = (int?)null });

            Assert.AreEqual(3, result.c);
        }
示例#14
0
        public void OutputParamFromRawSql_IsBetter()
        {
            var db     = new MightyOrm(ConnectionStrings.AdventureWorksFull);
            var result = db.ExecuteWithParams("SELECT @sum = @0 + @0 + @1",
                                              outParams: new { sum = (int?)null },
                                              args: new object[] { 1, 3 });

            Assert.AreEqual(5, result.sum);
        }
示例#15
0
        public void OutputParamFromRawSql_IsBetter2()
        {
            var db     = new MightyOrm(ConnectionStrings.AdventureWorksFull);
            var result = db.ExecuteWithParams("SELECT @sum = @a + @a + @b",
                                              outParams: new { sum = (int?)null },
                                              inParams: new { a = 1, b = 3 });

            Assert.AreEqual(5, result.sum);
        }
示例#16
0
文件: ReadTests.cs 项目: brgrz/Mighty
        public void WorksWithSpacedStrangeCaseConnectionString()
        {
            var from = "ProviderName=";
            var to   = " PrOviDernamE =   ";

            Assert.That(TestConstants.ReadTestConnection.Contains(from), $"{TestConstants.ReadTestConnection} does not contain {from}");
            var db   = new MightyOrm(string.Format(TestConstants.ReadTestConnection.Replace(from, to), TestConstants.ProviderName));
            var item = db.SingleFromQuery("SELECT 1 AS a");

            Assert.That(item.a, Is.EqualTo(1));
        }
示例#17
0
        public void Setup()
        {
            BaseSetup();

            // Mighty needs the connection string to contain the ProviderName in addition to everything else for Reasons.
            // However, it appears the SQL Server driver chokes on it if it's in the full connection string, so we programatically add it here.
            var connectionString = $"{ConnectionStringSettings.ConnectionString};ProviderName={ConnectionStringSettings.ProviderName}";

            _model        = new MightyOrm <Post>(connectionString);
            _dynamicModel = new MightyOrm(connectionString);
        }
示例#18
0
        public List <Orders> GetOrders(int iteration)
        {
            var db         = new MightyOrm <Orders>("AdventureWorks2014");
            var listOrders = new List <Orders>();

            for (int i = 1; i <= iteration; i++)
            {
                listOrders.Add(GetOrder(db, i));
            }

            return(listOrders);
        }
        private static void storeTestCase(MightyOrm db, MightyOrm dbTr, TestCase tc, int trID)
        {
            var insert = db.New();

            insert.TestRunID     = trID;
            insert.TestCaseDesc  = tc.TestCaseDesc;
            insert.HOriginal     = tc.HOriginal;
            insert.HBitString    = tc.HBitstring;
            insert.HAssessed     = tc.HAssessed;
            insert.RetMinEntropy = tc.RetMinEntropy;
            insert.DataWordSize  = tc.DataWordSize;
            insert.BinTTupleRes  = tc.BinTTupleRes;
            insert.TTupleRes     = tc.TTupleRes;
            insert.BinLrsRes     = tc.BinLrsRes;
            insert.LrsRes        = tc.LrsRes;
            insert.Mean          = tc.Mean;
            insert.Median        = tc.Median;
            insert.Binary        = tc.Binary;

            insert.LiteralMCVEstimateMode                   = tc.LiteralMCVEstimateMode;
            insert.LiteralMCVEstimatePHat                   = tc.LiteralMCVEstimatePHat;
            insert.LiteralMCVEstimatePU                     = tc.LiteralMCVEstimatePU;
            insert.BitstringMCVEstimateMode                 = tc.BitstringMCVEstimateMode;
            insert.BitstringMCVEstimatePHat                 = tc.BitstringMCVEstimatePHat;
            insert.BitstringMCVEstimatePU                   = tc.BitstringMCVEstimatePU;
            insert.ChiSquareIndependenceScore               = tc.ChiSquareIndependenceScore;
            insert.ChiSquareIndependenceDegressOfFreedom    = tc.ChiSquareIndependenceDegressOfFreedom;
            insert.ChiSquareIndependencePValue              = tc.ChiSquareIndependencePValue;
            insert.ChiSquareGoodnessOfFitScore              = tc.ChiSquareGoodnessOfFitScore;
            insert.ChiSquareGoodnessOfFitDegressOfFreedom   = tc.ChiSquareGoodnessOfFitDegressOfFreedom;
            insert.ChiSquareGoodnessOfFit_p_value           = tc.ChiSquareGoodnessOfFit_p_value;
            insert.PassedChiSquareTests                     = tc.PassedChiSquareTests;
            insert.LongestRepeatedSubstringPCol             = tc.LongestRepeatedSubstringPCol;
            insert.LongestRepeatedSubstringLengthOfLrs      = tc.LongestRepeatedSubstringLengthOfLrs;
            insert.LongestRepeatedSubstringPRX1             = tc.LongestRepeatedSubstringPRX1;
            insert.PassedLengthLongestRepeatedSubstringTest = tc.PassedLengthLongestRepeatedSubstringTest;
            insert.PassedIidPermutationTests                = tc.PassedIidPermutationTests;

            db.Insert(insert);

            List <TestResult> testResults = tc.TestResults;

            if (testResults != null && testResults.Count > 0)
            {
                foreach (TestResult tr in testResults)
                {
                    DatabaseConnector.storeTestResult(dbTr, tr, insert.TestCaseID);
                }
            }

            Console.WriteLine(insert.TestCaseID);
        }
示例#20
0
        public void BoolTypes()
        {
            var db      = new MightyOrm <BitTest>(string.Format(TestConstants.WriteTestConnection, ProviderName));
            var results = db.All();

            foreach (var result in results)
            {
                // check all the bool values, which - note - come out the same on either driver
                Assert.That(result.tinyint_bool, Is.EqualTo(result.id != 1), "tinyint_bool");
                Assert.That(result.tinyint_one, Is.EqualTo(result.id != 1), "tinyint_one");
                Assert.That(result.bit_one, Is.EqualTo(result.id == 2), "bit_one");
            }
        }
        public static bool removeTaskQueueItem(int taskQueueID)
        {
            MightyOrm <TaskQueueItem> db = DatabaseConnector.createConnectionTaskQueueItem();
            int numberRemoved            = db.Delete(taskQueueID);

            if (numberRemoved > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#22
0
        public void Guid_Arg()
        {
            // PostgreSQL has true Guid type support
            var     db   = new MightyOrm(string.Format(TestConstants.ReadWriteTestConnection, TestConstants.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 = db.Single(command);
            }
            Assert.AreEqual(guid, item.val);
        }
示例#23
0
        public void Guid_Arg()
        {
            // SQL Server has true Guid type support
            var     db   = new MightyOrm(TestConstants.ReadTestConnection);
            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 = db.Single(command);
            }
            Assert.AreEqual(guid, item.val);
        }
示例#24
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);
        }
示例#25
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));
        }
        public static bool isTaskQueueEmpty()
        {
            MightyOrm <TaskQueueItem> db = DatabaseConnector.createConnectionTaskQueueItem();
            // TaskQueueItem tq = db.Single("SELECT * from TaskQueue");

            TaskQueueItem tq = db.Single("");

            if (tq == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#27
0
        private IEnumerable <dynamic> LoadTableMetaData(bool isGeneric, TableMetaDataKey key, object Mighty)
        {
            var sql = key.Plugin.BuildTableMetaDataQuery(key.BareTableName, key.TableOwner);
            IEnumerable <dynamic> unprocessedMetaData;
            dynamic db = Mighty;

            if (isGeneric)
            {
                // we need a dynamic query, so on the generic version we create a new dynamic DB object with the same connection info
                db = new MightyOrm(connectionProvider: new PresetsConnectionProvider(key.ConnectionString, key.Factory, key.Plugin.GetType()));
            }
            unprocessedMetaData = (IEnumerable <dynamic>)db.Query(sql, key.BareTableName, key.TableOwner);
            var postProcessedMetaData = key.Plugin.PostProcessTableMetaData(unprocessedMetaData);

            return(FilterTableMetaData(key, postProcessedMetaData));
        }
示例#28
0
        private IEnumerable <dynamic> LoadTableMetaData(bool isGeneric, TableMetaDataKey key, dynamic Mighty, DbConnection connection)
        {
            var sql = key.Plugin.BuildTableMetaDataQuery(key.BareTableName, key.TableOwner);
            IEnumerable <dynamic> unprocessedMetaData;
            dynamic db = Mighty;

            if (isGeneric)
            {
                // we need a dynamic query, so on the generic version we create a new dynamic DB object with the same connection info
                db = new MightyOrm(connectionProvider: new PresetsConnectionProvider(connection == null ? key.ConnectionString : null, key.Factory, key.Plugin.GetType()));
            }
            unprocessedMetaData = (IEnumerable <dynamic>)db.Query(sql, connection, key.BareTableName, key.TableOwner);
            var postProcessedMetaData = key.Plugin.PostProcessTableMetaData(unprocessedMetaData);

            if (postProcessedMetaData.Count == 0)
            {
                throw new InvalidOperationException($"Cannot find any meta-data for table {(key.TableOwner == null ? "" : $"{key.TableOwner }.")}{key.BareTableName} in database");
示例#29
0
        public void Guid_Arg()
        {
            // Oracle has no Guid parameter support, Massive maps Guid to string in Oracle
            var     db        = new MightyOrm(string.Format(TestConstants.ReadWriteTestConnection, ProviderName));
            var     guid      = Guid.NewGuid();
            var     inParams  = new { inval = guid };
            var     outParams = new { val = new Guid() };
            dynamic item;

            using (var command = db.CreateCommandWithParams("begin :val := :inval; end;", inParams: inParams, outParams: outParams))
            {
                Assert.AreEqual(DbType.String, command.Parameters[0].DbType);
                db.Execute(command);
                item = db.ResultsAsExpando(command);
            }
            Assert.AreEqual(typeof(string), item.val.GetType());
            Assert.AreEqual(guid, new Guid(item.val));
        }
示例#30
0
 public void Save_NoSequenceWithPk_CanInsert()
 {
     dynamic toSave = new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando();
     {
         var depts  = new Department(ProviderName);
         var result = depts.Save(toSave);
         Assert.AreEqual(1, result);
         Assert.IsTrue(toSave.DEPTNO > 0);
         Assert.AreEqual(1, depts.Delete(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 = depts.Insert(toSave);
         Assert.AreEqual(oldId, result.DEPTNO);
         Assert.AreEqual(1, depts.Delete(toSave.DEPTNO));
     }
 }