Skip to content

Commit

Permalink
Merge pull request #181 from jermdavis/master
Browse files Browse the repository at this point in the history
Adding a meaningful error message if FakeDb.Serialization encounters a duplicated Item ID
  • Loading branch information
sshushliapin authored Jun 16, 2017
2 parents 187b944 + f921274 commit 22da2e8
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Sitecore.FakeDb.Serialization/DuplicateIdException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Sitecore.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sitecore.FakeDb.Serialization
{

/// <summary>
/// Exception thrown if the deserialization logic encounters a duplicated content item ID.
/// Ensures that the user gets a meaningful error message to help them debug their serialized content.
/// </summary>
public class DuplicateIdException : ArgumentException
{
public DuplicateIdException(ID id, string firstFile, string secondFile)
: base(string.Format(
"FakeDb.Serialization is unable to process this content tree.\n\nThe item id {0} defined by item file being processed \"{1}\" has already been used by the item in \"{2}\"",
id, firstFile, secondFile))
{
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var shortenedItemsFolder in ShortenedPathsDictionary.GetLocationsFromLinkFiles(s
}

var itemId = ID.Parse(itemIdStr);
if (pathSet.Paths.ContainsKey(itemId))
{
throw new DuplicateIdException(itemId, file, pathSet.Paths[itemId]);
}
pathSet.Paths.Add(itemId, file);
if (itemId == id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Deserializer.cs" />
<Compile Include="DsDbItem.cs" />
<Compile Include="DsDbTemplate.cs" />
<Compile Include="DuplicateIdException.cs" />
<Compile Include="Pipelines\CopyParentId.cs" />
<Compile Include="Pipelines\CopySharedFields.cs" />
<Compile Include="Pipelines\CopyVersionedFields.cs" />
Expand Down
1 change: 1 addition & 0 deletions test/Sitecore.FakeDb.Serialization.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<folder name="core" value="..\..\Data\CoreSerialization\core\" />
<folder name="master" value="..\..\Data\Serialization\master\" />
<folder name="custom" value="..\..\Data\CustomSerialization\master\" />
<folder name="incorrect" value="..\..\Data\IncorrectSerialization\master\" />
</szfolders>
<pipelines>
<loadDsDbItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
----item----
version: 1
id: {108266C2-304B-4AD3-9813-2BE1B88609FF}
database: master
path: /sitecore/content/Item only available in custom serialization folder
parent: {0DE95AE4-41AB-4D01-9EB0-67441B7C2450}
name: Item only available in custom serialization folder
master: {00000000-0000-0000-0000-000000000000}
template: {A87A00B1-E6DB-45AB-8B54-636FEC3B5523}
templatekey: Folder

----version----
language: en
version: 1
revision: 9a93e109-ce03-4f04-95bb-15d6dd3041f3

----field----
field: {25BED78C-4957-4165-998A-CA1B52F67497}
name: __Created
key: __created
content-length: 16

20140928T183147Z
----field----
field: {5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}
name: __Created by
key: __created by
content-length: 14

sitecore\admin
----field----
field: {8CDC337E-A112-42FB-BBB4-4143751E123F}
name: __Revision
key: __revision
content-length: 36

9a93e109-ce03-4f04-95bb-15d6dd3041f3
----field----
field: {D9CF14B1-FA16-4BA6-9288-E8A174D4D522}
name: __Updated
key: __updated
content-length: 35

20140928T183147:635475259073629721Z
----field----
field: {BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}
name: __Updated by
key: __updated by
content-length: 14

sitecore\admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
----item----
version: 1
id: {108266C2-304B-4AD3-9813-2BE1B88609FF}
database: master
path: /sitecore/content/Item only available in custom serialization folder
parent: {0DE95AE4-41AB-4D01-9EB0-67441B7C2450}
name: Item only available in custom serialization folder
master: {00000000-0000-0000-0000-000000000000}
template: {A87A00B1-E6DB-45AB-8B54-636FEC3B5523}
templatekey: Folder

----version----
language: en
version: 1
revision: 9a93e109-ce03-4f04-95bb-15d6dd3041f3

----field----
field: {25BED78C-4957-4165-998A-CA1B52F67497}
name: __Created
key: __created
content-length: 16

20140928T183147Z
----field----
field: {5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}
name: __Created by
key: __created by
content-length: 14

sitecore\admin
----field----
field: {8CDC337E-A112-42FB-BBB4-4143751E123F}
name: __Revision
key: __revision
content-length: 36

9a93e109-ce03-4f04-95bb-15d6dd3041f3
----field----
field: {D9CF14B1-FA16-4BA6-9288-E8A174D4D522}
name: __Updated
key: __updated
content-length: 35

20140928T183147:635475259073629721Z
----field----
field: {BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}
name: __Updated by
key: __updated by
content-length: 14

sitecore\admin
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@ public void ShouldFindPathForId()
File.Exists(filePath).Should().BeTrue();
Path.GetFileNameWithoutExtension(filePath).ShouldBeEquivalentTo("Item only available in custom serialization folder");
}

[Fact]
public void DuplicatedID_Throws_MeaningfulException()
{
Assert.Throws<DuplicateIdException>(() => {
ID.Parse("{108266C2-304B-4AD3-9813-2BE1B88609FF}").FindFilePath("incorrect");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<ItemGroup>
<Folder Include="Data\CoreSerialization\" />
<Folder Include="Data\CustomSerialization\" />
<Folder Include="Data\IncorrectSerialization\" />
<Folder Include="Data\LargeSetSerialization\" />
<Folder Include="Data\Serialization\" />
</ItemGroup>
Expand Down

0 comments on commit 22da2e8

Please sign in to comment.