Example #1
0
        public void Rescan()
        {
            // Set default operator.
            SetDefault();

            // Activate base type to load assembly for tests.
            _ = new Table2Type();

            // Scan.
            SqlOperatorHandler.RescanDatabaseStructure();
        }
Example #2
0
        public void Generate()
        {
            // Set default operator.
            SetDefault();

            #region Schema test
            // Create schema.
            bool chemaResult = SqlOperatorHandler.Active.ActivateSchema("testSchema", out string error);
            if (chemaResult)
            {
                chemaResult = SqlOperatorHandler.Active.ActivateSchema("testSchema2", out error);
            }
            if (!chemaResult)
            {
                Assert.Fail("Schema not created. " + error);
                return;
            }
            #endregion

            #region Table set test
            // Generate tables.
            bool tableResult = UniformDataOperator.Sql.Markup.TableAttribute.TrySetTables(
                true, out error,
                typeof(TableType),
                typeof(Table2Type),
                typeof(Table3Type),
                typeof(Table4Type),
                typeof(Table5Type));
            if (!tableResult)
            {
                Assert.Fail("Table not created. " + error);
                return;
            }
            #endregion

            #region Data auto-write
            Table2Type data2 = new Table2Type()
            {
                intFK     = 0,
                stringVar = "Test init"
            };
            bool setResult = SqlOperatorHandler.Active.SetToTable(typeof(Table2Type), data2, out error);
            if (!setResult)
            {
                Assert.Fail("Data2 set not operated. " + error);
                return;
            }

            // Set obejct's data.
            TableType data = new TableType()
            {
                pk      = 1,
                intVar  = 99,
                uintVar = 42,
                blob    = new BlobType()
                {
                    i  = -10000,
                    s  = "set test",
                    ui = 9999
                },
                IntProp = -256,
                fk      = 0
            };
            setResult = SqlOperatorHandler.Active.SetToTable(typeof(TableType), data, out error);
            if (!setResult)
            {
                Assert.Fail("Data set not operated. " + error);
                return;
            }
            #endregion

            #region Data auto-read
            // Initialize object with desciped primary keys that would be used as source for data request.
            TableType readedObject = new TableType()
            {
                pk = 1
            };

            // Variable that would contain error's message in case of occuring.
            string readingError = null;
            // Subscribing on errors occuring event.
            void SqlOperatorHandler_SqlErrorOccured(object arg1, string arg2)
            {
                // Unsubscribe.
                SqlOperatorHandler.SqlErrorOccured -= SqlOperatorHandler_SqlErrorOccured;

                readingError = arg2;
            }

            SqlOperatorHandler.SqlErrorOccured += SqlOperatorHandler_SqlErrorOccured;

            // Request data set from server.
            SqlOperatorHandler.Active.SetToObjectAsync(
                typeof(TableType),
                new System.Threading.CancellationToken(),
                readedObject,
                "intVar",
                "uintVar",
                "intFK",
                "intProp",
                "blobProp");

            Assert.IsTrue(readingError == null, readingError);
            #endregion
        }