Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenDBDiff.Schema.SQLServer.Generates.Generates.Util;
|
||||
|
||||
namespace OpenDBDiff.Schema.SQLServer.Generates.Generates.Utils.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ByteToHexEncoderTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void EncodesBytesIntoHex()
|
||||
{
|
||||
byte[] bytes = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
|
||||
|
||||
var hex = ByteToHexEncoder.ByteArrayToHex(bytes);
|
||||
|
||||
Assert.AreEqual("0x000102040810204080FF", hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
237
OpenDBDiff.Schema.SQLServer.GeneratesTests/Model/ColumnsTests.cs
Normal file
237
OpenDBDiff.Schema.SQLServer.GeneratesTests/Model/ColumnsTests.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenDBDiff.Schema.SQLServer.Generates.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenDBDiff.Schema.Model;
|
||||
using OpenDBDiff.Schema.SQLServer.Generates.Compare;
|
||||
|
||||
namespace OpenDBDiff.Schema.SQLServer.Generates.Model.Tests
|
||||
{
|
||||
[TestClass()]
|
||||
public class ColumnsTests
|
||||
{
|
||||
[TestMethod()]
|
||||
public void OriginHasExtraColumn_NothingSelected_ShouldDropExtraColumn()
|
||||
{
|
||||
int idStorage = 1;
|
||||
System.Func<int> getId = new Func<int>(()=>++idStorage);
|
||||
|
||||
Database originDatabase = new Database();
|
||||
originDatabase.Info = new DatabaseInfo()
|
||||
{
|
||||
Collation = "SQL_Latin1_General_CP1_CI_AS",
|
||||
};
|
||||
originDatabase.Options = new Options.SqlOption();
|
||||
originDatabase.Id = getId();
|
||||
Table originTable = new Table(originDatabase);
|
||||
originTable.Name = "Example";
|
||||
originTable.Id = getId();
|
||||
var originColumn1 = new Column(originTable)
|
||||
{
|
||||
Name = "Test",
|
||||
Type = "int",
|
||||
Id = getId()
|
||||
};
|
||||
var originColumn2 = new Column(originTable)
|
||||
{
|
||||
Name = "Test2",
|
||||
Type = "varchar(20)",
|
||||
Id = getId()
|
||||
};
|
||||
var originColumn3 = new Column(originTable)
|
||||
{
|
||||
Name = "Test3",
|
||||
Type = "bigint",
|
||||
Id = getId()
|
||||
};
|
||||
originTable.Columns.Add(originColumn1);
|
||||
originTable.Columns.Add(originColumn3);
|
||||
originTable.Columns.Add(originColumn2);
|
||||
originDatabase.Tables.Add(originTable);
|
||||
|
||||
|
||||
Database destinationDatabase = new Database();
|
||||
destinationDatabase.Info = new DatabaseInfo()
|
||||
{
|
||||
Collation = "SQL_Latin1_General_CP1_CI_AS"
|
||||
};
|
||||
destinationDatabase.Id = getId();
|
||||
destinationDatabase.Options = new Options.SqlOption();
|
||||
Table destinationTable = new Table(destinationDatabase);
|
||||
destinationTable.Name = "Example";
|
||||
destinationTable.Id = getId();
|
||||
var destinationColumn1 = new Column(destinationTable)
|
||||
{
|
||||
Name = "Test",
|
||||
Type = "int",
|
||||
Id = getId()
|
||||
};
|
||||
var destinationColumn3 = new Column(destinationTable)
|
||||
{
|
||||
Name = "Test3",
|
||||
Type = "bigint",
|
||||
Id = getId()
|
||||
};
|
||||
destinationTable.Columns.Add(destinationColumn1);
|
||||
destinationTable.Columns.Add(destinationColumn3);
|
||||
destinationDatabase.Tables.Add(destinationTable);
|
||||
|
||||
|
||||
originTable.OriginalTable = (Table)originTable.Clone((Database)originTable.Parent);
|
||||
new CompareColumns().GenerateDifferences<Table>(originTable.Columns, destinationTable.Columns);
|
||||
|
||||
SQLScriptList sqlList = originTable.ToSqlDiff(new List<ISchemaBase>());
|
||||
string sql = sqlList.ToSQL();
|
||||
Assert.AreEqual(originColumn2.ToSqlDrop(), sql);
|
||||
}
|
||||
[TestMethod()]
|
||||
public void OriginHasExtraColumn_NotChangedColumnSelected_ShouldBeEmptyScript()
|
||||
{
|
||||
int idStorage = 1;
|
||||
System.Func<int> getId = new Func<int>(() => ++idStorage);
|
||||
Database originDatabase = new Database();
|
||||
originDatabase.Info = new DatabaseInfo()
|
||||
{
|
||||
Collation = "SQL_Latin1_General_CP1_CI_AS"
|
||||
};
|
||||
originDatabase.Id = getId();
|
||||
originDatabase.Options = new Options.SqlOption();
|
||||
Table originTable = new Table(originDatabase);
|
||||
originTable.Name = "Example";
|
||||
originTable.Id = getId();
|
||||
var originColumn1 = new Column(originTable)
|
||||
{
|
||||
Name = "Test",
|
||||
Type = "int",
|
||||
Id = getId()
|
||||
};
|
||||
var originColumn2 = new Column(originTable)
|
||||
{
|
||||
Name = "Test2",
|
||||
Type = "varchar(20)",
|
||||
Id = getId()
|
||||
};
|
||||
var originColumn3 = new Column(originTable)
|
||||
{
|
||||
Name = "Test3",
|
||||
Type = "bigint",
|
||||
Id = getId()
|
||||
};
|
||||
originTable.Columns.Add(originColumn1);
|
||||
originTable.Columns.Add(originColumn3);
|
||||
originTable.Columns.Add(originColumn2);
|
||||
originDatabase.Tables.Add(originTable);
|
||||
|
||||
|
||||
Database destinationDatabase = new Database();
|
||||
destinationDatabase.Info = new DatabaseInfo()
|
||||
{
|
||||
Collation = "SQL_Latin1_General_CP1_CI_AS"
|
||||
};
|
||||
destinationDatabase.Id = getId();
|
||||
destinationDatabase.Options = new Options.SqlOption();
|
||||
Table destinationTable = new Table(destinationDatabase);
|
||||
destinationTable.Name = "Example";
|
||||
destinationTable.Id = getId();
|
||||
var destinationColumn1 = new Column(destinationTable)
|
||||
{
|
||||
Name = "Test",
|
||||
Type = "int",
|
||||
Id = getId()
|
||||
};
|
||||
var destinationColumn3 = new Column(destinationTable)
|
||||
{
|
||||
Name = "Test3",
|
||||
Type = "bigint",
|
||||
Id = getId()
|
||||
};
|
||||
destinationTable.Columns.Add(destinationColumn1);
|
||||
destinationTable.Columns.Add(destinationColumn3);
|
||||
destinationDatabase.Tables.Add(destinationTable);
|
||||
|
||||
|
||||
originTable.OriginalTable = (Table)originTable.Clone((Database)originTable.Parent);
|
||||
new CompareColumns().GenerateDifferences<Table>(originTable.Columns, destinationTable.Columns);
|
||||
|
||||
SQLScriptList sqlList = originTable.ToSqlDiff(new List<ISchemaBase>() { originColumn3 });
|
||||
string sql = sqlList.ToSQL();
|
||||
Assert.AreEqual("", sql);
|
||||
}
|
||||
[TestMethod()]
|
||||
public void OriginHasExtraColumn_ExtraColumnSelected_ShouldBeDropColumnScript()
|
||||
{
|
||||
int idStorage = 1;
|
||||
System.Func<int> getId = new Func<int>(() => ++idStorage);
|
||||
Database originDatabase = new Database();
|
||||
originDatabase.Info = new DatabaseInfo()
|
||||
{
|
||||
Collation = "SQL_Latin1_General_CP1_CI_AS"
|
||||
};
|
||||
originDatabase.Id = getId();
|
||||
originDatabase.Options = new Options.SqlOption();
|
||||
Table originTable = new Table(originDatabase);
|
||||
originTable.Name = "Example";
|
||||
originTable.Id = getId();
|
||||
var originColumn1 = new Column(originTable)
|
||||
{
|
||||
Name = "Test",
|
||||
Type = "int",
|
||||
Id = getId()
|
||||
};
|
||||
var originColumn2 = new Column(originTable)
|
||||
{
|
||||
Name = "Test2",
|
||||
Type = "varchar(20)",
|
||||
Id = getId()
|
||||
};
|
||||
var originColumn3 = new Column(originTable)
|
||||
{
|
||||
Name = "Test3",
|
||||
Type = "bigint",
|
||||
Id = getId()
|
||||
};
|
||||
originTable.Columns.Add(originColumn1);
|
||||
originTable.Columns.Add(originColumn3);
|
||||
originTable.Columns.Add(originColumn2);
|
||||
originDatabase.Tables.Add(originTable);
|
||||
|
||||
|
||||
Database destinationDatabase = new Database();
|
||||
destinationDatabase.Info = new DatabaseInfo()
|
||||
{
|
||||
Collation = "SQL_Latin1_General_CP1_CI_AS"
|
||||
};
|
||||
destinationDatabase.Id = getId();
|
||||
destinationDatabase.Options = new Options.SqlOption();
|
||||
Table destinationTable = new Table(destinationDatabase);
|
||||
destinationTable.Name = "Example";
|
||||
destinationTable.Id = getId();
|
||||
var destinationColumn1 = new Column(destinationTable)
|
||||
{
|
||||
Name = "Test",
|
||||
Type = "int",
|
||||
Id = getId()
|
||||
};
|
||||
var destinationColumn3 = new Column(destinationTable)
|
||||
{
|
||||
Name = "Test3",
|
||||
Type = "bigint",
|
||||
Id = getId()
|
||||
};
|
||||
destinationTable.Columns.Add(destinationColumn1);
|
||||
destinationTable.Columns.Add(destinationColumn3);
|
||||
destinationDatabase.Tables.Add(destinationTable);
|
||||
|
||||
|
||||
originTable.OriginalTable = (Table)originTable.Clone((Database)originTable.Parent);
|
||||
new CompareColumns().GenerateDifferences<Table>(originTable.Columns, destinationTable.Columns);
|
||||
|
||||
SQLScriptList sqlList = originTable.ToSqlDiff(new List<ISchemaBase>() { originColumn2 });
|
||||
string sql = sqlList.ToSQL();
|
||||
Assert.AreEqual(originColumn2.ToSqlDrop(), sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{94F5C91A-6268-41E9-A15E-FA5451BB2B6F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OpenDBDiff.Schema.SQLServer.GeneratesTests</RootNamespace>
|
||||
<AssemblyName>OpenDBDiff.Schema.SQLServer.GeneratesTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\OpenDBDiff\Properties\AssemblyVersionInfo.cs">
|
||||
<Link>Properties\AssemblyVersionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Generates\Util\ByteToHexEncoderTests.cs" />
|
||||
<Compile Include="Model\ColumnsTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenDBDiff.Schema.SQLServer.Generates\OpenDBDiff.Schema.SQLServer.Generates.csproj">
|
||||
<Project>{32AC9AF6-DB93-4354-B69F-6DBC65C70867}</Project>
|
||||
<Name>DBDiff.Schema.SQLServer.Generates</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\OpenDBDiff.Schema\OpenDBDiff.Schema.csproj">
|
||||
<Project>{406558A0-1B98-4D0E-B8B6-2013700B065A}</Project>
|
||||
<Name>DBDiff.Schema</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig">
|
||||
<Link>.editorconfig</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("OpenDBDiff.Schema.SQLServer.GeneratesTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("OpenDBDiff.Schema.SQLServer.GeneratesTests")]
|
||||
[assembly: AssemblyCopyright("OpenDBDiff")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("94f5c91a-6268-41e9-a15e-fa5451bb2b6f")]
|
||||
Reference in New Issue
Block a user