Browse Source

Missing changes committed

pull/1/head
Sebastian Stehle 9 years ago
parent
commit
4ef27bb390
  1. 4
      global.json
  2. 41
      src/Squidex.Core/Schemas/BooleanField.cs
  3. 16
      src/Squidex.Core/Schemas/BooleanFieldEditor.cs
  4. 50
      src/Squidex.Core/Schemas/BooleanFieldProperties.cs
  5. 1
      src/Squidex.Core/Schemas/FieldRegistry.cs
  6. 37
      src/Squidex.Core/Schemas/Schema.cs
  7. 18
      src/Squidex.Events/Schemas/SchemaPublished.cs
  8. 18
      src/Squidex.Events/Schemas/SchemaUnpublished.cs
  9. 2
      src/Squidex.Infrastructure/RefToken.cs
  10. 2
      src/Squidex.Read/Schemas/Repositories/ISchemaEntity.cs
  11. 1
      src/Squidex.Store.MongoDb/History/ParsedHistoryEvent.cs
  12. 4
      src/Squidex.Store.MongoDb/Schemas/MongoSchemaEntity.cs
  13. 12
      src/Squidex.Store.MongoDb/Schemas/MongoSchemaRepository.cs
  14. 14
      src/Squidex.Write/Schemas/Commands/PublishSchema.cs
  15. 14
      src/Squidex.Write/Schemas/Commands/UnpublishSchema.cs
  16. 10
      src/Squidex.Write/Schemas/SchemaCommandHandler.cs
  17. 28
      src/Squidex.Write/Schemas/SchemaDomainObject.cs
  18. 4
      src/Squidex/Config/Identity/SwaggerIdentityUsage.cs
  19. 8
      src/Squidex/Controllers/Api/Schemas/SchemasController.cs
  20. 34
      tests/Squidex.Core.Tests/Schemas/BooleanFieldPropertiesTests.cs
  21. 66
      tests/Squidex.Core.Tests/Schemas/BooleanFieldTests.cs
  22. 1
      tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs
  23. 31
      tests/Squidex.Core.Tests/Schemas/SchemaTests.cs
  24. 34
      tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs
  25. 72
      tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs

4
global.json

@ -1,6 +1,6 @@
{ {
"projects": [ "src" ], "projects": [ "src", "tests" ],
"sdk": { "sdk": {
"version": "1.0.0-preview2-003133" "version": "1.0.0-preview2-1-003177"
} }
} }

41
src/Squidex.Core/Schemas/BooleanField.cs

@ -0,0 +1,41 @@
// ==========================================================================
// BooleanField.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using System.Globalization;
using Squidex.Core.Schemas.Validators;
using Squidex.Infrastructure;
namespace Squidex.Core.Schemas
{
public sealed class BooleanField : Field<BooleanFieldProperties>
{
public BooleanField(long id, string name, BooleanFieldProperties properties)
: base(id, name, properties)
{
}
protected override IEnumerable<IValidator> CreateValidators()
{
if (Properties.IsRequired)
{
yield return new RequiredValidator();
}
}
protected override object ConvertValue(PropertyValue property)
{
return property.ToNullableBoolean(CultureInfo.InvariantCulture);
}
protected override Field Clone()
{
return new BooleanField(Id, Name, Properties);
}
}
}

16
src/Squidex.Core/Schemas/BooleanFieldEditor.cs

@ -0,0 +1,16 @@
// ==========================================================================
// BooleanFieldEditor.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
namespace Squidex.Core.Schemas
{
public enum BooleanFieldEditor
{
Checkbox,
Toggle
}
}

50
src/Squidex.Core/Schemas/BooleanFieldProperties.cs

@ -0,0 +1,50 @@
// ==========================================================================
// BooleanFieldProperties.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using Squidex.Infrastructure;
namespace Squidex.Core.Schemas
{
[TypeName("BooleanField")]
public sealed class BooleanFieldProperties : FieldProperties
{
private BooleanFieldEditor editor;
private bool? defaultValue;
public bool? DefaultValue
{
get { return defaultValue; }
set
{
ThrowIfFrozen();
defaultValue = value;
}
}
public BooleanFieldEditor Editor
{
get { return editor; }
set
{
ThrowIfFrozen();
editor = value;
}
}
protected override IEnumerable<ValidationError> ValidateCore()
{
if (!Editor.IsEnumValue())
{
yield return new ValidationError("Editor ist not a valid value", nameof(Editor));
}
}
}
}

