|
|
@ -6,47 +6,52 @@ |
|
|
// All rights reserved.
|
|
|
// All rights reserved.
|
|
|
// ==========================================================================
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using FluentAssertions; |
|
|
|
|
|
using Squidex.Core.Schemas; |
|
|
using Squidex.Core.Schemas; |
|
|
using Squidex.Events.Schemas; |
|
|
using Squidex.Events.Schemas; |
|
|
using Squidex.Infrastructure; |
|
|
using Squidex.Infrastructure; |
|
|
using Squidex.Infrastructure.CQRS; |
|
|
using Squidex.Infrastructure.CQRS; |
|
|
using Squidex.Infrastructure.CQRS.Events; |
|
|
|
|
|
using Squidex.Write.Schemas.Commands; |
|
|
using Squidex.Write.Schemas.Commands; |
|
|
|
|
|
using Squidex.Write.TestHelpers; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
// ReSharper disable ConvertToConstant.Local
|
|
|
// ReSharper disable ConvertToConstant.Local
|
|
|
|
|
|
|
|
|
namespace Squidex.Write.Schemas |
|
|
namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
public class SchemaDomainObjectTests |
|
|
public class SchemaDomainObjectTests : HandlerTestBase<SchemaDomainObject> |
|
|
{ |
|
|
{ |
|
|
private readonly Guid appId = Guid.NewGuid(); |
|
|
|
|
|
private readonly string fieldName = "age"; |
|
|
private readonly string fieldName = "age"; |
|
|
private readonly string appName = "schema"; |
|
|
private readonly NamedId<long> fieldId; |
|
|
private readonly SchemaDomainObject sut; |
|
|
private readonly SchemaDomainObject sut; |
|
|
|
|
|
|
|
|
public SchemaDomainObjectTests() |
|
|
public SchemaDomainObjectTests() |
|
|
{ |
|
|
{ |
|
|
|
|
|
fieldId = new NamedId<long>(1, fieldName); |
|
|
|
|
|
|
|
|
var fieldRegistry = new FieldRegistry(new TypeNameRegistry()); |
|
|
var fieldRegistry = new FieldRegistry(new TypeNameRegistry()); |
|
|
|
|
|
|
|
|
sut = new SchemaDomainObject(Guid.NewGuid(), 0, fieldRegistry); |
|
|
sut = new SchemaDomainObject(SchemaId, 0, fieldRegistry); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Create_should_throw_if_created() |
|
|
public void Create_should_throw_if_created() |
|
|
{ |
|
|
{ |
|
|
sut.Create(new CreateSchema { Name = appName }); |
|
|
sut.Create(new CreateSchema { Name = SchemaName }); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.Create(new CreateSchema { Name = appName })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Create(CreateCommand(new CreateSchema { Name = SchemaName })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Create_should_throw_if_command_is_not_valid() |
|
|
public void Create_should_throw_if_command_is_not_valid() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<ValidationException>(() => sut.Create(new CreateSchema())); |
|
|
Assert.Throws<ValidationException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Create(CreateCommand(new CreateSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -54,22 +59,22 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
var properties = new SchemaProperties(); |
|
|
var properties = new SchemaProperties(); |
|
|
|
|
|
|
|
|
sut.Create(new CreateSchema { Name = appName, AppId = appId, Properties = properties }); |
|
|
sut.Create(CreateCommand(new CreateSchema { Name = SchemaName, Properties = properties })); |
|
|
|
|
|
|
|
|
Assert.Equal("schema", sut.Schema.Name); |
|
|
|
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
Assert.Equal(SchemaName, sut.Schema.Name); |
|
|
.ShouldBeEquivalentTo( |
|
|
|
|
|
new IEvent[] |
|
|
|
|
|
{ |
|
|
|
|
|
new SchemaCreated { Name = appName, Properties = properties } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents() |
|
|
|
|
|
.ShouldHaveSameEvents( |
|
|
|
|
|
CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties }) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Update_should_throw_if_not_created() |
|
|
public void Update_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.Update(new UpdateSchema { Properties = new SchemaProperties() })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Update(CreateCommand(new UpdateSchema { Properties = new SchemaProperties() })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -78,7 +83,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<ValidationException>(() => sut.Update(new UpdateSchema())); |
|
|
Assert.Throws<ValidationException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Update(CreateCommand(new UpdateSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -86,7 +94,10 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<ValidationException>(() => sut.Update(new UpdateSchema())); |
|
|
Assert.Throws<ValidationException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Update(CreateCommand(new UpdateSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -96,22 +107,23 @@ namespace Squidex.Write.Schemas |
|
|
|
|
|
|
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
sut.Update(new UpdateSchema { Properties = properties }); |
|
|
sut.Update(CreateCommand(new UpdateSchema { Properties = properties })); |
|
|
|
|
|
|
|
|
Assert.Equal(properties, sut.Schema.Properties); |
|
|
Assert.Equal(properties, sut.Schema.Properties); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new SchemaUpdated { Properties = properties }) |
|
|
{ |
|
|
); |
|
|
new SchemaUpdated { Properties = properties } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Publish_should_throw_if_not_created() |
|
|
public void Publish_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.Publish(new PublishSchema())); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Publish(CreateCommand(new PublishSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -120,7 +132,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.Publish(new PublishSchema())); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Publish(CreateCommand(new PublishSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -128,22 +143,23 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
sut.Publish(new PublishSchema()); |
|
|
sut.Publish(CreateCommand(new PublishSchema())); |
|
|
|
|
|
|
|
|
Assert.True(sut.Schema.IsPublished); |
|
|
Assert.True(sut.Schema.IsPublished); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new SchemaPublished()) |
|
|
{ |
|
|
); |
|
|
new SchemaPublished() |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Unpublish_should_throw_if_not_created() |
|
|
public void Unpublish_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.Unpublish(new UnpublishSchema())); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Unpublish(CreateCommand(new UnpublishSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -152,7 +168,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.Unpublish(new UnpublishSchema())); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Unpublish(CreateCommand(new UnpublishSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -161,22 +180,23 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
PublishSchema(); |
|
|
PublishSchema(); |
|
|
|
|
|
|
|
|
sut.Unpublish(new UnpublishSchema()); |
|
|
sut.Unpublish(CreateCommand(new UnpublishSchema())); |
|
|
|
|
|
|
|
|
Assert.False(sut.Schema.IsPublished); |
|
|
Assert.False(sut.Schema.IsPublished); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new SchemaUnpublished()) |
|
|
{ |
|
|
); |
|
|
new SchemaUnpublished() |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Delete_should_throw_if_not_created() |
|
|
public void Delete_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.Delete(new DeleteSchema())); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Delete(CreateCommand(new DeleteSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -185,7 +205,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.Delete(new DeleteSchema())); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.Delete(CreateCommand(new DeleteSchema())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -193,28 +216,32 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
sut.Delete(new DeleteSchema()); |
|
|
sut.Delete(CreateCommand(new DeleteSchema())); |
|
|
|
|
|
|
|
|
Assert.True(sut.IsDeleted); |
|
|
Assert.True(sut.IsDeleted); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new SchemaDeleted()) |
|
|
{ |
|
|
); |
|
|
new SchemaDeleted() |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void AddField_should_throw_if_not_created() |
|
|
public void AddField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.AddField(new AddField { Name = fieldName, Properties = new NumberFieldProperties() })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.AddField(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void AddField_should_throw_if_command_is_not_valid() |
|
|
public void AddField_should_throw_if_command_is_not_valid() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<ValidationException>(() => sut.AddField(new AddField())); |
|
|
Assert.Throws<ValidationException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.AddField(CreateCommand(new AddField())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -223,7 +250,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.AddField(new AddField { Name = fieldName, Properties = new NumberFieldProperties() })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.AddField(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -233,28 +263,32 @@ namespace Squidex.Write.Schemas |
|
|
|
|
|
|
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
sut.AddField(new AddField { Name = fieldName, Properties = properties }); |
|
|
sut.AddField(CreateCommand(new AddField { Name = fieldName, Properties = properties })); |
|
|
|
|
|
|
|
|
Assert.Equal(properties, sut.Schema.Fields[1].RawProperties); |
|
|
Assert.Equal(properties, sut.Schema.Fields[1].RawProperties); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldAdded { Name = fieldName, FieldId = fieldId, Properties = properties }) |
|
|
{ |
|
|
); |
|
|
new FieldAdded { Name = fieldName, FieldId = 1, Properties = properties } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void UpdateField_should_throw_if_not_created() |
|
|
public void UpdateField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.UpdateField(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void UpdateField_should_throw_if_command_is_not_valid() |
|
|
public void UpdateField_should_throw_if_command_is_not_valid() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<ValidationException>(() => sut.UpdateField(new UpdateField())); |
|
|
Assert.Throws<ValidationException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.UpdateField(CreateCommand(new UpdateField())); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -262,7 +296,10 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainObjectNotFoundException>(() => sut.UpdateField(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() })); |
|
|
Assert.Throws<DomainObjectNotFoundException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -271,7 +308,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.UpdateField(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -282,22 +322,23 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
CreateField(); |
|
|
CreateField(); |
|
|
|
|
|
|
|
|
sut.UpdateField(new UpdateField { FieldId = 1, Properties = properties }); |
|
|
sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = properties })); |
|
|
|
|
|
|
|
|
Assert.Equal(properties, sut.Schema.Fields[1].RawProperties); |
|
|
Assert.Equal(properties, sut.Schema.Fields[1].RawProperties); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldUpdated { FieldId = fieldId, Properties = properties }) |
|
|
{ |
|
|
); |
|
|
new FieldUpdated { FieldId = 1, Properties = properties } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void HideField_should_throw_if_not_created() |
|
|
public void HideField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.HideField(new HideField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.HideField(CreateCommand(new HideField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -305,7 +346,10 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainObjectNotFoundException>(() => sut.HideField(new HideField { FieldId = 2 })); |
|
|
Assert.Throws<DomainObjectNotFoundException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.HideField(CreateCommand(new HideField { FieldId = 2 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -314,7 +358,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.HideField(new HideField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.HideField(CreateCommand(new HideField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -323,22 +370,23 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
CreateField(); |
|
|
CreateField(); |
|
|
|
|
|
|
|
|
sut.HideField(new HideField { FieldId = 1 }); |
|
|
sut.HideField(CreateCommand(new HideField { FieldId = 1 })); |
|
|
|
|
|
|
|
|
Assert.True(sut.Schema.Fields[1].IsHidden); |
|
|
Assert.True(sut.Schema.Fields[1].IsHidden); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldHidden { FieldId = fieldId }) |
|
|
{ |
|
|
); |
|
|
new FieldHidden { FieldId = 1 } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void ShowField_should_throw_if_not_created() |
|
|
public void ShowField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.ShowField(new ShowField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.ShowField(CreateCommand(new ShowField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -346,7 +394,10 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainObjectNotFoundException>(() => sut.ShowField(new ShowField { FieldId = 2 })); |
|
|
Assert.Throws<DomainObjectNotFoundException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.ShowField(CreateCommand(new ShowField { FieldId = 2 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -355,7 +406,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.ShowField(new ShowField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.ShowField(CreateCommand(new ShowField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -364,23 +418,24 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
CreateField(); |
|
|
CreateField(); |
|
|
|
|
|
|
|
|
sut.HideField(new HideField { FieldId = 1 }); |
|
|
sut.HideField(CreateCommand(new HideField { FieldId = 1 })); |
|
|
sut.ShowField(new ShowField { FieldId = 1 }); |
|
|
sut.ShowField(CreateCommand(new ShowField { FieldId = 1 })); |
|
|
|
|
|
|
|
|
Assert.False(sut.Schema.Fields[1].IsHidden); |
|
|
Assert.False(sut.Schema.Fields[1].IsHidden); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).Skip(1).ToArray() |
|
|
sut.GetUncomittedEvents().Skip(1) |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldShown { FieldId = fieldId }) |
|
|
{ |
|
|
); |
|
|
new FieldShown { FieldId = 1 } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void DisableField_should_throw_if_not_created() |
|
|
public void DisableField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.DisableField(new DisableField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.DisableField(CreateCommand(new DisableField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -388,7 +443,10 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainObjectNotFoundException>(() => sut.DisableField(new DisableField { FieldId = 2 })); |
|
|
Assert.Throws<DomainObjectNotFoundException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.DisableField(CreateCommand(new DisableField { FieldId = 2 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -397,7 +455,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.DisableField(new DisableField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.DisableField(CreateCommand(new DisableField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -405,23 +466,24 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
CreateField(); |
|
|
CreateField(); |
|
|
|
|
|
|
|
|
sut.DisableField(new DisableField { FieldId = 1 }); |
|
|
sut.DisableField(CreateCommand(new DisableField { FieldId = 1 })); |
|
|
|
|
|
|
|
|
Assert.True(sut.Schema.Fields[1].IsDisabled); |
|
|
Assert.True(sut.Schema.Fields[1].IsDisabled); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldDisabled { FieldId = fieldId }) |
|
|
{ |
|
|
); |
|
|
new FieldDisabled { FieldId = 1 } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void EnableField_should_throw_if_not_created() |
|
|
public void EnableField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.EnableField(new EnableField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.EnableField(CreateCommand(new EnableField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -429,7 +491,10 @@ namespace Squidex.Write.Schemas |
|
|
{ |
|
|
{ |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainObjectNotFoundException>(() => sut.EnableField(new EnableField { FieldId = 2 })); |
|
|
Assert.Throws<DomainObjectNotFoundException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.EnableField(CreateCommand(new EnableField { FieldId = 2 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -438,7 +503,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.EnableField(new EnableField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.EnableField(CreateCommand(new EnableField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -447,23 +515,24 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
CreateField(); |
|
|
CreateField(); |
|
|
|
|
|
|
|
|
sut.DisableField(new DisableField { FieldId = 1 }); |
|
|
sut.DisableField(CreateCommand(new DisableField { FieldId = 1 })); |
|
|
sut.EnableField(new EnableField { FieldId = 1 }); |
|
|
sut.EnableField(CreateCommand(new EnableField { FieldId = 1 })); |
|
|
|
|
|
|
|
|
Assert.False(sut.Schema.Fields[1].IsDisabled); |
|
|
Assert.False(sut.Schema.Fields[1].IsDisabled); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).Skip(1).ToArray() |
|
|
sut.GetUncomittedEvents().Skip(1) |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldEnabled { FieldId = fieldId }) |
|
|
{ |
|
|
); |
|
|
new FieldEnabled { FieldId = 1 } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void DeleteField_should_throw_if_not_created() |
|
|
public void DeleteField_should_throw_if_not_created() |
|
|
{ |
|
|
{ |
|
|
Assert.Throws<DomainException>(() => sut.DeleteField(new DeleteField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.DeleteField(CreateCommand(new DeleteField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -472,7 +541,10 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
DeleteSchema(); |
|
|
DeleteSchema(); |
|
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => sut.DeleteField(new DeleteField { FieldId = 1 })); |
|
|
Assert.Throws<DomainException>(() => |
|
|
|
|
|
{ |
|
|
|
|
|
sut.DeleteField(CreateCommand(new DeleteField { FieldId = 1 })); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -481,16 +553,14 @@ namespace Squidex.Write.Schemas |
|
|
CreateSchema(); |
|
|
CreateSchema(); |
|
|
CreateField(); |
|
|
CreateField(); |
|
|
|
|
|
|
|
|
sut.DeleteField(new DeleteField { FieldId = 1 }); |
|
|
sut.DeleteField(CreateCommand(new DeleteField { FieldId = 1 })); |
|
|
|
|
|
|
|
|
Assert.False(sut.Schema.Fields.ContainsKey(1)); |
|
|
Assert.False(sut.Schema.Fields.ContainsKey(1)); |
|
|
|
|
|
|
|
|
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray() |
|
|
sut.GetUncomittedEvents() |
|
|
.ShouldBeEquivalentTo( |
|
|
.ShouldHaveSameEvents( |
|
|
new IEvent[] |
|
|
CreateEvent(new FieldDeleted { FieldId = fieldId }) |
|
|
{ |
|
|
); |
|
|
new FieldDeleted { FieldId = 1 } |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void CreateField() |
|
|
private void CreateField() |
|
|
@ -502,21 +572,21 @@ namespace Squidex.Write.Schemas |
|
|
|
|
|
|
|
|
private void CreateSchema() |
|
|
private void CreateSchema() |
|
|
{ |
|
|
{ |
|
|
sut.Create(new CreateSchema { Name = appName, AppId = appId }); |
|
|
sut.Create(CreateCommand(new CreateSchema { Name = SchemaName })); |
|
|
|
|
|
|
|
|
((IAggregate)sut).ClearUncommittedEvents(); |
|
|
((IAggregate)sut).ClearUncommittedEvents(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void PublishSchema() |
|
|
private void PublishSchema() |
|
|
{ |
|
|
{ |
|
|
sut.Publish(new PublishSchema()); |
|
|
sut.Publish(CreateCommand(new PublishSchema())); |
|
|
|
|
|
|
|
|
((IAggregate)sut).ClearUncommittedEvents(); |
|
|
((IAggregate)sut).ClearUncommittedEvents(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void DeleteSchema() |
|
|
private void DeleteSchema() |
|
|
{ |
|
|
{ |
|
|
sut.Delete(new DeleteSchema()); |
|
|
sut.Delete(CreateCommand(new DeleteSchema())); |
|
|
|
|
|
|
|
|
((IAggregate)sut).ClearUncommittedEvents(); |
|
|
((IAggregate)sut).ClearUncommittedEvents(); |
|
|
} |
|
|
} |
|
|
|