Permalink
Browse files

Add support for execute arrays (for better formatting)

  • Loading branch information...
thomasvm committed Jul 22, 2011
1 parent 19fbcfe commit 658d486c9bbf3df3c22392e3bfe4ca19657b7fa1
Showing with 12,054 additions and 2 deletions.
  1. +39 −0 Manatee.Test/ExecuteTests.cs
  2. +11 −0 Manatee.Test/Manatee.Test.csproj
  3. +4 −0 Manatee.Test/packages.config
  4. +30 −2 Migrator.cs
  5. BIN packages/NUnit.2.5.10.11092/Logo.ico
  6. BIN packages/NUnit.2.5.10.11092/NUnit.2.5.10.11092.nupkg
  7. +277 −0 packages/NUnit.2.5.10.11092/NUnitFitTests.html
  8. +342 −0 packages/NUnit.2.5.10.11092/fit-license.txt
  9. BIN packages/NUnit.2.5.10.11092/lib/nunit.framework.dll
  10. +10,407 −0 packages/NUnit.2.5.10.11092/lib/nunit.framework.xml
  11. BIN packages/NUnit.2.5.10.11092/lib/nunit.mocks.dll
  12. BIN packages/NUnit.2.5.10.11092/lib/pnunit.framework.dll
  13. +15 −0 packages/NUnit.2.5.10.11092/license.txt
  14. +124 −0 packages/NUnit.2.5.10.11092/tools/NUnitTests.VisualState.xml
  15. +85 −0 packages/NUnit.2.5.10.11092/tools/NUnitTests.config
  16. +14 −0 packages/NUnit.2.5.10.11092/tools/NUnitTests.nunit
  17. +4 −0 packages/NUnit.2.5.10.11092/tools/agent.conf
  18. +18 −0 packages/NUnit.2.5.10.11092/tools/agent.log.conf
  19. +18 −0 packages/NUnit.2.5.10.11092/tools/launcher.log.conf
  20. BIN packages/NUnit.2.5.10.11092/tools/lib/Failure.png
  21. BIN packages/NUnit.2.5.10.11092/tools/lib/Ignored.png
  22. BIN packages/NUnit.2.5.10.11092/tools/lib/Inconclusive.png
  23. BIN packages/NUnit.2.5.10.11092/tools/lib/Skipped.png
  24. BIN packages/NUnit.2.5.10.11092/tools/lib/Success.png
  25. BIN packages/NUnit.2.5.10.11092/tools/lib/fit.dll
  26. BIN packages/NUnit.2.5.10.11092/tools/lib/log4net.dll
  27. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit-console-runner.dll
  28. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit-gui-runner.dll
  29. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit.core.dll
  30. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit.core.interfaces.dll
  31. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit.fixtures.dll
  32. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit.uiexception.dll
  33. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit.uikit.dll
  34. BIN packages/NUnit.2.5.10.11092/tools/lib/nunit.util.dll
  35. BIN packages/NUnit.2.5.10.11092/tools/nunit-agent-x86.exe
  36. +69 −0 packages/NUnit.2.5.10.11092/tools/nunit-agent-x86.exe.config
  37. BIN packages/NUnit.2.5.10.11092/tools/nunit-agent.exe
  38. +69 −0 packages/NUnit.2.5.10.11092/tools/nunit-agent.exe.config
  39. BIN packages/NUnit.2.5.10.11092/tools/nunit-console-x86.exe
  40. +69 −0 packages/NUnit.2.5.10.11092/tools/nunit-console-x86.exe.config
  41. BIN packages/NUnit.2.5.10.11092/tools/nunit-console.exe
  42. +69 −0 packages/NUnit.2.5.10.11092/tools/nunit-console.exe.config
  43. BIN packages/NUnit.2.5.10.11092/tools/nunit-x86.exe
  44. +83 −0 packages/NUnit.2.5.10.11092/tools/nunit-x86.exe.config
  45. BIN packages/NUnit.2.5.10.11092/tools/nunit.exe
  46. +83 −0 packages/NUnit.2.5.10.11092/tools/nunit.exe.config
  47. BIN packages/NUnit.2.5.10.11092/tools/nunit.framework.dll
  48. BIN packages/NUnit.2.5.10.11092/tools/pnunit-agent.exe
  49. +77 −0 packages/NUnit.2.5.10.11092/tools/pnunit-agent.exe.config
  50. BIN packages/NUnit.2.5.10.11092/tools/pnunit-launcher.exe
  51. +77 −0 packages/NUnit.2.5.10.11092/tools/pnunit-launcher.exe.config
  52. BIN packages/NUnit.2.5.10.11092/tools/pnunit.framework.dll
  53. BIN packages/NUnit.2.5.10.11092/tools/pnunit.tests.dll
  54. BIN packages/NUnit.2.5.10.11092/tools/runFile.exe
  55. +43 −0 packages/NUnit.2.5.10.11092/tools/runFile.exe.config
  56. +2 −0 packages/NUnit.2.5.10.11092/tools/runpnunit.bat
  57. +24 −0 packages/NUnit.2.5.10.11092/tools/test.conf
  58. +1 −0 packages/repositories.config
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace Manatee.Test
+{
+ [TestFixture]
+ public class ExecuteTests
+ {
+ [Test]
+ public void Execute_WithArray_ConcatenesValues()
+ {
+ var migrator = new Migrator();
+
+ string json = @"{execute: [
+ 'SELECT current_timestamp, ',
+ 'system_user'
+ ]}";
+
+ string command = migrator.GetCommandFromJson(json);
+
+ Assert.AreEqual(string.Format(@"SELECT current_timestamp, {0}system_user{0}", Environment.NewLine), command);
+ }
+
+ [Test]
+ public void Execute_WithSingleValue_TakesValue()
+ {
+ var migrator = new Migrator();
+
+ string json = @"{execute: 'SELECT current_timestamp' }";
+
+ string command = migrator.GetCommandFromJson(json);
+
+ Assert.AreEqual("SELECT current_timestamp", command);
+ }
+ }
+}
@@ -35,6 +35,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="nunit.framework">
+ <HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="nunit.mocks">
+ <HintPath>..\packages\NUnit.2.5.10.11092\lib\nunit.mocks.dll</HintPath>
+ </Reference>
+ <Reference Include="pnunit.framework">
+ <HintPath>..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -44,6 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="ExecuteTests.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -76,6 +86,7 @@
<Content Include="DB\005 - Create Category.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NUnit" version="2.5.10.11092" />
+</packages>
View
@@ -7,6 +7,7 @@
using System.Dynamic;
using System.IO;
using System.Linq;
+using System.Text;
using System.Web.Script.Serialization;
using Manatee.Command;
@@ -162,6 +163,13 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
private Database _db;
private string _migrationsFolder;
+ /// <summary>
+ /// For testing purposes only
+ /// </summary>
+ public Migrator()
+ {
+ }
+
public Migrator(string pathToMigrationFiles, string connectionStringName = "")
{
_db = new Database(connectionStringName);
@@ -356,11 +364,20 @@ private IEnumerable<string> GetCommands(dynamic op)
yield return GetCommand(op);
}
+ /// <summary>
+ /// For testing only
+ /// </summary>
+ public string GetCommandFromJson(string json)
+ {
+ dynamic decoded = Json.Decode(json);
+ return GetCommand(decoded);
+ }
+
/// <summary>
/// This is the main "builder" of the DDL SQL and it's tuned for SQL CE.
/// The idea is that you build your app using SQL CE, then upgrade it to SQL Server when you need to
/// </summary>
- private string GetCommand(dynamic op)
+ public string GetCommand(dynamic op)
{
//the "op" here is an "up" or a "down". It's dynamic as that's what the JSON parser
//will return. The neat thing about this parser is that the dynamic result will
@@ -466,7 +483,18 @@ private string GetCommand(dynamic op)
}
else if (op.execute != null)
{
- result = op.execute;
+ if (op.execute is List<object>)
+ {
+ var builder = new StringBuilder();
+ foreach (var item in (List<object>)op.execute)
+ builder.AppendLine(item.ToString());
+
+ result = builder.ToString();
+ }
+ else
+ {
+ result = op.execute;
+ }
}
else if (op.execute_file != null)
{
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 658d486

Please sign in to comment.