1
src/Squidex.Core/Schemas/FieldRegistry.cs

@ -51,6 +51,7 @@ namespace Squidex.Core.Schemas
public FieldRegistry() public FieldRegistry()
{ {
Add<BooleanFieldProperties>((id, name, properties) => new BooleanField(id, name, (BooleanFieldProperties)properties));
Add<NumberFieldProperties>((id, name, properties) => new NumberField(id, name, (NumberFieldProperties)properties)); Add<NumberFieldProperties>((id, name, properties) => new NumberField(id, name, (NumberFieldProperties)properties));
Add<StringFieldProperties>((id, name, properties) => new StringField(id, name, (StringFieldProperties)properties)); Add<StringFieldProperties>((id, name, properties) => new StringField(id, name, (StringFieldProperties)properties));
} }

37
src/Squidex.Core/Schemas/Schema.cs

@ -20,6 +20,7 @@ namespace Squidex.Core.Schemas
public sealed class Schema public sealed class Schema
{ {
private readonly string name; private readonly string name;
private readonly bool isPublished;
private readonly SchemaProperties properties; private readonly SchemaProperties properties;
private readonly ImmutableDictionary<long, Field> fieldsById; private readonly ImmutableDictionary<long, Field> fieldsById;
private readonly Dictionary<string, Field> fieldsByName; private readonly Dictionary<string, Field> fieldsByName;
@ -29,6 +30,11 @@ namespace Squidex.Core.Schemas
get { return name; } get { return name; }
} }
public bool IsPublished
{
get { return isPublished; }
}
public ImmutableDictionary<long, Field> Fields public ImmutableDictionary<long, Field> Fields
{ {
get { return fieldsById; } get { return fieldsById; }
@ -39,7 +45,7 @@ namespace Squidex.Core.Schemas
get { return properties; } get { return properties; }
} }
public Schema(string name, SchemaProperties properties, ImmutableDictionary<long, Field> fields) public Schema(string name, SchemaProperties properties, bool isPublished, ImmutableDictionary<long, Field> fields)
{ {
Guard.NotNull(fields, nameof(fields)); Guard.NotNull(fields, nameof(fields));
Guard.NotNull(properties, nameof(properties)); Guard.NotNull(properties, nameof(properties));
@ -48,6 +54,7 @@ namespace Squidex.Core.Schemas
this.name = name; this.name = name;
this.properties = properties; this.properties = properties;
this.isPublished = isPublished;
fieldsById = fields; fieldsById = fields;
fieldsByName = fields.Values.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase); fieldsByName = fields.Values.ToDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase);
@ -64,14 +71,14 @@ namespace Squidex.Core.Schemas
throw new ValidationException("Cannot create a new schema", error); throw new ValidationException("Cannot create a new schema", error);
} }
return new Schema(name, newProperties, ImmutableDictionary<long, Field>.Empty); return new Schema(name, newProperties, false, ImmutableDictionary<long, Field>.Empty);
} }
public Schema Update(SchemaProperties newProperties) public Schema Update(SchemaProperties newProperties)
{ {
Guard.NotNull(newProperties, nameof(newProperties)); Guard.NotNull(newProperties, nameof(newProperties));
return new Schema(name, newProperties, fieldsById); return new Schema(name, newProperties, isPublished, fieldsById);
} }
public Schema AddOrUpdateField(Field field) public Schema AddOrUpdateField(Field field)
@ -83,7 +90,7 @@ namespace Squidex.Core.Schemas
throw new ValidationException($"A field with name '{field.Name}' already exists."); throw new ValidationException($"A field with name '{field.Name}' already exists.");
} }
return new Schema(name, properties, fieldsById.SetItem(field.Id, field)); return new Schema(name, properties, isPublished, fieldsById.SetItem(field.Id, field));
} }
public Schema UpdateField(long fieldId, FieldProperties newProperties) public Schema UpdateField(long fieldId, FieldProperties newProperties)
@ -118,7 +125,27 @@ namespace Squidex.Core.Schemas
public Schema DeleteField(long fieldId) public Schema DeleteField(long fieldId)
{ {
return new Schema(name, properties, fieldsById.Remove(fieldId)); return new Schema(name, properties, isPublished, fieldsById.Remove(fieldId));
}
public Schema Publish()
{
if (isPublished)
{
throw new DomainException("Schema is already published");
}
return new Schema(name, properties, true, fieldsById);
}
public Schema Unpublish()
{
if (!isPublished)
{
throw new DomainException("Schema is not published");
}
return new Schema(name, properties, false, fieldsById);
} }
public Schema UpdateField(long fieldId, Func<Field, Field> updater) public Schema UpdateField(long fieldId, Func<Field, Field> updater)

