Browse Source

Tests and logic fixed.

pull/203/merge
Sebastian Stehle 8 years ago
parent
commit
3d83860f96
  1. 21
      src/Squidex.Domain.Apps.Core.Model/Contents/ContentData.cs
  2. 2
      src/Squidex.Domain.Apps.Core.Model/Contents/IdContentData.cs
  3. 8
      src/Squidex.Domain.Apps.Core.Model/Contents/NamedContentData.cs
  4. 6
      src/Squidex.Domain.Apps.Write/Contents/ContentDomainObject.cs
  5. 4
      tests/Squidex.Domain.Apps.Core.Tests/Model/Contents/ContentDataTests.cs
  6. 7
      tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentDomainObjectTests.cs

21
src/Squidex.Domain.Apps.Core.Model/Contents/ContentData.cs

@ -31,20 +31,25 @@ namespace Squidex.Domain.Apps.Core.Contents
{ {
} }
protected static TResult Merge<TResult>(TResult source, TResult target) where TResult : ContentData<T> protected static TResult Merge<TResult>(TResult target, TResult source1, TResult source2) where TResult : ContentData<T>
{ {
if (ReferenceEquals(target, source)) if (ReferenceEquals(source1, source2))
{ {
return source; return source1;
} }
foreach (var otherValue in source) var sources = new[] { source1, source2 };
{
var fieldValue = target.GetOrAdd(otherValue.Key, x => new ContentFieldData());
foreach (var value in otherValue.Value) foreach (var source in sources)
{
foreach (var otherValue in source)
{ {
fieldValue[value.Key] = value.Value; var fieldValue = target.GetOrAdd(otherValue.Key, x => new ContentFieldData());
foreach (var value in otherValue.Value)
{
fieldValue[value.Key] = value.Value;
}
} }
} }

2
src/Squidex.Domain.Apps.Core.Model/Contents/IdContentData.cs

@ -26,7 +26,7 @@ namespace Squidex.Domain.Apps.Core.Contents
public IdContentData MergeInto(IdContentData target) public IdContentData MergeInto(IdContentData target)
{ {
return Merge(this, target); return Merge(new IdContentData(), this, target);
} }
public IdContentData ToCleaned() public IdContentData ToCleaned()

8
src/Squidex.Domain.Apps.Core.Model/Contents/NamedContentData.cs

@ -7,6 +7,7 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using Squidex.Infrastructure; using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Core.Contents namespace Squidex.Domain.Apps.Core.Contents
@ -18,9 +19,14 @@ namespace Squidex.Domain.Apps.Core.Contents
{ {
} }
public NamedContentData(NamedContentData copy)
: base(copy, EqualityComparer<string>.Default)
{
}
public NamedContentData MergeInto(NamedContentData target) public NamedContentData MergeInto(NamedContentData target)
{ {
return Merge(this, target); return Merge(new NamedContentData(), this, target);
} }
public NamedContentData ToCleaned() public NamedContentData ToCleaned()

6
src/Squidex.Domain.Apps.Write/Contents/ContentDomainObject.cs

@ -119,7 +119,11 @@ namespace Squidex.Domain.Apps.Write.Contents
if (!newData.Equals(Data)) if (!newData.Equals(Data))
{ {
RaiseEvent(SimpleMapper.Map(command, new ContentUpdated { Data = newData })); var @event = SimpleMapper.Map(command, new ContentUpdated());
@event.Data = newData;
RaiseEvent(@event);
} }
return this; return this;

4
tests/Squidex.Domain.Apps.Core.Tests/Model/Contents/ContentDataTests.cs

@ -113,6 +113,8 @@ namespace Squidex.Domain.Apps.Core.Model.Contents
var actual = lhs.MergeInto(rhs); var actual = lhs.MergeInto(rhs);
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
Assert.NotSame(expected, rhs);
Assert.NotSame(expected, lhs);
} }
[Fact] [Fact]
@ -152,6 +154,8 @@ namespace Squidex.Domain.Apps.Core.Model.Contents
var actual = lhs.MergeInto(rhs); var actual = lhs.MergeInto(rhs);
Assert.Equal(expected, actual); Assert.Equal(expected, actual);
Assert.NotSame(expected, rhs);
Assert.NotSame(expected, lhs);
} }
[Fact] [Fact]

7
tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentDomainObjectTests.cs

@ -32,10 +32,14 @@ namespace Squidex.Domain.Apps.Write.Contents
new ContentFieldData() new ContentFieldData()
.AddValue("iv", 2)); .AddValue("iv", 2));
private readonly NamedContentData patched;
public Guid ContentId { get; } = Guid.NewGuid(); public Guid ContentId { get; } = Guid.NewGuid();
public ContentDomainObjectTests() public ContentDomainObjectTests()
{ {
patched = otherData.MergeInto(data);
sut = new ContentDomainObject(ContentId, 0); sut = new ContentDomainObject(ContentId, 0);
} }
@ -143,12 +147,13 @@ namespace Squidex.Domain.Apps.Write.Contents
public void Patch_should_create_events() public void Patch_should_create_events()
{ {
CreateContent(); CreateContent();
UpdateContent();
sut.Patch(CreateContentCommand(new PatchContent { Data = otherData })); sut.Patch(CreateContentCommand(new PatchContent { Data = otherData }));
sut.GetUncomittedEvents() sut.GetUncomittedEvents()
.ShouldHaveSameEvents( .ShouldHaveSameEvents(
CreateContentEvent(new ContentUpdated { Data = otherData }) CreateContentEvent(new ContentUpdated { Data = patched })
); );
} }

Loading…
Cancel
Save