Browse Source

Tests and logic fixed.

pull/203/merge
Sebastian Stehle 8 years ago
parent
commit
3d83860f96
  1. 11
      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

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

@ -31,13 +31,17 @@ 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;
}
var sources = new[] { source1, source2 };
foreach (var source in sources)
{
foreach (var otherValue in source)
{
var fieldValue = target.GetOrAdd(otherValue.Key, x => new ContentFieldData());
@ -47,6 +51,7 @@ namespace Squidex.Domain.Apps.Core.Contents
fieldValue[value.Key] = value.Value;
}
}
}
return target;
}

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)
{
return Merge(this, target);
return Merge(new IdContentData(), this, target);
}
public IdContentData ToCleaned()

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

@ -7,6 +7,7 @@
// ==========================================================================
using System;
using System.Collections.Generic;
using Squidex.Infrastructure;
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)
{
return Merge(this, target);
return Merge(new NamedContentData(), this, target);
}
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))
{
RaiseEvent(SimpleMapper.Map(command, new ContentUpdated { Data = newData }));
var @event = SimpleMapper.Map(command, new ContentUpdated());
@event.Data = newData;
RaiseEvent(@event);
}
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);
Assert.Equal(expected, actual);
Assert.NotSame(expected, rhs);
Assert.NotSame(expected, lhs);
}
[Fact]
@ -152,6 +154,8 @@ namespace Squidex.Domain.Apps.Core.Model.Contents
var actual = lhs.MergeInto(rhs);
Assert.Equal(expected, actual);
Assert.NotSame(expected, rhs);
Assert.NotSame(expected, lhs);
}
[Fact]

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

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

Loading…
Cancel
Save