18
src/Squidex.Events/Schemas/SchemaPublished.cs

@ -0,0 +1,18 @@
// ==========================================================================
// SchemaPublished.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Events;
namespace Squidex.Events.Schemas
{
[TypeName("SchemaPublished")]
public class SchemaPublished : IEvent
{
}
}

18
src/Squidex.Events/Schemas/SchemaUnpublished.cs

@ -0,0 +1,18 @@
// ==========================================================================
// SchemaUnpublished.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Events;
namespace Squidex.Events.Schemas
{
[TypeName("SchemaUnpublished")]
public class SchemaUnpublished : IEvent
{
}
}

2
src/Squidex.Infrastructure/RefToken.cs

@ -58,7 +58,7 @@ namespace Squidex.Infrastructure
public override int GetHashCode() public override int GetHashCode()
{ {
return (Type.GetHashCode() * 397) ^ (Identifier.GetHashCode()); return (Type.GetHashCode() * 397) ^ Identifier.GetHashCode();
} }
} }
} }

2
src/Squidex.Read/Schemas/Repositories/ISchemaEntity.cs

@ -10,5 +10,7 @@ namespace Squidex.Read.Schemas.Repositories
public interface ISchemaEntity : IAppRefEntity, ITrackCreatedByEntity, ITrackLastModifiedByEntity public interface ISchemaEntity : IAppRefEntity, ITrackCreatedByEntity, ITrackLastModifiedByEntity
{ {
string Name { get; } string Name { get; }
bool IsPublished { get; }
} }
} }

1
src/Squidex.Store.MongoDb/History/ParsedHistoryEvent.cs

