Exemplo n.º 1
0
        public void GenerateScriptTest()
        {
            var dbConnection = DbConnection.From(modelConnection, "unemployment");
            var service      = new DbUpgradeService(dbConnection);
            var dacpac       = service.GenerateDacPac();

            var script = service.GenerateUpgradeScript(dacpac, DbUpgradeOptions.From(ObjectType.Users, ObjectType.Views, ObjectType.RoleMembership, ObjectType.Permissions, ObjectType.ExtendedProperties, ObjectType.StoredProcedures, ObjectType.Logins, ObjectType.DatabaseTriggers, ObjectType.ServerTriggers), "newdb");

            Assert.IsNotNull(script);
        }
Exemplo n.º 2
0
        public void GenerateDacPacTest()
        {
            var dbConnection = DbConnection.From(modelConnection, "unemployment");
            var service      = new DbUpgradeService(dbConnection);
            var result       = service.GenerateDacPac();

            var fileName = $"{Guid.NewGuid()}.dacpac";

            File.WriteAllBytes(fileName, result);

            Assert.IsNotNull(result);
            Assert.IsTrue(File.Exists(fileName));
        }
Exemplo n.º 3
0
        public ActionResult GenerateDacPac(DacPacModel model)
        {
            if (ModelState.IsValid)
            {
                var upgradeService = new DbUpgradeService(DbConnection.From(model.ConnectionString, model.DatabaseName));

                var dacpacFile = upgradeService.GenerateDacPac();

                var stream = new MemoryStream(dacpacFile);
                return(File(stream, "application/octet-stream", $"{model.DatabaseName}.dacpac"));
            }

            return(View());
        }