2014-03-14 17:11:21 +11:00
|
|
|
using System;
|
2016-02-19 13:33:11 +01:00
|
|
|
using System.Linq;
|
2015-01-09 12:04:33 +11:00
|
|
|
using Moq;
|
2014-03-14 17:11:21 +11:00
|
|
|
using NUnit.Framework;
|
2015-01-09 12:04:33 +11:00
|
|
|
using Umbraco.Core.Logging;
|
2014-03-14 17:11:21 +11:00
|
|
|
using Umbraco.Core.Models.Rdbms;
|
2016-02-19 13:33:11 +01:00
|
|
|
using Umbraco.Core.Persistence;
|
2014-03-14 17:11:21 +11:00
|
|
|
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
2016-02-19 13:33:11 +01:00
|
|
|
using Umbraco.Core.Persistence.Migrations;
|
2014-03-14 17:11:21 +11:00
|
|
|
using Umbraco.Core.Persistence.SqlSyntax;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Persistence.SyntaxProvider
|
|
|
|
|
{
|
2016-02-19 13:33:11 +01:00
|
|
|
//[NUnit.Framework.Ignore("This doesn't actually test anything")]
|
2014-03-14 17:11:21 +11:00
|
|
|
[TestFixture]
|
|
|
|
|
public class MySqlSyntaxProviderTests
|
|
|
|
|
{
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp()
|
|
|
|
|
{
|
2015-01-09 12:04:33 +11:00
|
|
|
SqlSyntaxContext.SqlSyntaxProvider = new MySqlSyntaxProvider(Mock.Of<ILogger>());
|
2014-03-14 17:11:21 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2016-02-19 13:33:11 +01:00
|
|
|
[NUnit.Framework.Ignore]
|
2014-03-14 17:11:21 +11:00
|
|
|
public void Can_Generate_Create_Table_Statement()
|
|
|
|
|
{
|
|
|
|
|
var type = typeof(TagRelationshipDto);
|
|
|
|
|
var definition = DefinitionFactory.GetTableDefinition(type);
|
|
|
|
|
|
|
|
|
|
string create = SqlSyntaxContext.SqlSyntaxProvider.Format(definition);
|
|
|
|
|
string primaryKey = SqlSyntaxContext.SqlSyntaxProvider.FormatPrimaryKey(definition);
|
|
|
|
|
var indexes = SqlSyntaxContext.SqlSyntaxProvider.Format(definition.Indexes);
|
|
|
|
|
var keys = SqlSyntaxContext.SqlSyntaxProvider.Format(definition.ForeignKeys);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(create);
|
|
|
|
|
Console.WriteLine(primaryKey);
|
|
|
|
|
foreach (var sql in keys)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var sql in indexes)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(sql);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
|
|
|
|
SqlSyntaxContext.SqlSyntaxProvider = null;
|
|
|
|
|
}
|
2016-02-19 13:33:11 +01:00
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void U4_8017()
|
|
|
|
|
{
|
|
|
|
|
var logger = Mock.Of<ILogger>();
|
|
|
|
|
var migration = new TestMigration(SqlSyntaxContext.SqlSyntaxProvider, logger);
|
|
|
|
|
var context = new MigrationContext(DatabaseProviders.MySql, null, logger);
|
|
|
|
|
migration.Context = context;
|
|
|
|
|
migration.Up();
|
|
|
|
|
var x = context.Expressions;
|
|
|
|
|
Assert.AreEqual(1, x.Count);
|
|
|
|
|
var e = x.First().ToString();
|
|
|
|
|
|
|
|
|
|
// SQLCE provider *does* use UniqueIdentifier
|
|
|
|
|
// MySql using GUID...? because InitColumnTypeMap() missing in provider, fixed
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("ALTER TABLE `cmsPropertyTypeGroup` ADD COLUMN `uniqueID` char(36) NOT NULL", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Migration("1.0.0", 0, "Test")]
|
|
|
|
|
private class TestMigration : MigrationBase
|
|
|
|
|
{
|
|
|
|
|
public TestMigration(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
public override void Up()
|
|
|
|
|
{
|
|
|
|
|
Create.Column("uniqueID").OnTable("cmsPropertyTypeGroup").AsGuid().NotNullable().WithDefault(SystemMethods.NewGuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Down()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-14 17:11:21 +11:00
|
|
|
}
|
|
|
|
|
}
|