@ -10,6 +10,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Read.History; using Squidex.Read.History;
// ReSharper disable LoopCanBeConvertedToQuery
namespace Squidex.Store.MongoDb.History namespace Squidex.Store.MongoDb.History
{ {

4
src/Squidex.Store.MongoDb/Schemas/MongoSchemaEntity.cs

@ -45,6 +45,10 @@ namespace Squidex.Store.MongoDb.Schemas
[BsonElement] [BsonElement]
public BsonDocument Schema { get; set; } public BsonDocument Schema { get; set; }
[BsonIgnoreIfDefault]
[BsonElement]
public bool IsPublished { get; set; }
Schema ISchemaEntityWithSchema.Schema Schema ISchemaEntityWithSchema.Schema
{ {
get { return schema.Value; } get { return schema.Value; }

12
src/Squidex.Store.MongoDb/Schemas/MongoSchemaRepository.cs

@ -128,6 +128,16 @@ namespace Squidex.Store.MongoDb.Schemas
return UpdateSchema(headers, s => s.Update(@event.Properties)); return UpdateSchema(headers, s => s.Update(@event.Properties));
} }
protected Task On(SchemaPublished @event, EnvelopeHeaders headers)
{
return UpdateSchema(headers, s => s.Publish());
}
protected Task On(SchemaUnpublished @event, EnvelopeHeaders headers)
{
return UpdateSchema(headers, s => s.Publish());
}
protected Task On(FieldAdded @event, EnvelopeHeaders headers) protected Task On(FieldAdded @event, EnvelopeHeaders headers)
{ {
var field = fieldRegistry.CreateField(@event.FieldId, @event.Name, @event.Properties); var field = fieldRegistry.CreateField(@event.FieldId, @event.Name, @event.Properties);
@ -159,6 +169,8 @@ namespace Squidex.Store.MongoDb.Schemas
currentSchema = updater(currentSchema); currentSchema = updater(currentSchema);
Serialize(entity, currentSchema); Serialize(entity, currentSchema);
entity.IsPublished = currentSchema.IsPublished;
} }
private void Serialize(MongoSchemaEntity entity, Schema schema) private void Serialize(MongoSchemaEntity entity, Schema schema)

14
src/Squidex.Write/Schemas/Commands/PublishSchema.cs

@ -0,0 +1,14 @@
// ==========================================================================
// PublishSchema.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
namespace Squidex.Write.Schemas.Commands
{
public class PublishSchema : AppCommand
{
}
}

14
src/Squidex.Write/Schemas/Commands/UnpublishSchema.cs

@ -0,0 +1,14 @@
// ==========================================================================
// UnpublishShema.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
namespace Squidex.Write.Schemas.Commands
{
public class UnpublishSchema : AppCommand
{
}
}

10
src/Squidex.Write/Schemas/SchemaCommandHandler.cs

@ -99,6 +99,16 @@ namespace Squidex.Write.Schemas
return handler.UpdateAsync<SchemaDomainObject>(command, s => { s.UpdateField(command); }); return handler.UpdateAsync<SchemaDomainObject>(command, s => { s.UpdateField(command); });
} }
protected Task On(PublishSchema command, CommandContext context)
{
return handler.UpdateAsync<SchemaDomainObject>(command, s => { s.Publish(command); });
}
protected Task On(UnpublishSchema command, CommandContext context)
{
return handler.UpdateAsync<SchemaDomainObject>(command, s => { s.Unpublish(command); });
}
public Task<bool> HandleAsync(CommandContext context) public Task<bool> HandleAsync(CommandContext context)
{ {
return context.IsHandled ? Task.FromResult(false) : this.DispatchActionAsync(context.Command, context); return context.IsHandled ? Task.FromResult(false) : this.DispatchActionAsync(context.Command, context);

28
src/Squidex.Write/Schemas/SchemaDomainObject.cs

@ -90,6 +90,16 @@ namespace Squidex.Write.Schemas
schema = schema.DeleteField(@event.FieldId); schema = schema.DeleteField(@event.FieldId);
} }
protected void On(SchemaPublished @event)
{
schema = schema.Publish();
}
protected void On(SchemaUnpublished @event)
{
schema = schema.Unpublish();
}
protected void On(SchemaDeleted @event) protected void On(SchemaDeleted @event)
{ {
isDeleted = true; isDeleted = true;
@ -194,6 +204,24 @@ namespace Squidex.Write.Schemas
return this; return this;
} }
public SchemaDomainObject Publish(PublishSchema command)
{
VerifyCreatedAndNotDeleted();
RaiseEvent(new SchemaPublished());
return this;
}
public SchemaDomainObject Unpublish(UnpublishSchema command)
{
VerifyCreatedAndNotDeleted();
RaiseEvent(new SchemaUnpublished());
return this;
}
public SchemaDomainObject Delete(DeleteSchema command) public SchemaDomainObject Delete(DeleteSchema command)
{ {
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();

4
src/Squidex/Config/Identity/SwaggerIdentityUsage.cs

@ -22,7 +22,9 @@ namespace Squidex.Config.Identity
$ curl $ curl
-X POST '{0}' -X POST '{0}'
-H 'Content-Type: application/x-www-form-urlencoded' -H 'Content-Type: application/x-www-form-urlencoded'
-d 'grant_type=client_credentials&client_id=[APP_NAME]:[CLIENT_NAME]&client_secret=[CLIENT_SECRET]'"; -d 'grant_type=client_credentials&
client_id=[APP_NAME]:[CLIENT_NAME]&
client_secret=[CLIENT_SECRET]'";
public static SwaggerOwinSettings ConfigureIdentity(this SwaggerOwinSettings settings, MyUrlsOptions options) public static SwaggerOwinSettings ConfigureIdentity(this SwaggerOwinSettings settings, MyUrlsOptions options)
{ {

8
src/Squidex/Controllers/Api/Schemas/SchemasController.cs

@ -127,7 +127,7 @@ namespace Squidex.Controllers.Api.Schemas
} }
/// <summary> /// <summary>
/// Publishs a schema. /// Publish a schema.
/// </summary> /// </summary>
/// <param name="app">The app where the schema is a part of.</param> /// <param name="app">The app where the schema is a part of.</param>
/// <param name="name">The name of the schema to publish.</param> /// <param name="name">The name of the schema to publish.</param>
@ -137,6 +137,7 @@ namespace Squidex.Controllers.Api.Schemas
/// </returns> /// </returns>
[HttpPut] [HttpPut]
[Route("apps/{app}/schemas/{name}/publish")] [Route("apps/{app}/schemas/{name}/publish")]
[ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> PublishSchema(string app, string name) public async Task<IActionResult> PublishSchema(string app, string name)
{ {
await CommandBus.PublishAsync(new PublishSchema()); await CommandBus.PublishAsync(new PublishSchema());
@ -145,7 +146,7 @@ namespace Squidex.Controllers.Api.Schemas
} }
/// <summary> /// <summary>
/// Unpublishs a schema. /// Unpublish a schema.
/// </summary> /// </summary>
/// <param name="app">The app where the schema is a part of.</param> /// <param name="app">The app where the schema is a part of.</param>
/// <param name="name">The name of the schema to unpublish.</param> /// <param name="name">The name of the schema to unpublish.</param>
@ -154,7 +155,8 @@ namespace Squidex.Controllers.Api.Schemas
/// 204 => Schema has been deleted. /// 204 => Schema has been deleted.
/// </returns> /// </returns>
[HttpPut] [HttpPut]
[Route("apps/{app}/schemas/{name}/publish")] [Route("apps/{app}/schemas/{name}/unpublish")]
[ProducesResponseType(typeof(ErrorDto), 400)]
public async Task<IActionResult> UnpublishSchema(string app, string name) public async Task<IActionResult> UnpublishSchema(string app, string name)
{ {
await CommandBus.PublishAsync(new UnpublishSchema()); await CommandBus.PublishAsync(new UnpublishSchema());

34
tests/Squidex.Core.Tests/Schemas/BooleanFieldPropertiesTests.cs

@ -0,0 +1,34 @@
// ==========================================================================
// BooleanFieldPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Core.Schemas
{
public class BooleanFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_add_error_if_editor_is_not_valid()
{
var sut = new BooleanFieldProperties { Editor = (BooleanFieldEditor)123 };
sut.Validate(errors);
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Editor ist not a valid value", "Editor")
});
}
}
}

66
tests/Squidex.Core.Tests/Schemas/BooleanFieldTests.cs

@ -0,0 +1,66 @@
// ==========================================================================
// BooleanFieldTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using System.Threading.Tasks;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Core.Schemas
{
public class BooleanFieldTests
{
private readonly List<string> errors = new List<string>();
[Fact]
public void Should_instantiate_field()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties());
Assert.Equal("name", sut.Name);
}
[Fact]
public void Should_clone_object()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties());
Assert.NotEqual(sut, sut.Enable());
}
[Fact]
public async Task Should_add_errors_if_boolean_is_required()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties { Label = "Name", IsRequired = true });
await sut.ValidateAsync(CreateValue(null), errors);
errors.ShouldBeEquivalentTo(
new[] { "Name is required" });
}
[Fact]
public async Task Should_add_errors_if_value_is_not_valid()
{
var sut = new BooleanField(1, "name", new BooleanFieldProperties { Label = "Name" });
await sut.ValidateAsync(CreateValue("Invalid"), errors);
errors.ShouldBeEquivalentTo(
new[] { "Name is not a valid value" });
}
private static PropertyValue CreateValue(object v)
{
var bag = new PropertiesBag().Set("value", v);
return bag["value"];
}
}
}

