Skip to content

Commit

Permalink
Merge pull request #9 from luuksommers/feature/ValidateCompleteTransform
Browse files Browse the repository at this point in the history
Feature/validate complete transform
  • Loading branch information
luuksommers authored Mar 8, 2018
2 parents e1d37e5 + 8f8cfe1 commit d6a21f1
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/YmlTransform/Exceptions/IncompleteTransformationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YmlTransform.Exceptions
{
public class IncompleteTransformationException : Exception
{
public IncompleteTransformationException()
{ }

public IncompleteTransformationException(string message) : base(message)
{ }
}
}
17 changes: 16 additions & 1 deletion src/YmlTransform/Models/TransformItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@ namespace YmlTransform.Models
{
class TransformItem
{
private string _value;
private bool _used;

public string Path { get; set; }
public string Type { get; set; }
public string Languages { get; set; }
public Guid FieldId { get; set; }
public string Value { get; set; }

public string Value
{
get
{
_used = true;
return _value;
}
set { _value = value; }
}

public string Hint { get; set; }

public bool Used => _used;
}
}
1 change: 1 addition & 0 deletions src/YmlTransform/YmlTransform.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Exceptions\IncompleteTransformationException.cs" />
<Compile Include="ReflectionHelper.cs" />
<Compile Include="Models\Options.cs" />
<Compile Include="Program.cs" />
Expand Down
5 changes: 5 additions & 0 deletions src/YmlTransform/YmlTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Rainbow.Model;
using Rainbow.Storage.Yaml;
using Rainbow.Storage.Yaml.OutputModel;
using YmlTransform.Exceptions;
using YmlTransform.Models;

namespace YmlTransform
Expand Down Expand Up @@ -93,6 +94,10 @@ private static void TransformSingle(List<TransformItem> transformations, string
}
}

if (!transformations.All(x => x.Used))
{
throw new IncompleteTransformationException();
}

if (transformed)
{
Expand Down
25 changes: 25 additions & 0 deletions tests/YmlTransform.Tests/Data/MissingTransformation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
ID: "ab5b233c-111c-4fa8-affe-b0c7315fedf4"
Parent: "756fff26-90f2-4889-bace-da656e66b9c1"
Template: "013bc834-c0f6-4377-924e-0de185abfbe7"
Path: /sitecore/content/Home/Unversioned
DB: master
SharedFields:
- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e"
Hint: __Sortorder
Value: 375
Languages:
- Language: en
Fields:
- ID: "11c0c7c6-673f-432a-b2fa-acfead30b6dd"
Hint: Field1
Value: "Value1"
- ID: "814e27bf-7ae2-433c-affa-aafc0797e0a8"
Hint: Field2
Value: "Value2"
Versions:
- Version: 1
Fields:
- ID: "25bed78c-4957-4165-998a-ca1b52f67497"
Hint: __Created
Value: 20171016T073039Z
18 changes: 18 additions & 0 deletions tests/YmlTransform.Tests/Data/MissingTransformation.ymltransform
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"FieldId": "11c0c7c6-673f-432a-b2fa-acfead30b6dd",
"Hint": "Field1",
"Languages": "*",
"Path": "/sitecore/content/Home/Unversioned",
"Type": "Unversioned",
"Value": "Value1New"
},
{
"FieldId": "714e27bf-7ae2-433c-affa-aafc0797e0a8",
"Hint": "Field3",
"Languages": "*",
"Path": "/sitecore/content/Home/Unversioned",
"Type": "Unversioned",
"Value": "Value2New"
}
]
9 changes: 9 additions & 0 deletions tests/YmlTransform.Tests/YmlTransform.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Linq, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Reflection, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -80,6 +83,12 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Data\MissingTransformation.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Data\MissingTransformation.ymltransform">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Data\Unversioned.yml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
9 changes: 9 additions & 0 deletions tests/YmlTransform.Tests/YmlTransformerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading;
using Xunit;
using YmlTransform.Exceptions;

namespace YmlTransform.Tests
{
Expand Down Expand Up @@ -38,5 +39,13 @@ public void TestUnversionedTransformation()

Assert.Equal(expectedHash, originalHash);
}

[Fact]
public void TestExceptionThrownOnIncompleteTransform()
{
const string originalFile = @"Data\\MissingTransformation.yml";

Assert.Throws<IncompleteTransformationException>(() => YmlTransformer.TransformFile(originalFile, "Data\\MissingTransformation.ymltransform"));
}
}
}
1 change: 1 addition & 0 deletions tests/YmlTransform.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.Linq" version="4.3.0" targetFramework="net47" />
<package id="System.Reflection" version="4.3.0" targetFramework="net47" />
<package id="System.Runtime" version="4.3.0" targetFramework="net47" />
<package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net47" />
Expand Down

0 comments on commit d6a21f1

Please sign in to comment.