Пример #1
0
        /// <summary>
        /// When overridden in the derived class, runs the test.
        /// </summary>
        /// <param name="errorMessage">When the method returns false, contains an error message as to why
        /// the test failed. Otherwise, contains an empty string.</param>
        /// <returns>
        /// True if the test passed; false if the test failed.
        /// </returns>
        protected override bool RunTest(ref string errorMessage)
        {
            var schemaFile = MySqlHelper.DbSchemaFile;

            if (!File.Exists(schemaFile))
            {
                const string errmsg =
                    "The database schema file could not be found at path `{0}`, so this program will not be" +
                    " able to check your database schema to see if it is up-to-date.";
                errorMessage = string.Format(errmsg, schemaFile);
                return(false);
            }

            try
            {
                var schema = SchemaReader.Load(schemaFile);
                _schema = schema;
            }
            catch (Exception ex)
            {
                errorMessage = AppendErrorDetails(string.Format(_failMessage, schemaFile), ex.ToString());
                return(false);
            }

            return(true);
        }
        public async Task LoadSprocs()
        {
            var dl = new SchemaReader(connectionString);
            var manifest = await dl.Load(SchemaTypes.StoredProcedure);

            Assert.IsNotNull(manifest);
            Assert.AreEqual(1, manifest.Count());
            var manyTypes = manifest.FirstOrDefault();
            Assert.IsNotNull(manyTypes);
            Assert.AreEqual(16, manyTypes.Variables.Count());
        }
        public async Task LoadTable()
        {
            var dl = new SchemaReader(connectionString);
            var manifest = await dl.Load(SchemaTypes.Table);

            Assert.IsNotNull(manifest);
            Assert.AreEqual(2, manifest.Count());
            var table = (from m in manifest
                               where m.Preface == "dbo"
                               && m.Name == "LotsOfStuff"
                               select m).FirstOrDefault();
            Assert.IsNotNull(table);
            Assert.AreEqual(17, table.Variables.Count());
            var key = (from v in table.Variables
                       where v.IsPrimaryKey
                       select v).FirstOrDefault();
            Assert.IsNotNull(key);
            Assert.AreEqual("Id", key.ParameterName);
        }
        public async Task DualPrimaryKeys()
        {
            var dl = new SchemaReader(connectionString);
            var manifest = await dl.Load(SchemaTypes.Table);

            Assert.IsNotNull(manifest);
            Assert.AreEqual(2, manifest.Count());
            var table = (from m in manifest
                         where m.Preface == "dbo"
                         && m.Name == "DualPrimaryKeys"
                         select m).FirstOrDefault();
            Assert.IsNotNull(table);
            Assert.AreEqual(3, table.Variables.Count());
            var keys = from v in table.Variables
                       where v.IsPrimaryKey
                       select v;
            Assert.IsNotNull(keys);
            foreach (var key in keys)
            {
                Assert.IsTrue(key.ParameterName == "FirstId" || key.ParameterName == "SecondId");
            }
        }