1
tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs

@ -27,6 +27,7 @@ namespace Squidex.Core.Schemas
static FieldRegistryTests() static FieldRegistryTests()
{ {
TypeNameRegistry.Map(typeof(BooleanFieldProperties), "BooleanField");
TypeNameRegistry.Map(typeof(NumberFieldProperties), "NumberField"); TypeNameRegistry.Map(typeof(NumberFieldProperties), "NumberField");
TypeNameRegistry.Map(typeof(StringFieldProperties), "StringField"); TypeNameRegistry.Map(typeof(StringFieldProperties), "StringField");
TypeNameRegistry.Map(typeof(InvalidProperties), "invalid"); TypeNameRegistry.Map(typeof(InvalidProperties), "invalid");

31
tests/Squidex.Core.Tests/Schemas/SchemaTests.cs

@ -267,6 +267,37 @@ namespace Squidex.Core.Schemas
}); });
} }
[Fact]
public void Should_publish_schema()
{
sut = sut.Publish();
Assert.True(sut.IsPublished);
}
[Fact]
public void Should_throw_if_schema_is_already_published()
{
sut = sut.Publish();
Assert.Throws<DomainException>(() => sut.Publish());
}
[Fact]
public void Should_unpublish_schema()
{
sut = sut.Publish();
sut = sut.Unpublish();
Assert.False(sut.IsPublished);
}
[Fact]
public void Should_throw_if_schema_is_not_published()
{
Assert.Throws<DomainException>(() => sut.Unpublish());
}
private NumberField AddField() private NumberField AddField()
{ {
var field = new NumberField(1, "my-field", new NumberFieldProperties()); var field = new NumberField(1, "my-field", new NumberFieldProperties());

34
tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs

@ -90,6 +90,35 @@ namespace Squidex.Write.Schemas
}); });
} }
[Fact]
public async Task PublishSchema_should_update_domain_object()
{
CreateSchema();
var command = new PublishSchema { AggregateId = Id };
var context = new CommandContext(command);
await TestUpdate(schema, async _ =>
{
await sut.HandleAsync(context);
});
}
[Fact]
public async Task UnpublishSchema_should_update_domain_object()
{
CreateSchema();
PublishSchema();
var command = new UnpublishSchema { AggregateId = Id };
var context = new CommandContext(command);
await TestUpdate(schema, async _ =>
{
await sut.HandleAsync(context);
});
}
[Fact] [Fact]
public async Task DeleteSchema_should_update_domain_object() public async Task DeleteSchema_should_update_domain_object()
{ {
@ -215,6 +244,11 @@ namespace Squidex.Write.Schemas
schema.Create(new CreateSchema { Name = schemaName }); schema.Create(new CreateSchema { Name = schemaName });
} }
private void PublishSchema()
{
schema.Publish(new PublishSchema());
}
private void CreateField() private void CreateField()
{ {
schema.AddField(new AddField { Name = fieldName, Properties = new NumberFieldProperties() }); schema.AddField(new AddField { Name = fieldName, Properties = new NumberFieldProperties() });

72
tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs

@ -108,6 +108,71 @@ namespace Squidex.Write.Schemas
}); });
} }
[Fact]
public void Publish_should_throw_if_not_created()
{
Assert.Throws<DomainException>(() => sut.Publish(new PublishSchema()));
}
[Fact]
public void Publish_should_throw_if_schema_is_deleted()
{
CreateSchema();
DeleteSchema();
Assert.Throws<DomainException>(() => sut.Publish(new PublishSchema()));
}
[Fact]
public void Publish_should_refresh_properties_and_create_events()
{
CreateSchema();
sut.Publish(new PublishSchema());
Assert.True(sut.Schema.IsPublished);
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray()
.ShouldBeEquivalentTo(
new IEvent[]
{
new SchemaPublished()
});
}
[Fact]
public void Unpublish_should_throw_if_not_created()
{
Assert.Throws<DomainException>(() => sut.Unpublish(new UnpublishSchema()));
}
[Fact]
public void Unpublish_should_throw_if_schema_is_deleted()
{
CreateSchema();
DeleteSchema();
Assert.Throws<DomainException>(() => sut.Unpublish(new UnpublishSchema()));
}
[Fact]
public void Unpublish_should_refresh_properties_and_create_events()
{
CreateSchema();
PublishSchema();
sut.Unpublish(new UnpublishSchema());
Assert.False(sut.Schema.IsPublished);
sut.GetUncomittedEvents().Select(x => x.Payload).ToArray()
.ShouldBeEquivalentTo(
new IEvent[]
{
new SchemaUnpublished()
});
}
[Fact] [Fact]
public void Delete_should_throw_if_not_created() public void Delete_should_throw_if_not_created()
{ {
@ -442,6 +507,13 @@ namespace Squidex.Write.Schemas
((IAggregate)sut).ClearUncommittedEvents(); ((IAggregate)sut).ClearUncommittedEvents();
} }
private void PublishSchema()
{
sut.Publish(new PublishSchema());
((IAggregate)sut).ClearUncommittedEvents();
}
private void DeleteSchema() private void DeleteSchema()
{ {
sut.Delete(new DeleteSchema()); sut.Delete(new DeleteSchema());

Loading…
Cancel
Save