Browse Source

Merge branch 'feature-import'

pull/65/head
Sebastian Stehle 9 years ago
parent
commit
6c6d46ba3d
  1. 2
      src/Squidex.Core/Schemas/FieldRegistry.cs
  2. 2
      src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs
  3. 10
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs
  4. 13
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs
  5. 2
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs
  6. 2
      src/Squidex.Read/Contents/Builders/EdmModelBuilder.cs
  7. 6
      src/Squidex.Read/Schemas/ISchemaEntity.cs
  8. 17
      src/Squidex.Read/Schemas/ISchemaEntityWithSchema.cs
  9. 6
      src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs
  10. 4
      src/Squidex.Read/Schemas/Services/ISchemaProvider.cs
  11. 8
      src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs
  12. 36
      src/Squidex.Write/Schemas/Commands/CreateSchema.cs
  13. 39
      src/Squidex.Write/Schemas/SchemaDomainObject.cs
  14. 45
      src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs
  15. 11
      src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs
  16. 44
      src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaFieldDto.cs
  17. 12
      src/Squidex/Controllers/Api/Schemas/Models/SchemaDetailsDto.cs
  18. 6
      src/Squidex/Controllers/Api/Schemas/Models/SchemaDto.cs
  19. 27
      src/Squidex/Controllers/Api/Schemas/Models/SchemaPropertiesDto.cs
  20. 6
      src/Squidex/Controllers/Api/Schemas/SchemasController.cs
  21. 2
      src/Squidex/Controllers/ContentApi/ContentSwaggerController.cs
  22. 4
      src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs
  23. 4
      src/Squidex/app/features/content/pages/content/content-field.component.html
  24. 2
      src/Squidex/app/features/content/pages/contents/contents-page.component.html
  25. 2
      src/Squidex/app/features/content/pages/schemas/schemas-page.component.html
  26. 4
      src/Squidex/app/features/schemas/pages/messages.ts
  27. 2
      src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html
  28. 15
      src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.ts
  29. 6
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.html
  30. 20
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  31. 15
      src/Squidex/app/features/schemas/pages/schema/schema-properties.ts
  32. 11
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html
  33. 13
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.scss
  34. 23
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts
  35. 2
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html
  36. 2
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  37. 23
      src/Squidex/app/shared/services/schemas.service.spec.ts
  38. 24
      src/Squidex/app/shared/services/schemas.service.ts
  39. 2
      tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs
  40. 32
      tests/Squidex.Core.Tests/Schemas/SchemaTests.cs
  41. 4
      tests/Squidex.Infrastructure.Tests/CQRS/Commands/AggregateHandlerTests.cs
  42. 2
      tests/Squidex.Infrastructure.Tests/CQRS/Commands/DefaultDomainObjectFactoryTests.cs
  43. 4
      tests/Squidex.Infrastructure.Tests/GuardTests.cs
  44. 6
      tests/Squidex.Infrastructure.Tests/LanguageTests.cs
  45. 6
      tests/Squidex.Infrastructure.Tests/NamedIdTest.cs
  46. 2
      tests/Squidex.Infrastructure.Tests/RefTokenTests.cs
  47. 8
      tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs
  48. 4
      tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs
  49. 10
      tests/Squidex.Infrastructure.Tests/TypeNameRegistryTests.cs
  50. 6
      tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs
  51. 2
      tests/Squidex.Read.Tests/MongoDb/Contents/ODataQueryTests.cs
  52. 12
      tests/Squidex.Read.Tests/Schemas/CachingSchemaProviderTests.cs
  53. 8
      tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs
  54. 62
      tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs
  55. 18
      tests/Squidex.Write.Tests/Assets/AssetDomainObjectTests.cs
  56. 2
      tests/Squidex.Write.Tests/Contents/ContentCommandHandlerTests.cs
  57. 28
      tests/Squidex.Write.Tests/Contents/ContentDomainObjectTests.cs
  58. 6
      tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs
  59. 114
      tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs

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

@ -90,6 +90,8 @@ namespace Squidex.Core.Schemas
public Field CreateField(long id, string name, Partitioning partitioning, FieldProperties properties) public Field CreateField(long id, string name, Partitioning partitioning, FieldProperties properties)
{ {
Guard.NotNull(properties, nameof(properties));
var registered = fieldsByPropertyType.GetOrDefault(properties.GetType()); var registered = fieldsByPropertyType.GetOrDefault(properties.GetType());
if (registered == null) if (registered == null)

2
src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs

@ -139,7 +139,7 @@ namespace Squidex.Read.MongoDb.Contents
return result; return result;
} }
private async Task ForSchemaAsync(Guid schemaId, Func<IMongoCollection<MongoContentEntity>, ISchemaEntityWithSchema, Task> action) private async Task ForSchemaAsync(Guid schemaId, Func<IMongoCollection<MongoContentEntity>, ISchemaEntity, Task> action)
{ {
var collection = GetCollection(schemaId); var collection = GetCollection(schemaId);

10
src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs

@ -17,7 +17,7 @@ using Squidex.Read.Schemas;
namespace Squidex.Read.MongoDb.Schemas namespace Squidex.Read.MongoDb.Schemas
{ {
public sealed class MongoSchemaEntity : MongoEntity, ISchemaEntityWithSchema public sealed class MongoSchemaEntity : MongoEntity, ISchemaEntity
{ {
private Lazy<Schema> schema; private Lazy<Schema> schema;
@ -25,10 +25,6 @@ namespace Squidex.Read.MongoDb.Schemas
[BsonElement] [BsonElement]
public string Name { get; set; } public string Name { get; set; }
[BsonRequired]
[BsonElement]
public string Label { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement]
public string Schema { get; set; } public string Schema { get; set; }
@ -57,15 +53,13 @@ namespace Squidex.Read.MongoDb.Schemas
[BsonElement] [BsonElement]
public bool IsDeleted { get; set; } public bool IsDeleted { get; set; }
Schema ISchemaEntityWithSchema.Schema Schema ISchemaEntity.Schema
{ {
get { return schema.Value; } get { return schema.Value; }
} }
public void SerializeSchema(Schema newSchema, SchemaJsonSerializer serializer) public void SerializeSchema(Schema newSchema, SchemaJsonSerializer serializer)
{ {
Label = newSchema.Properties.Label ?? newSchema.Name;
Schema = serializer.Serialize(newSchema).ToString(); Schema = serializer.Serialize(newSchema).ToString();
schema = new Lazy<Schema>(() => newSchema); schema = new Lazy<Schema>(() => newSchema);

13
src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs

@ -51,19 +51,12 @@ namespace Squidex.Read.MongoDb.Schemas
{ {
var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync(); var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync();
return entities.OfType<ISchemaEntity>().ToList();
}
public async Task<IReadOnlyList<ISchemaEntityWithSchema>> QueryAllWithSchemaAsync(Guid appId)
{
var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync();
entities.ForEach(x => x.DeserializeSchema(serializer)); entities.ForEach(x => x.DeserializeSchema(serializer));
return entities.OfType<ISchemaEntityWithSchema>().ToList(); return entities.OfType<ISchemaEntity>().ToList();
} }
public async Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid appId, string name) public async Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name)
{ {
var entity = var entity =
await Collection.Find(s => s.Name == name && s.AppId == appId && !s.IsDeleted) await Collection.Find(s => s.Name == name && s.AppId == appId && !s.IsDeleted)
@ -74,7 +67,7 @@ namespace Squidex.Read.MongoDb.Schemas
return entity; return entity;
} }
public async Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid schemaId) public async Task<ISchemaEntity> FindSchemaAsync(Guid schemaId)
{ {
var entity = var entity =
await Collection.Find(s => s.Id == schemaId) await Collection.Find(s => s.Id == schemaId)

2
src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs

@ -38,7 +38,7 @@ namespace Squidex.Read.MongoDb.Schemas
protected Task On(SchemaCreated @event, EnvelopeHeaders headers) protected Task On(SchemaCreated @event, EnvelopeHeaders headers)
{ {
var schema = SchemaEventDispatcher.Dispatch(@event); var schema = SchemaEventDispatcher.Dispatch(@event, registry);
return Collection.CreateAsync(@event, headers, s => { UpdateSchema(s, schema); SimpleMapper.Map(@event, s); }); return Collection.CreateAsync(@event, headers, s => { UpdateSchema(s, schema); SimpleMapper.Map(@event, s); });
} }

2
src/Squidex.Read/Contents/Builders/EdmModelBuilder.cs

@ -26,7 +26,7 @@ namespace Squidex.Read.Contents.Builders
{ {
} }
public IEdmModel BuildEdmModel(ISchemaEntityWithSchema schemaEntity, IAppEntity app) public IEdmModel BuildEdmModel(ISchemaEntity schemaEntity, IAppEntity app)
{ {
Guard.NotNull(schemaEntity, nameof(schemaEntity)); Guard.NotNull(schemaEntity, nameof(schemaEntity));

6
src/Squidex.Read/Schemas/ISchemaEntity.cs

@ -6,16 +6,18 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using Squidex.Core.Schemas;
namespace Squidex.Read.Schemas namespace Squidex.Read.Schemas
{ {
public interface ISchemaEntity : IAppRefEntity, IEntityWithCreatedBy, IEntityWithLastModifiedBy, IEntityWithVersion public interface ISchemaEntity : IAppRefEntity, IEntityWithCreatedBy, IEntityWithLastModifiedBy, IEntityWithVersion
{ {
string Name { get; } string Name { get; }
string Label { get; }
bool IsPublished { get; } bool IsPublished { get; }
bool IsDeleted { get; } bool IsDeleted { get; }
Schema Schema { get; }
} }
} }

17
src/Squidex.Read/Schemas/ISchemaEntityWithSchema.cs

@ -1,17 +0,0 @@
// ==========================================================================
// ISchemaEntityWithSchema.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using Squidex.Core.Schemas;
namespace Squidex.Read.Schemas
{
public interface ISchemaEntityWithSchema : ISchemaEntity
{
Schema Schema { get; }
}
}

6
src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs

@ -16,10 +16,8 @@ namespace Squidex.Read.Schemas.Repositories
{ {
Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId); Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId);
Task<IReadOnlyList<ISchemaEntityWithSchema>> QueryAllWithSchemaAsync(Guid appId); Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name);
Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid appId, string name); Task<ISchemaEntity> FindSchemaAsync(Guid schemaId);
Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid schemaId);
} }
} }

4
src/Squidex.Read/Schemas/Services/ISchemaProvider.cs

@ -13,8 +13,8 @@ namespace Squidex.Read.Schemas.Services
{ {
public interface ISchemaProvider public interface ISchemaProvider
{ {
Task<ISchemaEntityWithSchema> FindSchemaByIdAsync(Guid id, bool provideDeleted = false); Task<ISchemaEntity> FindSchemaByIdAsync(Guid id, bool provideDeleted = false);
Task<ISchemaEntityWithSchema> FindSchemaByNameAsync(Guid appId, string name); Task<ISchemaEntity> FindSchemaByNameAsync(Guid appId, string name);
} }
} }

8
src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs

@ -45,11 +45,11 @@ namespace Squidex.Read.Schemas.Services.Implementations
this.repository = repository; this.repository = repository;
} }
public async Task<ISchemaEntityWithSchema> FindSchemaByIdAsync(Guid id, bool provideDeleted = false) public async Task<ISchemaEntity> FindSchemaByIdAsync(Guid id, bool provideDeleted = false)
{ {
var cacheKey = BuildIdCacheKey(id); var cacheKey = BuildIdCacheKey(id);
if (!Cache.TryGetValue(cacheKey, out ISchemaEntityWithSchema result)) if (!Cache.TryGetValue(cacheKey, out ISchemaEntity result))
{ {
result = await repository.FindSchemaAsync(id); result = await repository.FindSchemaAsync(id);
@ -69,13 +69,13 @@ namespace Squidex.Read.Schemas.Services.Implementations
return result; return result;
} }
public async Task<ISchemaEntityWithSchema> FindSchemaByNameAsync(Guid appId, string name) public async Task<ISchemaEntity> FindSchemaByNameAsync(Guid appId, string name)
{ {
Guard.NotNullOrEmpty(name, nameof(name)); Guard.NotNullOrEmpty(name, nameof(name));
var cacheKey = BuildNameCacheKey(appId, name); var cacheKey = BuildNameCacheKey(appId, name);
if (!Cache.TryGetValue(cacheKey, out ISchemaEntityWithSchema result)) if (!Cache.TryGetValue(cacheKey, out ISchemaEntity result))
{ {
result = await repository.FindSchemaAsync(appId, name); result = await repository.FindSchemaAsync(appId, name);

36
src/Squidex.Write/Schemas/Commands/CreateSchema.cs

@ -18,13 +18,36 @@ namespace Squidex.Write.Schemas.Commands
{ {
public class CreateSchema : AppCommand, IValidatable, IAggregateCommand public class CreateSchema : AppCommand, IValidatable, IAggregateCommand
{ {
private SchemaProperties properties;
private SchemaFields fields;
public Guid SchemaId { get; set; } public Guid SchemaId { get; set; }
public string Name { get; set; } public SchemaProperties Properties
{
get
{
return properties ?? (properties = new SchemaProperties());
}
set
{
properties = value;
}
}
public SchemaFields Fields { get; set; } = new SchemaFields(); public SchemaFields Fields
{
get
{
return fields ?? (fields = new SchemaFields());
}
set
{
fields = value;
}
}
public SchemaProperties Properties { get; set; } public string Name { get; set; }
Guid IAggregateCommand.AggregateId Guid IAggregateCommand.AggregateId
{ {
@ -47,6 +70,13 @@ namespace Squidex.Write.Schemas.Commands
{ {
errors.Add(new ValidationError("Properties must be specified", nameof(Properties))); errors.Add(new ValidationError("Properties must be specified", nameof(Properties)));
} }
var index = 0;
foreach (var field in Fields)
{
field.Validate(index++, errors);
}
} }
} }
} }

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

@ -16,6 +16,7 @@ using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.Dispatching; using Squidex.Infrastructure.Dispatching;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Write.Schemas.Commands; using Squidex.Write.Schemas.Commands;
using System.Collections.Generic;
namespace Squidex.Write.Schemas namespace Squidex.Write.Schemas
{ {
@ -53,7 +54,7 @@ namespace Squidex.Write.Schemas
protected void On(SchemaCreated @event) protected void On(SchemaCreated @event)
{ {
schema = SchemaEventDispatcher.Dispatch(@event); schema = SchemaEventDispatcher.Dispatch(@event, registry);
} }
protected void On(FieldUpdated @event) protected void On(FieldUpdated @event)
@ -111,35 +112,49 @@ namespace Squidex.Write.Schemas
isDeleted = true; isDeleted = true;
} }
public SchemaDomainObject AddField(AddField command) public SchemaDomainObject Create(CreateSchema command)
{ {
Guard.Valid(command, nameof(command), () => $"Cannot add field to schema {Id}"); Guard.Valid(command, nameof(command), () => "Cannot create schema");
VerifyCreatedAndNotDeleted(); VerifyNotCreated();
RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = new NamedId<long>(totalFields + 1, command.Name) })); var @event = SimpleMapper.Map(command, new SchemaCreated { SchemaId = new NamedId<Guid>(Id, command.Name) });
if (command.Fields != null)
{
@event.Fields = new List<SchemaCreatedField>();
foreach (var commandField in command.Fields)
{
var eventField = SimpleMapper.Map(commandField, new SchemaCreatedField());
@event.Fields.Add(eventField);
}
}
RaiseEvent(@event);
return this; return this;
} }
public SchemaDomainObject UpdateField(UpdateField command) public SchemaDomainObject AddField(AddField command)
{ {
Guard.Valid(command, nameof(command), () => $"Cannot update schema '{Id}'"); Guard.Valid(command, nameof(command), () => $"Cannot add field to schema {Id}");
VerifyCreatedAndNotDeleted(); VerifyCreatedAndNotDeleted();
RaiseEvent(command, SimpleMapper.Map(command, new FieldUpdated())); RaiseEvent(SimpleMapper.Map(command, new FieldAdded { FieldId = new NamedId<long>(totalFields + 1, command.Name) }));
return this; return this;
} }
public SchemaDomainObject Create(CreateSchema command) public SchemaDomainObject UpdateField(UpdateField command)
{ {
Guard.Valid(command, nameof(command), () => "Cannot create schema"); Guard.Valid(command, nameof(command), () => $"Cannot update schema '{Id}'");
VerifyNotCreated(); VerifyCreatedAndNotDeleted();
RaiseEvent(SimpleMapper.Map(command, new SchemaCreated { SchemaId = new NamedId<Guid>(Id, command.Name) })); RaiseEvent(command, SimpleMapper.Map(command, new FieldUpdated()));
return this; return this;
} }

45
src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs

@ -12,6 +12,9 @@ using System.Linq;
using Squidex.Core.Schemas; using Squidex.Core.Schemas;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Read.Schemas; using Squidex.Read.Schemas;
using Squidex.Write.Schemas.Commands;
// ReSharper disable InvertIf
namespace Squidex.Controllers.Api.Schemas.Models.Converters namespace Squidex.Controllers.Api.Schemas.Models.Converters
{ {
@ -49,13 +52,24 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters
} }
}; };
public static SchemaDetailsDto ToModel(this ISchemaEntityWithSchema entity) public static SchemaDto ToModel(this ISchemaEntity entity)
{ {
var dto = new SchemaDetailsDto(); var dto = new SchemaDto { Properties = new SchemaPropertiesDto() };
SimpleMapper.Map(entity, dto); SimpleMapper.Map(entity, dto);
SimpleMapper.Map(entity.Schema, dto); SimpleMapper.Map(entity.Schema, dto);
SimpleMapper.Map(entity.Schema.Properties, dto); SimpleMapper.Map(entity.Schema.Properties, dto.Properties);
return dto;
}
public static SchemaDetailsDto ToDetailsModel(this ISchemaEntity entity)
{
var dto = new SchemaDetailsDto { Properties = new SchemaPropertiesDto() };
SimpleMapper.Map(entity, dto);
SimpleMapper.Map(entity.Schema, dto);
SimpleMapper.Map(entity.Schema.Properties, dto.Properties);
dto.Fields = new List<FieldDto>(); dto.Fields = new List<FieldDto>();
@ -76,6 +90,31 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters
return dto; return dto;
} }
public static CreateSchema ToCommand(this CreateSchemaDto dto)
{
var command = new CreateSchema();
SimpleMapper.Map(dto, command);
if (dto.Properties != null)
{
SimpleMapper.Map(dto.Properties, command.Properties);
}
if (dto.Fields != null)
{
foreach (var fieldDto in dto.Fields)
{
var fieldProperties = fieldDto?.Properties.ToProperties();
var fieldInstance = SimpleMapper.Map(fieldDto, new CreateSchemaField { Properties = fieldProperties });
command.Fields.Add(fieldInstance);
}
}
return command;
}
private static FieldPropertiesDto Convert(BooleanFieldProperties source) private static FieldPropertiesDto Convert(BooleanFieldProperties source)
{ {
var result = SimpleMapper.Map(source, new BooleanFieldPropertiesDto()); var result = SimpleMapper.Map(source, new BooleanFieldPropertiesDto());

11
src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs

@ -6,6 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Schemas.Models namespace Squidex.Controllers.Api.Schemas.Models
@ -18,5 +19,15 @@ namespace Squidex.Controllers.Api.Schemas.Models
[Required] [Required]
[RegularExpression("^[a-z0-9]+(\\-[a-z0-9]+)*$")] [RegularExpression("^[a-z0-9]+(\\-[a-z0-9]+)*$")]
public string Name { get; set; } public string Name { get; set; }
/// <summary>
/// The optional properties.
/// </summary>
public SchemaPropertiesDto Properties { get; set; }
/// <summary>
/// Optional fields.
/// </summary>
public List<CreateSchemaFieldDto> Fields { get; set; }
} }
} }

44
src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaFieldDto.cs

@ -0,0 +1,44 @@
// ==========================================================================
// CreateSchemaFieldDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Schemas.Models
{
public sealed class CreateSchemaFieldDto
{
/// <summary>
/// The name of the field. Must be unique within the schema.
/// </summary>
[Required]
[RegularExpression("^[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*$")]
public string Name { get; set; }
/// <summary>
/// Defines if the field is hidden.
/// </summary>
public bool IsHidden { get; set; }
/// <summary>
/// Defines if the field is disabled.
/// </summary>
public bool IsDisabled { get; set; }
/// <summary>
/// Determines the optional partitioning of the field.
/// </summary>
public string Partitioning { get; set; }
/// <summary>
/// The field properties.
/// </summary>
[Required]
public FieldPropertiesDto Properties { get; set; }
}
}

12
src/Squidex/Controllers/Api/Schemas/Models/SchemaDetailsDto.cs

@ -40,16 +40,10 @@ namespace Squidex.Controllers.Api.Schemas.Models
public List<FieldDto> Fields { get; set; } public List<FieldDto> Fields { get; set; }
/// <summary> /// <summary>
/// Optional label for the editor. /// The schema properties.
/// </summary> /// </summary>
[StringLength(100)] [Required]
public string Label { get; set; } public SchemaPropertiesDto Properties { get; set; }
/// <summary>
/// Hints to describe the schema.
/// </summary>
[StringLength(1000)]
public string Hints { get; set; }
/// <summary> /// <summary>
/// The user that has created the schema. /// The user that has created the schema.

6
src/Squidex/Controllers/Api/Schemas/Models/SchemaDto.cs

@ -28,10 +28,10 @@ namespace Squidex.Controllers.Api.Schemas.Models
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// Optional label for the editor. /// The schema properties.
/// </summary> /// </summary>
[StringLength(100)] [Required]
public string Label { get; set; } public SchemaPropertiesDto Properties { get; set; }
/// <summary> /// <summary>
/// Indicates if the schema is published. /// Indicates if the schema is published.

27
src/Squidex/Controllers/Api/Schemas/Models/SchemaPropertiesDto.cs

@ -0,0 +1,27 @@
// ==========================================================================
// SchemaPropertiesDto.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.ComponentModel.DataAnnotations;
namespace Squidex.Controllers.Api.Schemas.Models
{
public class SchemaPropertiesDto
{
/// <summary>
/// Optional label for the editor.
/// </summary>
[StringLength(100)]
public string Label { get; set; }
/// <summary>
/// Hints to describe the schema.
/// </summary>
[StringLength(1000)]
public string Hints { get; set; }
}
}

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

@ -55,7 +55,7 @@ namespace Squidex.Controllers.Api.Schemas
{ {
var schemas = await schemaRepository.QueryAllAsync(AppId); var schemas = await schemaRepository.QueryAllAsync(AppId);
var model = schemas.Select(s => SimpleMapper.Map(s, new SchemaDto())).ToList(); var model = schemas.Select(s => s.ToModel()).ToList();
return Ok(model); return Ok(model);
} }
@ -82,7 +82,7 @@ namespace Squidex.Controllers.Api.Schemas
return NotFound(); return NotFound();
} }
var model = entity.ToModel(); var model = entity.ToDetailsModel();
Response.Headers["ETag"] = new StringValues(entity.Version.ToString()); Response.Headers["ETag"] = new StringValues(entity.Version.ToString());
@ -107,7 +107,7 @@ namespace Squidex.Controllers.Api.Schemas
[ApiCosts(1)] [ApiCosts(1)]
public async Task<IActionResult> PostSchema(string app, [FromBody] CreateSchemaDto request) public async Task<IActionResult> PostSchema(string app, [FromBody] CreateSchemaDto request)
{ {
var command = SimpleMapper.Map(request, new CreateSchema()); var command = request.ToCommand();
await CommandBus.PublishAsync(command); await CommandBus.PublishAsync(command);

2
src/Squidex/Controllers/ContentApi/ContentSwaggerController.cs

@ -56,7 +56,7 @@ namespace Squidex.Controllers.ContentApi
return NotFound(); return NotFound();
} }
var schemas = await schemaRepository.QueryAllWithSchemaAsync(appEntity.Id); var schemas = await schemaRepository.QueryAllAsync(appEntity.Id);
var swaggerDocument = await schemasSwaggerGenerator.Generate(appEntity, schemas); var swaggerDocument = await schemasSwaggerGenerator.Generate(appEntity, schemas);

4
src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs

@ -61,7 +61,7 @@ namespace Squidex.Controllers.ContentApi.Generator
schemaQueryDescription = SwaggerHelper.LoadDocs("schemaquery"); schemaQueryDescription = SwaggerHelper.LoadDocs("schemaquery");
} }
public async Task<SwaggerDocument> Generate(IAppEntity targetApp, IEnumerable<ISchemaEntityWithSchema> schemas) public async Task<SwaggerDocument> Generate(IAppEntity targetApp, IEnumerable<ISchemaEntity> schemas)
{ {
app = targetApp; app = targetApp;
@ -159,7 +159,7 @@ namespace Squidex.Controllers.ContentApi.Generator
} }
} }
private void GenerateSchemasOperations(IEnumerable<ISchemaEntityWithSchema> schemas) private void GenerateSchemasOperations(IEnumerable<ISchemaEntity> schemas)
{ {
foreach (var schema in schemas.Where(x => x.IsPublished).Select(x => x.Schema)) foreach (var schema in schemas.Where(x => x.IsPublished).Select(x => x.Schema))
{ {

4
src/Squidex/app/features/content/pages/content/content-field.component.html

@ -1,6 +1,6 @@
<div class="table-items-row" [class.invalid]="fieldForm.invalid"> <div class="table-items-row" [class.invalid]="fieldForm.invalid">
<label> <label>
{{field|displayName:'properties.label':'name'}} <span class="field-required" [class.hidden]="!field.properties.isRequired">*</span> {{field | displayName:'properties.label':'name'}} <span class="field-required" [class.hidden]="!field.properties.isRequired">*</span>
</label> </label>
<span class="field-disabled" *ngIf="field.isDisabled">Disabled</span> <span class="field-disabled" *ngIf="field.isDisabled">Disabled</span>
@ -12,7 +12,7 @@
<div *ngFor="let partition of fieldPartitions"> <div *ngFor="let partition of fieldPartitions">
<div *ngIf="partition == fieldPartition"> <div *ngIf="partition == fieldPartition">
<sqx-control-errors [for]="partition" fieldName="{{field|displayName:'properties.label':'name'}}" [submitted]="contentFormSubmitted"></sqx-control-errors> <sqx-control-errors [for]="partition" fieldName="{{field | displayName:'properties.label':'name'}}" [submitted]="contentFormSubmitted"></sqx-control-errors>
<div [ngSwitch]="field.properties.fieldType"> <div [ngSwitch]="field.properties.fieldType">
<div *ngSwitchCase="'Number'"> <div *ngSwitchCase="'Number'">

2
src/Squidex/app/features/content/pages/contents/contents-page.component.html

@ -44,7 +44,7 @@
<thead> <thead>
<tr> <tr>
<th *ngFor="let field of contentFields"> <th *ngFor="let field of contentFields">
<span class="field">{{field|displayName:'properties.label':'name'}}</span> <span class="field">{{field | displayName:'properties.label':'name'}}</span>
</th> </th>
<th> <th>
Updated Updated

2
src/Squidex/app/features/content/pages/schemas/schemas-page.component.html

@ -24,7 +24,7 @@
<ul class="nav nav-pills flex-column nav-dark nav-dark-bordered"> <ul class="nav nav-pills flex-column nav-dark nav-dark-bordered">
<li class="nav-item" *ngFor="let schema of schemasFiltered | async"> <li class="nav-item" *ngFor="let schema of schemasFiltered | async">
<a class="nav-link" [routerLink]="[schema.name]" routerLinkActive="active"> <a class="nav-link" [routerLink]="[schema.name]" routerLinkActive="active">
{{schema|displayName}} {{schema | displayName}}
<i class="icon-angle-right"></i> <i class="icon-angle-right"></i>
</a> </a>
</li> </li>

4
src/Squidex/app/features/schemas/pages/messages.ts

@ -5,10 +5,12 @@
* Copyright (c) Sebastian Stehle. All rights reserved * Copyright (c) Sebastian Stehle. All rights reserved
*/ */
import { SchemaPropertiesDto } from 'shared';
export class SchemaUpdated { export class SchemaUpdated {
constructor( constructor(
public readonly name: string, public readonly name: string,
public readonly label: string, public readonly properties: SchemaPropertiesDto,
public readonly isPublished: boolean, public readonly isPublished: boolean,
public readonly version: string public readonly version: string
) { ) {

2
src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.html

@ -2,7 +2,7 @@
<div class="form-group"> <div class="form-group">
<label for="schema-name">Name</label> <label for="schema-name">Name</label>
<input type="text" class="form-control" id="schema-name" formControlName="name" readonly /> <input type="text" class="form-control" id="schema-name" [attr.value]="name" readonly />
</div> </div>
<div class="form-group"> <div class="form-group">

15
src/Squidex/app/features/schemas/pages/schema/schema-edit-form.component.ts

@ -11,12 +11,11 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { import {
Notification, Notification,
NotificationService, NotificationService,
SchemaPropertiesDto,
SchemasService, SchemasService,
Version Version
} from 'shared'; } from 'shared';
import { SchemaPropertiesDto } from './schema-properties';
@Component({ @Component({
selector: 'sqx-schema-edit-form', selector: 'sqx-schema-edit-form',
styleUrls: ['./schema-edit-form.component.scss'], styleUrls: ['./schema-edit-form.component.scss'],
@ -30,7 +29,10 @@ export class SchemaEditFormComponent implements OnInit {
public cancelled = new EventEmitter(); public cancelled = new EventEmitter();
@Input() @Input()
public schema: SchemaPropertiesDto; public name: string;
@Input()
public properties: SchemaPropertiesDto;
@Input() @Input()
public version: Version; public version: Version;
@ -41,7 +43,6 @@ export class SchemaEditFormComponent implements OnInit {
public editFormSubmitted = false; public editFormSubmitted = false;
public editForm: FormGroup = public editForm: FormGroup =
this.formBuilder.group({ this.formBuilder.group({
name: '',
label: ['', label: ['',
[ [
Validators.maxLength(100) Validators.maxLength(100)
@ -60,7 +61,7 @@ export class SchemaEditFormComponent implements OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.editForm.patchValue(this.schema); this.editForm.patchValue(this.properties);
} }
public cancel() { public cancel() {
@ -76,10 +77,10 @@ export class SchemaEditFormComponent implements OnInit {
const requestDto = this.editForm.value; const requestDto = this.editForm.value;
this.schemas.putSchema(this.appName, this.schema.name, requestDto, this.version) this.schemas.putSchema(this.appName, this.name, requestDto, this.version)
.subscribe(dto => { .subscribe(dto => {
this.reset(); this.reset();
this.saved.emit(new SchemaPropertiesDto(this.schema.name, requestDto.label, requestDto.hints)); this.saved.emit(new SchemaPropertiesDto(requestDto.label, requestDto.hints));
}, error => { }, error => {
this.editForm.enable(); this.editForm.enable();
this.notifications.notify(Notification.error(error.displayMessage)); this.notifications.notify(Notification.error(error.displayMessage));

6
src/Squidex/app/features/schemas/pages/schema/schema-page.component.html

@ -5,7 +5,7 @@
<div class="panel-title-row"> <div class="panel-title-row">
<div class="float-right"> <div class="float-right">
<button type="button" class="btn btn-link btn-sm btn-export" (click)="exportSchemaDialog.show()"> <button type="button" class="btn btn-link btn-sm btn-export" (click)="exportSchemaDialog.show()">
Export JSON
</button> </button>
<div class="btn-group btn-group-sm" data-toggle="buttons"> <div class="btn-group btn-group-sm" data-toggle="buttons">
@ -30,7 +30,7 @@
</div> </div>
<h3 class="panel-title"> <h3 class="panel-title">
{{schemaProperties|displayName}} <i class="schema-edit icon-pencil" (click)="editSchemaDialog.show()"></i> {{schemaInformation | displayName}} <i class="schema-edit icon-pencil" (click)="editSchemaDialog.show()"></i>
</h3> </h3>
</div> </div>
@ -132,7 +132,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<sqx-schema-edit-form [appName]="appName() | async" [schema]="schemaProperties" [version]="schemaVersion" (saved)="onSchemaSaved($event)" (cancelled)="editSchemaDialog.hide()"></sqx-schema-edit-form> <sqx-schema-edit-form [appName]="appName() | async" [name]="schemaName" [properties]="schemaProperties" [version]="schemaVersion" (saved)="onSchemaSaved($event)" (cancelled)="editSchemaDialog.hide()"></sqx-schema-edit-form>
</div> </div>
</div> </div>
</div> </div>

20
src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

@ -22,13 +22,13 @@ import {
ModalView, ModalView,
NotificationService, NotificationService,
SchemaDetailsDto, SchemaDetailsDto,
SchemaPropertiesDto,
SchemasService, SchemasService,
UpdateFieldDto, UpdateFieldDto,
ValidatorsEx, ValidatorsEx,
Version Version
} from 'shared'; } from 'shared';
import { SchemaPropertiesDto } from './schema-properties';
import { SchemaDeleted, SchemaUpdated } from './../messages'; import { SchemaDeleted, SchemaUpdated } from './../messages';
@Component({ @Component({
@ -51,10 +51,11 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
]; ];
public schemaExport: any; public schemaExport: any;
public schemaFields = ImmutableArray.empty<FieldDto>();
public schemaName: string; public schemaName: string;
public schemaProperties: SchemaPropertiesDto; public schemaFields = ImmutableArray.empty<FieldDto>();
public schemaVersion = new Version(''); public schemaVersion = new Version('');
public schemaProperties: SchemaPropertiesDto;
public schemaInformation: any;
public confirmDeleteDialog = new ModalView(); public confirmDeleteDialog = new ModalView();
@ -99,8 +100,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
.subscribe((schema: SchemaDetailsDto) => { .subscribe((schema: SchemaDetailsDto) => {
this.schemaName = schema.name; this.schemaName = schema.name;
this.schemaFields = ImmutableArray.of(schema.fields); this.schemaFields = ImmutableArray.of(schema.fields);
this.schemaProperties = new SchemaPropertiesDto(schema.name, schema.label, schema.hints);
this.schemaVersion = schema.version; this.schemaVersion = schema.version;
this.schemaProperties = schema.properties;
this.schemaInformation = { properties: schema.properties, name: schema.name };
this.isPublished = schema.isPublished; this.isPublished = schema.isPublished;
@ -269,6 +271,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
private updateProperties(properties: SchemaPropertiesDto) { private updateProperties(properties: SchemaPropertiesDto) {
this.schemaProperties = properties; this.schemaProperties = properties;
this.schemaInformation = { properties: properties, name: this.schemaName };
this.notify(); this.notify();
this.export(); this.export();
@ -304,15 +307,16 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
} }
return copy; return copy;
}) }),
properties: {}
}; };
if (this.schemaProperties.label) { if (this.schemaProperties.label) {
result.label = this.schemaProperties.label; result.properties.label = this.schemaProperties.label;
} }
if (this.schemaProperties.hints) { if (this.schemaProperties.hints) {
result.hints = this.schemaProperties.hints; result.properties.hints = this.schemaProperties.hints;
} }
this.schemaExport = result; this.schemaExport = result;
@ -320,7 +324,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
private notify() { private notify() {
this.messageBus.publish(new HistoryChannelUpdated()); this.messageBus.publish(new HistoryChannelUpdated());
this.messageBus.publish(new SchemaUpdated(this.schemaName, this.schemaProperties.label, this.isPublished, this.schemaVersion.value)); this.messageBus.publish(new SchemaUpdated(this.schemaName, this.schemaProperties, this.isPublished, this.schemaVersion.value));
} }
} }

15
src/Squidex/app/features/schemas/pages/schema/schema-properties.ts

@ -1,15 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
export class SchemaPropertiesDto {
constructor(
public readonly name: string,
public readonly label: string,
public readonly hints: string
) {
}
}

11
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html

@ -20,6 +20,17 @@
</span> </span>
</div> </div>
<div>
<button class="btn btn-sm btn-link" (click)="toggleImport()" [class.hidden]="showImport">
Import schema
</button>
<button class="btn btn-sm btn-link" (click)="toggleImport()" [class.hidden]="!showImport">
Hide
</button>
<sqx-json-editor *ngIf="showImport" formControlName="import"></sqx-json-editor>
</div>
<div class="form-group clearfix"> <div class="form-group clearfix">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button> <button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button>
<button type="submit" class="float-right btn btn-success">Create</button> <button type="submit" class="float-right btn btn-success">Create</button>

13
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.scss

@ -1,2 +1,13 @@
@import '_vars'; @import '_vars';
@import '_mixins'; @import '_mixins';
.btn-link {
margin-top: -1rem;
margin-left: -.5rem;
}
:host /deep/ .editor {
height: 15rem !important;
margin-bottom: .5rem;
margin-top: 0;
}

23
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts

@ -11,10 +11,10 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { import {
ApiUrlConfig, ApiUrlConfig,
AuthService, AuthService,
CreateSchemaDto,
DateTime, DateTime,
fadeAnimation, fadeAnimation,
SchemaDto, SchemaDto,
SchemaPropertiesDto,
SchemasService, SchemasService,
ValidatorsEx, ValidatorsEx,
Version Version
@ -40,6 +40,8 @@ export class SchemaFormComponent {
@Output() @Output()
public cancelled = new EventEmitter(); public cancelled = new EventEmitter();
public showImport = false;
public creationError = ''; public creationError = '';
public createFormSubmitted = false; public createFormSubmitted = false;
public createForm: FormGroup = public createForm: FormGroup =
@ -49,7 +51,8 @@ export class SchemaFormComponent {
Validators.required, Validators.required,
Validators.maxLength(40), Validators.maxLength(40),
ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes only (not at the end).') ValidatorsEx.pattern('[a-z0-9]+(\-[a-z0-9]+)*', 'Name can contain lower case letters (a-z), numbers and dashes only (not at the end).')
]] ]],
import: [{}]
}); });
public schemaName = public schemaName =
@ -64,6 +67,12 @@ export class SchemaFormComponent {
) { ) {
} }
public toggleImport() {
this.showImport = !this.showImport;
return false;
}
public cancel() { public cancel() {
this.reset(); this.reset();
this.cancelled.emit(); this.cancelled.emit();
@ -78,12 +87,14 @@ export class SchemaFormComponent {
const schemaVersion = new Version(); const schemaVersion = new Version();
const schemaName = this.createForm.get('name')!.value; const schemaName = this.createForm.get('name')!.value;
const requestDto = new CreateSchemaDto(schemaName); const requestDto = Object.assign(this.createForm.get('import')!.value || {}, {});
requestDto.name = schemaName;
this.schemas.postSchema(this.appName, requestDto, schemaVersion) this.schemas.postSchema(this.appName, requestDto, schemaVersion)
.subscribe(dto => { .subscribe(dto => {
this.reset(); this.reset();
this.created.emit(this.createSchemaDto(dto.id, schemaName, schemaVersion)); this.created.emit(this.createSchemaDto(dto.id, requestDto.properties || {}, schemaName, schemaVersion));
}, error => { }, error => {
this.createForm.enable(); this.createForm.enable();
this.creationError = error.displayMessage; this.creationError = error.displayMessage;
@ -97,10 +108,10 @@ export class SchemaFormComponent {
this.createFormSubmitted = false; this.createFormSubmitted = false;
} }
private createSchemaDto(id: string, name: string, version: Version) { private createSchemaDto(id: string, properties: SchemaPropertiesDto, name: string, version: Version) {
const user = this.authService.user!.token; const user = this.authService.user!.token;
const now = DateTime.now(); const now = DateTime.now();
return new SchemaDto(id, name, null, false, user, user, now, now, version); return new SchemaDto(id, name, properties, false, user, user, now, now, version);
} }
} }

2
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html

@ -30,7 +30,7 @@
<a class="nav-link" [routerLink]="[schema.name]" routerLinkActive="active"> <a class="nav-link" [routerLink]="[schema.name]" routerLinkActive="active">
<div class="row"> <div class="row">
<div class="col col-4"> <div class="col col-4">
<span class="schema-name">{{schema|displayName}}</span> <span class="schema-name">{{schema | displayName:'properties.label':'name'}}</span>
</div> </div>
<div class="col col-4"> <div class="col col-4">
<span class="schema-user"> <span class="schema-user">

2
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -136,7 +136,7 @@ function updateSchema(schema: SchemaDto, authService: AuthService, message: Sche
return new SchemaDto( return new SchemaDto(
schema.id, schema.id,
schema.name, schema.name,
message.label, message.properties,
message.isPublished, message.isPublished,
schema.createdBy, me, schema.createdBy, me,
schema.created, DateTime.now(), schema.created, DateTime.now(),

23
src/Squidex/app/shared/services/schemas.service.spec.ts

@ -20,6 +20,7 @@ import {
FieldDto, FieldDto,
SchemaDetailsDto, SchemaDetailsDto,
SchemaDto, SchemaDto,
SchemaPropertiesDto,
SchemasService, SchemasService,
UpdateFieldDto, UpdateFieldDto,
UpdateSchemaDto, UpdateSchemaDto,
@ -49,7 +50,10 @@ describe('SchemasService', () => {
{ {
id: 'id1', id: 'id1',
name: 'name1', name: 'name1',
label: 'label1', properties: {
label: 'label1',
hints: 'hints1'
},
isPublished: true, isPublished: true,
created: '2016-12-12T10:10', created: '2016-12-12T10:10',
createdBy: 'Created1', createdBy: 'Created1',
@ -61,7 +65,10 @@ describe('SchemasService', () => {
{ {
id: 'id2', id: 'id2',
name: 'name2', name: 'name2',
label: 'label2', properties: {
label: 'label2',
hints: 'hints2'
},
isPublished: true, isPublished: true,
created: '2016-10-12T10:10', created: '2016-10-12T10:10',
createdBy: 'Created2', createdBy: 'Created2',
@ -83,11 +90,11 @@ describe('SchemasService', () => {
}).unsubscribe(); }).unsubscribe();
expect(schemas).toEqual([ expect(schemas).toEqual([
new SchemaDto('id1', 'name1', 'label1', true, 'Created1', 'LastModifiedBy1', new SchemaDto('id1', 'name1', new SchemaPropertiesDto('label1', 'hints1'), true, 'Created1', 'LastModifiedBy1',
DateTime.parseISO_UTC('2016-12-12T10:10'), DateTime.parseISO_UTC('2016-12-12T10:10'),
DateTime.parseISO_UTC('2017-12-12T10:10'), DateTime.parseISO_UTC('2017-12-12T10:10'),
new Version('11')), new Version('11')),
new SchemaDto('id2', 'name2', 'label2', true, 'Created2', 'LastModifiedBy2', new SchemaDto('id2', 'name2', new SchemaPropertiesDto('label2', 'hints2'), true, 'Created2', 'LastModifiedBy2',
DateTime.parseISO_UTC('2016-10-12T10:10'), DateTime.parseISO_UTC('2016-10-12T10:10'),
DateTime.parseISO_UTC('2017-10-12T10:10'), DateTime.parseISO_UTC('2017-10-12T10:10'),
new Version('22')) new Version('22'))
@ -104,8 +111,10 @@ describe('SchemasService', () => {
body: { body: {
id: 'id1', id: 'id1',
name: 'name1', name: 'name1',
label: 'label1', properties: {
hints: 'hints1', label: 'label1',
hints: 'hints1'
},
isPublished: true, isPublished: true,
created: '2016-12-12T10:10', created: '2016-12-12T10:10',
createdBy: 'Created1', createdBy: 'Created1',
@ -197,7 +206,7 @@ describe('SchemasService', () => {
}).unsubscribe(); }).unsubscribe();
expect(schema).toEqual( expect(schema).toEqual(
new SchemaDetailsDto('id1', 'name1', 'label1', 'hints1', true, 'Created1', 'LastModifiedBy1', new SchemaDetailsDto('id1', 'name1', new SchemaPropertiesDto('label1', 'hints1'), true, 'Created1', 'LastModifiedBy1',
DateTime.parseISO_UTC('2016-12-12T10:10'), DateTime.parseISO_UTC('2016-12-12T10:10'),
DateTime.parseISO_UTC('2017-12-12T10:10'), DateTime.parseISO_UTC('2017-12-12T10:10'),
new Version('11'), new Version('11'),

24
src/Squidex/app/shared/services/schemas.service.ts

@ -59,7 +59,7 @@ export class SchemaDto {
constructor( constructor(
public readonly id: string, public readonly id: string,
public readonly name: string, public readonly name: string,
public readonly label: string | null, public readonly properties: SchemaPropertiesDto,
public readonly isPublished: boolean, public readonly isPublished: boolean,
public readonly createdBy: string, public readonly createdBy: string,
public readonly lastModifiedBy: string, public readonly lastModifiedBy: string,
@ -74,8 +74,7 @@ export class SchemaDetailsDto {
constructor( constructor(
public readonly id: string, public readonly id: string,
public readonly name: string, public readonly name: string,
public readonly label: string, public readonly properties: SchemaPropertiesDto,
public readonly hints: string,
public readonly isPublished: boolean, public readonly isPublished: boolean,
public readonly createdBy: string, public readonly createdBy: string,
public readonly lastModifiedBy: string, public readonly lastModifiedBy: string,
@ -194,6 +193,14 @@ export class JsonFieldPropertiesDto extends FieldPropertiesDto {
} }
} }
export class SchemaPropertiesDto {
constructor(
public readonly label: string,
public readonly hints: string
) {
}
}
export class UpdateSchemaDto { export class UpdateSchemaDto {
constructor( constructor(
public readonly label?: string, public readonly label?: string,
@ -242,10 +249,11 @@ export class SchemasService {
const items: any[] = response; const items: any[] = response;
return items.map(item => { return items.map(item => {
const properties = new SchemaPropertiesDto(item.properties.label, item.properties.hints);
return new SchemaDto( return new SchemaDto(
item.id, item.id,
item.name, item.name, properties,
item.label,
item.isPublished, item.isPublished,
item.createdBy, item.createdBy,
item.lastModifiedBy, item.lastModifiedBy,
@ -278,11 +286,11 @@ export class SchemasService {
propertiesDto); propertiesDto);
}); });
const properties = new SchemaPropertiesDto(response.properties.label, response.properties.hints);
return new SchemaDetailsDto( return new SchemaDetailsDto(
response.id, response.id,
response.name, response.name, properties,
response.label,
response.hints,
response.isPublished, response.isPublished,
response.createdBy, response.createdBy,
response.lastModifiedBy, response.lastModifiedBy,

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

@ -33,7 +33,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_creating_field_and_field_is_not_registered() public void Should_throw_exception_if_creating_field_and_field_is_not_registered()
{ {
Assert.Throws<InvalidOperationException>(() => sut.CreateField(1, "name", Partitioning.Invariant, new InvalidProperties())); Assert.Throws<InvalidOperationException>(() => sut.CreateField(1, "name", Partitioning.Invariant, new InvalidProperties()));
} }

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

@ -47,7 +47,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_creating_schema_with_invalid_name() public void Should_throw_exception_if_creating_schema_with_invalid_name()
{ {
Assert.Throws<ValidationException>(() => Schema.Create("Invalid Name", new SchemaProperties())); Assert.Throws<ValidationException>(() => Schema.Create("Invalid Name", new SchemaProperties()));
} }
@ -71,7 +71,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_adding_field_with_name_that_already_exists() public void Should_throw_exception_if_adding_field_with_name_that_already_exists()
{ {
AddField(); AddField();
@ -90,7 +90,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_hide_does_not_exist() public void Should_throw_exception_if_field_to_hide_does_not_exist()
{ {
Assert.Throws<DomainObjectNotFoundException>(() => sut.HideField(1)); Assert.Throws<DomainObjectNotFoundException>(() => sut.HideField(1));
} }
@ -108,7 +108,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_show_does_not_exist() public void Should_throw_exception_if_field_to_show_does_not_exist()
{ {
Assert.Throws<DomainObjectNotFoundException>(() => sut.ShowField(2)); Assert.Throws<DomainObjectNotFoundException>(() => sut.ShowField(2));
} }
@ -125,7 +125,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_disable_does_not_exist() public void Should_throw_exception_if_field_to_disable_does_not_exist()
{ {
Assert.Throws<DomainObjectNotFoundException>(() => sut.DisableField(1)); Assert.Throws<DomainObjectNotFoundException>(() => sut.DisableField(1));
} }
@ -143,7 +143,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_enable_does_not_exist() public void Should_throw_exception_if_field_to_enable_does_not_exist()
{ {
Assert.Throws<DomainObjectNotFoundException>(() => sut.EnableField(1)); Assert.Throws<DomainObjectNotFoundException>(() => sut.EnableField(1));
} }
@ -159,7 +159,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_new_field_already_exists() public void Should_throw_exception_if_new_field_already_exists()
{ {
AddField(); AddField();
@ -169,7 +169,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_new_field_name_is_not_valid() public void Should_throw_exception_if_new_field_name_is_not_valid()
{ {
AddField(); AddField();
@ -177,7 +177,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_rename_does_not_exist() public void Should_throw_exception_if_field_to_rename_does_not_exist()
{ {
Assert.Throws<DomainObjectNotFoundException>(() => sut.RenameField(1, "new-name")); Assert.Throws<DomainObjectNotFoundException>(() => sut.RenameField(1, "new-name"));
} }
@ -193,7 +193,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_not_throw_if_field_to_delete_does_not_exist() public void Should_not_throw_exception_if_field_to_delete_does_not_exist()
{ {
sut.DeleteField(1); sut.DeleteField(1);
} }
@ -209,7 +209,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_updating_field_with_invalid_property_type() public void Should_throw_exception_if_updating_field_with_invalid_property_type()
{ {
AddField(); AddField();
@ -217,7 +217,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_update_does_not_exist() public void Should_throw_exception_if_field_to_update_does_not_exist()
{ {
Assert.Throws<DomainObjectNotFoundException>(() => sut.UpdateField(1, new NumberFieldProperties())); Assert.Throws<DomainObjectNotFoundException>(() => sut.UpdateField(1, new NumberFieldProperties()));
} }
@ -231,7 +231,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_schema_is_already_published() public void Should_throw_exception_if_schema_is_already_published()
{ {
sut = sut.Publish(); sut = sut.Publish();
@ -248,7 +248,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_schema_is_not_published() public void Should_throw_exception_if_schema_is_not_published()
{ {
Assert.Throws<DomainException>(() => sut.Unpublish()); Assert.Throws<DomainException>(() => sut.Unpublish());
} }
@ -269,7 +269,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_not_all_fields_are_covered_for_reordering() public void Should_throw_exception_if_not_all_fields_are_covered_for_reordering()
{ {
var field1 = new StringField(1, "1", Partitioning.Invariant); var field1 = new StringField(1, "1", Partitioning.Invariant);
var field2 = new StringField(2, "2", Partitioning.Invariant); var field2 = new StringField(2, "2", Partitioning.Invariant);
@ -281,7 +281,7 @@ namespace Squidex.Core.Schemas
} }
[Fact] [Fact]
public void Should_throw_if_field_to_reorder_does_not_exist() public void Should_throw_exception_if_field_to_reorder_does_not_exist()
{ {
var field1 = new StringField(1, "1", Partitioning.Invariant); var field1 = new StringField(1, "1", Partitioning.Invariant);
var field2 = new StringField(2, "2", Partitioning.Invariant); var field2 = new StringField(2, "2", Partitioning.Invariant);

4
tests/Squidex.Infrastructure.Tests/CQRS/Commands/AggregateHandlerTests.cs

@ -83,7 +83,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
} }
[Fact] [Fact]
public Task Create_async_should_throw_if_not_aggregate_command() public Task Create_async_should_throw_exception_if_not_aggregate_command()
{ {
return Assert.ThrowsAnyAsync<ArgumentException>(() => sut.CreateAsync<MyDomainObject>(new CommandContext(new Mock<ICommand>().Object), x => TaskHelper.False)); return Assert.ThrowsAnyAsync<ArgumentException>(() => sut.CreateAsync<MyDomainObject>(new CommandContext(new Mock<ICommand>().Object), x => TaskHelper.False));
} }
@ -139,7 +139,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
} }
[Fact] [Fact]
public Task Update_async_should_throw_if_not_aggregate_command() public Task Update_async_should_throw_exception_if_not_aggregate_command()
{ {
return Assert.ThrowsAnyAsync<ArgumentException>(() => sut.UpdateAsync<MyDomainObject>(new CommandContext(new Mock<ICommand>().Object), x => TaskHelper.False)); return Assert.ThrowsAnyAsync<ArgumentException>(() => sut.UpdateAsync<MyDomainObject>(new CommandContext(new Mock<ICommand>().Object), x => TaskHelper.False));
} }

2
tests/Squidex.Infrastructure.Tests/CQRS/Commands/DefaultDomainObjectFactoryTests.cs

@ -52,7 +52,7 @@ namespace Squidex.Infrastructure.CQRS.Commands
} }
[Fact] [Fact]
public void Should_throw_if_new_entity_has_invalid_version() public void Should_throw_exception_if_new_entity_has_invalid_version()
{ {
var serviceProvider = new Mock<IServiceProvider>(); var serviceProvider = new Mock<IServiceProvider>();

4
tests/Squidex.Infrastructure.Tests/GuardTests.cs

@ -347,13 +347,13 @@ namespace Squidex.Infrastructure
} }
[Fact] [Fact]
public void Valid_should_throw_if_null() public void Valid_should_throw_exception_if_null()
{ {
Assert.Throws<ArgumentNullException>(() => Guard.Valid(null, "Parameter", () => "Message")); Assert.Throws<ArgumentNullException>(() => Guard.Valid(null, "Parameter", () => "Message"));
} }
[Fact] [Fact]
public void Valid_should_throw_if_invalid() public void Valid_should_throw_exception_if_invalid()
{ {
Assert.Throws<ValidationException>(() => Guard.Valid(new MyValidatableInvalid(), "Parameter", () => "Message")); Assert.Throws<ValidationException>(() => Guard.Valid(new MyValidatableInvalid(), "Parameter", () => "Message"));
} }

6
tests/Squidex.Infrastructure.Tests/LanguageTests.cs

@ -19,19 +19,19 @@ namespace Squidex.Infrastructure
[Theory] [Theory]
[InlineData("")] [InlineData("")]
[InlineData(" ")] [InlineData(" ")]
public void Should_throw_if_getting_by_empty_key(string key) public void Should_throw_exception_if_getting_by_empty_key(string key)
{ {
Assert.Throws<ArgumentException>(() => Language.GetLanguage(key)); Assert.Throws<ArgumentException>(() => Language.GetLanguage(key));
} }
[Fact] [Fact]
public void Should_throw_if_getting_by_null_key() public void Should_throw_exception_if_getting_by_null_key()
{ {
Assert.Throws<ArgumentNullException>(() => Language.GetLanguage(null)); Assert.Throws<ArgumentNullException>(() => Language.GetLanguage(null));
} }
[Fact] [Fact]
public void Should_throw_if_getting_by_unsupported_language() public void Should_throw_exception_if_getting_by_unsupported_language()
{ {
Assert.Throws<NotSupportedException>(() => Language.GetLanguage("xy")); Assert.Throws<NotSupportedException>(() => Language.GetLanguage("xy"));
} }

6
tests/Squidex.Infrastructure.Tests/NamedIdTest.cs

@ -126,20 +126,20 @@ namespace Squidex.Infrastructure
} }
[Fact] [Fact]
public void Should_throw_if_string_id_is_not_valid() public void Should_throw_exception_if_string_id_is_not_valid()
{ {
JsonHelper.DoesNotDeserialize<NamedId<string>>("123", new NamedStringIdConverter()); JsonHelper.DoesNotDeserialize<NamedId<string>>("123", new NamedStringIdConverter());
} }
[Fact] [Fact]
public void Should_throw_if_long_id_is_not_valid() public void Should_throw_exception_if_long_id_is_not_valid()
{ {
JsonHelper.DoesNotDeserialize<NamedId<long>>("123", new NamedLongIdConverter()); JsonHelper.DoesNotDeserialize<NamedId<long>>("123", new NamedLongIdConverter());
JsonHelper.DoesNotDeserialize<NamedId<long>>("invalid-long,name", new NamedLongIdConverter()); JsonHelper.DoesNotDeserialize<NamedId<long>>("invalid-long,name", new NamedLongIdConverter());
} }
[Fact] [Fact]
public void Should_throw_if_guid_id_is_not_valid() public void Should_throw_exception_if_guid_id_is_not_valid()
{ {
JsonHelper.DoesNotDeserialize<NamedId<Guid>>("123", new NamedGuidIdConverter()); JsonHelper.DoesNotDeserialize<NamedId<Guid>>("123", new NamedGuidIdConverter());
JsonHelper.DoesNotDeserialize<NamedId<Guid>>("invalid-guid,name", new NamedGuidIdConverter()); JsonHelper.DoesNotDeserialize<NamedId<Guid>>("invalid-guid,name", new NamedGuidIdConverter());

2
tests/Squidex.Infrastructure.Tests/RefTokenTests.cs

@ -22,7 +22,7 @@ namespace Squidex.Infrastructure
[InlineData(" ")] [InlineData(" ")]
[InlineData(":")] [InlineData(":")]
[InlineData("user")] [InlineData("user")]
public void Should_throw_if_parsing_invalid_input(string input) public void Should_throw_exception_if_parsing_invalid_input(string input)
{ {
Assert.Throws<ArgumentException>(() => RefToken.Parse(input)); Assert.Throws<ArgumentException>(() => RefToken.Parse(input));
} }

8
tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs

@ -63,13 +63,13 @@ namespace Squidex.Infrastructure.Reflection
} }
[Fact] [Fact]
public void Should_throw_if_setting_unknown_property() public void Should_throw_exception_if_setting_unknown_property()
{ {
Assert.Throws<ArgumentException>(() => accessor.SetValue(target, "Unknown", 123)); Assert.Throws<ArgumentException>(() => accessor.SetValue(target, "Unknown", 123));
} }
[Fact] [Fact]
public void Should_throw_if_setting_readonly() public void Should_throw_exception_if_setting_readonly()
{ {
Assert.Throws<NotSupportedException>(() => accessor.SetValue(target, "Read", 123)); Assert.Throws<NotSupportedException>(() => accessor.SetValue(target, "Read", 123));
} }
@ -91,13 +91,13 @@ namespace Squidex.Infrastructure.Reflection
} }
[Fact] [Fact]
public void Should_throw_if_getting_unknown_property() public void Should_throw_exception_if_getting_unknown_property()
{ {
Assert.Throws<ArgumentException>(() => accessor.GetValue(target, "Unknown")); Assert.Throws<ArgumentException>(() => accessor.GetValue(target, "Unknown"));
} }
[Fact] [Fact]
public void Should_throw_if_getting_readonly_property() public void Should_throw_exception_if_getting_readonly_property()
{ {
Assert.Throws<NotSupportedException>(() => accessor.GetValue(target, "Write")); Assert.Throws<NotSupportedException>(() => accessor.GetValue(target, "Write"));
} }

4
tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs

@ -61,13 +61,13 @@ namespace Squidex.Infrastructure.Reflection
} }
[Fact] [Fact]
public void Should_throw_if_mapping_with_null_source() public void Should_throw_exception_if_mapping_with_null_source()
{ {
Assert.Throws<ArgumentNullException>(() => SimpleMapper.Map((MyClass1)null, new MyClass2())); Assert.Throws<ArgumentNullException>(() => SimpleMapper.Map((MyClass1)null, new MyClass2()));
} }
[Fact] [Fact]
public void Should_throw_if_mapping_with_null_target() public void Should_throw_exception_if_mapping_with_null_target()
{ {
Assert.Throws<ArgumentNullException>(() => SimpleMapper.Map(new MyClass1(), (MyClass2)null)); Assert.Throws<ArgumentNullException>(() => SimpleMapper.Map(new MyClass1(), (MyClass2)null));
} }

10
tests/Squidex.Infrastructure.Tests/TypeNameRegistryTests.cs

@ -58,14 +58,14 @@ namespace Squidex.Infrastructure
} }
[Fact] [Fact]
public void Should_not_throw_if_type_is_already_registered_with_same_name() public void Should_not_throw_exception_if_type_is_already_registered_with_same_name()
{ {
sut.Map(typeof(long), "long"); sut.Map(typeof(long), "long");
sut.Map(typeof(long), "long"); sut.Map(typeof(long), "long");
} }
[Fact] [Fact]
public void Should_throw_if_type_is_already_registered() public void Should_throw_exception_if_type_is_already_registered()
{ {
sut.Map(typeof(long), "long"); sut.Map(typeof(long), "long");
@ -73,7 +73,7 @@ namespace Squidex.Infrastructure
} }
[Fact] [Fact]
public void Should_throw_if_name_is_already_registered() public void Should_throw_exception_if_name_is_already_registered()
{ {
sut.Map(typeof(short), "short"); sut.Map(typeof(short), "short");
@ -81,13 +81,13 @@ namespace Squidex.Infrastructure
} }
[Fact] [Fact]
public void Should_throw_if_name_is_not_supported() public void Should_throw_exception_if_name_is_not_supported()
{ {
Assert.Throws<TypeNameNotFoundException>(() => sut.GetType("unsupported")); Assert.Throws<TypeNameNotFoundException>(() => sut.GetType("unsupported"));
} }
[Fact] [Fact]
public void Should_throw_if_type_is_not_supported() public void Should_throw_exception_if_type_is_not_supported()
{ {
Assert.Throws<TypeNameNotFoundException>(() => sut.GetName<Guid>()); Assert.Throws<TypeNameNotFoundException>(() => sut.GetName<Guid>());
} }

6
tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs

@ -29,7 +29,7 @@ namespace Squidex.Infrastructure.UsageTracking
} }
[Fact] [Fact]
public Task Should_throw_if_tracking_on_disposed_object() public Task Should_throw_exception_if_tracking_on_disposed_object()
{ {
sut.Dispose(); sut.Dispose();
@ -37,7 +37,7 @@ namespace Squidex.Infrastructure.UsageTracking
} }
[Fact] [Fact]
public Task Should_throw_if_querying_on_disposed_object() public Task Should_throw_exception_if_querying_on_disposed_object()
{ {
sut.Dispose(); sut.Dispose();
@ -45,7 +45,7 @@ namespace Squidex.Infrastructure.UsageTracking
} }
[Fact] [Fact]
public Task Should_throw_if_querying_montly_usage_on_disposed_object() public Task Should_throw_exception_if_querying_montly_usage_on_disposed_object()
{ {
sut.Dispose(); sut.Dispose();

2
tests/Squidex.Read.Tests/MongoDb/Contents/ODataQueryTests.cs

@ -57,7 +57,7 @@ namespace Squidex.Read.MongoDb.Contents
{ {
var builder = new EdmModelBuilder(new MemoryCache(Options.Create(new MemoryCacheOptions()))); var builder = new EdmModelBuilder(new MemoryCache(Options.Create(new MemoryCacheOptions())));
var schemaEntity = new Mock<ISchemaEntityWithSchema>(); var schemaEntity = new Mock<ISchemaEntity>();
schemaEntity.Setup(x => x.Id).Returns(Guid.NewGuid()); schemaEntity.Setup(x => x.Id).Returns(Guid.NewGuid());
schemaEntity.Setup(x => x.Version).Returns(3); schemaEntity.Setup(x => x.Version).Returns(3);
schemaEntity.Setup(x => x.Schema).Returns(schema); schemaEntity.Setup(x => x.Schema).Returns(schema);

12
tests/Squidex.Read.Tests/Schemas/CachingSchemaProviderTests.cs

@ -28,15 +28,15 @@ namespace Squidex.Read.Schemas
private readonly IMemoryCache cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); private readonly IMemoryCache cache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
private readonly Mock<ISchemaRepository> repository = new Mock<ISchemaRepository>(); private readonly Mock<ISchemaRepository> repository = new Mock<ISchemaRepository>();
private readonly CachingSchemaProvider sut; private readonly CachingSchemaProvider sut;
private readonly ISchemaEntityWithSchema schemaV1; private readonly ISchemaEntity schemaV1;
private readonly ISchemaEntityWithSchema schemaV2; private readonly ISchemaEntity schemaV2;
private readonly NamedId<Guid> schemaId = new NamedId<Guid>(Guid.NewGuid(), "my-schema"); private readonly NamedId<Guid> schemaId = new NamedId<Guid>(Guid.NewGuid(), "my-schema");
private readonly NamedId<Guid> appId = new NamedId<Guid>(Guid.NewGuid(), "my-app"); private readonly NamedId<Guid> appId = new NamedId<Guid>(Guid.NewGuid(), "my-app");
public CachingSchemaProviderTests() public CachingSchemaProviderTests()
{ {
var schemaV1Mock = new Mock<ISchemaEntityWithSchema>(); var schemaV1Mock = new Mock<ISchemaEntity>();
var schemaV2Mock = new Mock<ISchemaEntityWithSchema>(); var schemaV2Mock = new Mock<ISchemaEntity>();
schemaV1Mock.Setup(x => x.Id).Returns(schemaId.Id); schemaV1Mock.Setup(x => x.Id).Returns(schemaId.Id);
schemaV1Mock.Setup(x => x.Name).Returns(schemaId.Name); schemaV1Mock.Setup(x => x.Name).Returns(schemaId.Name);
@ -108,12 +108,12 @@ namespace Squidex.Read.Schemas
repository.Verify(x => x.FindSchemaAsync(appId.Id, schemaId.Name), Times.Exactly(2)); repository.Verify(x => x.FindSchemaAsync(appId.Id, schemaId.Name), Times.Exactly(2));
} }
private async Task ProvideSchemaById(ISchemaEntityWithSchema schema) private async Task ProvideSchemaById(ISchemaEntity schema)
{ {
Assert.Equal(schema, await sut.FindSchemaByIdAsync(schemaId.Id)); Assert.Equal(schema, await sut.FindSchemaByIdAsync(schemaId.Id));
} }
private async Task ProvideSchemaByName(ISchemaEntityWithSchema schema) private async Task ProvideSchemaByName(ISchemaEntity schema)
{ {
Assert.Equal(schema, await sut.FindSchemaByNameAsync(appId.Id, schemaId.Name)); Assert.Equal(schema, await sut.FindSchemaByNameAsync(appId.Id, schemaId.Name));
} }

8
tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs

@ -48,7 +48,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public async Task Create_should_throw_if_a_name_with_same_name_already_exists() public async Task Create_should_throw_exception_if_a_name_with_same_name_already_exists()
{ {
var context = CreateContextForCommand(new CreateApp { Name = AppName, AppId = AppId }); var context = CreateContextForCommand(new CreateApp { Name = AppName, AppId = AppId });
@ -82,7 +82,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public async Task AssignContributor_should_throw_if_user_not_found() public async Task AssignContributor_should_throw_exception_if_user_not_found()
{ {
CreateApp(); CreateApp();
@ -97,7 +97,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public async Task AssignContributor_throw_if_reached_max_contributor_size() public async Task AssignContributor_throw_exception_if_reached_max_contributor_size()
{ {
appLimitsProvider.Setup(x => x.GetPlan(0)).Returns(new ConfigAppLimitsPlan { MaxContributors = 2 }); appLimitsProvider.Setup(x => x.GetPlan(0)).Returns(new ConfigAppLimitsPlan { MaxContributors = 2 });
@ -116,7 +116,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public async Task AssignContributor_should_throw_if_null_user_not_found() public async Task AssignContributor_should_throw_exception_if_null_user_not_found()
{ {
CreateApp(); CreateApp();

62
tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs

@ -35,7 +35,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void Create_should_throw_if_created() public void Create_should_throw_exception_if_created()
{ {
CreateApp(); CreateApp();
@ -46,7 +46,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void Create_should_throw_if_command_is_not_valid() public void Create_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -70,7 +70,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AssignContributor_should_throw_if_not_created() public void AssignContributor_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -79,7 +79,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AssignContributor_should_throw_if_command_is_not_valid() public void AssignContributor_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -88,7 +88,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AssignContributor_should_throw_if_single_owner_becomes_non_owner() public void AssignContributor_should_throw_exception_if_single_owner_becomes_non_owner()
{ {
CreateApp(); CreateApp();
@ -99,7 +99,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AssignContributor_should_throw_if_user_already_contributor() public void AssignContributor_should_throw_exception_if_user_already_contributor()
{ {
CreateApp(); CreateApp();
sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = PermissionLevel.Editor })); sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = PermissionLevel.Editor }));
@ -124,7 +124,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveContributor_should_throw_if_not_created() public void RemoveContributor_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -133,7 +133,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveContributor_should_throw_if_command_is_not_valid() public void RemoveContributor_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -142,7 +142,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveContributor_should_throw_if_all_owners_removed() public void RemoveContributor_should_throw_exception_if_all_owners_removed()
{ {
CreateApp(); CreateApp();
@ -153,7 +153,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveContributor_should_throw_if_contributor_not_found() public void RemoveContributor_should_throw_exception_if_contributor_not_found()
{ {
CreateApp(); CreateApp();
@ -178,7 +178,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AttachClient_should_throw_if_not_created() public void AttachClient_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -187,7 +187,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AttachClient_should_throw_if_command_is_not_valid() public void AttachClient_should_throw_exception_if_command_is_not_valid()
{ {
CreateApp(); CreateApp();
@ -203,7 +203,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AttachClient_should_throw_if_id_already_exists() public void AttachClient_should_throw_exception_if_id_already_exists()
{ {
CreateApp(); CreateApp();
@ -229,7 +229,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RevokeClient_should_throw_if_not_created() public void RevokeClient_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -238,7 +238,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RevokeClient_should_throw_if_command_is_not_valid() public void RevokeClient_should_throw_exception_if_command_is_not_valid()
{ {
CreateApp(); CreateApp();
@ -254,7 +254,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RevokeClient_should_throw_if_client_not_found() public void RevokeClient_should_throw_exception_if_client_not_found()
{ {
CreateApp(); CreateApp();
@ -279,7 +279,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RenameClient_should_throw_if_not_created() public void RenameClient_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -288,7 +288,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RenameClient_should_throw_if_command_is_not_valid() public void RenameClient_should_throw_exception_if_command_is_not_valid()
{ {
CreateApp(); CreateApp();
@ -304,7 +304,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RenameClient_should_throw_if_client_not_found() public void RenameClient_should_throw_exception_if_client_not_found()
{ {
CreateApp(); CreateApp();
@ -315,7 +315,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RenameClient_should_throw_if_same_client_name() public void RenameClient_should_throw_exception_if_same_client_name()
{ {
CreateApp(); CreateApp();
CreateClient(); CreateClient();
@ -343,7 +343,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AddLanguage_should_throw_if_not_created() public void AddLanguage_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -352,7 +352,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AddLanguage_should_throw_if_command_is_not_valid() public void AddLanguage_should_throw_exception_if_command_is_not_valid()
{ {
CreateApp(); CreateApp();
@ -363,7 +363,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void AddLanguage_should_throw_if_language_already_exists() public void AddLanguage_should_throw_exception_if_language_already_exists()
{ {
CreateApp(); CreateApp();
@ -387,7 +387,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveLanguage_should_throw_if_not_created() public void RemoveLanguage_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -396,7 +396,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveLanguage_should_throw_if_command_is_not_valid() public void RemoveLanguage_should_throw_exception_if_command_is_not_valid()
{ {
CreateApp(); CreateApp();
@ -407,7 +407,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveLanguage_should_throw_if_language_not_found() public void RemoveLanguage_should_throw_exception_if_language_not_found()
{ {
CreateApp(); CreateApp();
@ -418,7 +418,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void RemoveLanguage_should_throw_if_master_language() public void RemoveLanguage_should_throw_exception_if_master_language()
{ {
CreateApp(); CreateApp();
@ -443,7 +443,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void UpdateLanguage_should_throw_if_not_created() public void UpdateLanguage_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -452,7 +452,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void UpdateLanguage_should_throw_if_command_is_not_valid() public void UpdateLanguage_should_throw_exception_if_command_is_not_valid()
{ {
CreateApp(); CreateApp();
@ -463,7 +463,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void UpdateLanguage_should_throw_if_language_not_found() public void UpdateLanguage_should_throw_exception_if_language_not_found()
{ {
CreateApp(); CreateApp();
@ -474,7 +474,7 @@ namespace Squidex.Write.Apps
} }
[Fact] [Fact]
public void UpdateLanguage_should_throw_if_master_language() public void UpdateLanguage_should_throw_exception_if_master_language()
{ {
CreateApp(); CreateApp();

18
tests/Squidex.Write.Tests/Assets/AssetDomainObjectTests.cs

@ -34,7 +34,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Create_should_throw_if_created() public void Create_should_throw_exception_if_created()
{ {
sut.Create(new CreateAsset { File = file }); sut.Create(new CreateAsset { File = file });
@ -65,7 +65,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Update_should_throw_if_not_created() public void Update_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -74,7 +74,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Update_should_throw_if_asset_is_deleted() public void Update_should_throw_exception_if_asset_is_deleted()
{ {
CreateAsset(); CreateAsset();
DeleteAsset(); DeleteAsset();
@ -107,7 +107,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Rename_should_throw_if_not_created() public void Rename_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -116,7 +116,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Rename_should_throw_if_asset_is_deleted() public void Rename_should_throw_exception_if_asset_is_deleted()
{ {
CreateAsset(); CreateAsset();
DeleteAsset(); DeleteAsset();
@ -128,7 +128,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Rename_should_throw_if_command_is_not_valid() public void Rename_should_throw_exception_if_command_is_not_valid()
{ {
CreateAsset(); CreateAsset();
@ -139,7 +139,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Rename_should_throw_if_new_name_is_equal_to_old_name() public void Rename_should_throw_exception_if_new_name_is_equal_to_old_name()
{ {
CreateAsset(); CreateAsset();
@ -163,7 +163,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Delete_should_throw_if_not_created() public void Delete_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -172,7 +172,7 @@ namespace Squidex.Write.Assets
} }
[Fact] [Fact]
public void Delete_should_throw_if_already_deleted() public void Delete_should_throw_exception_if_already_deleted()
{ {
CreateAsset(); CreateAsset();
DeleteAsset(); DeleteAsset();

2
tests/Squidex.Write.Tests/Contents/ContentCommandHandlerTests.cs

@ -32,7 +32,7 @@ namespace Squidex.Write.Contents
private readonly ContentDomainObject content; private readonly ContentDomainObject content;
private readonly Mock<ISchemaProvider> schemaProvider = new Mock<ISchemaProvider>(); private readonly Mock<ISchemaProvider> schemaProvider = new Mock<ISchemaProvider>();
private readonly Mock<IAppProvider> appProvider = new Mock<IAppProvider>(); private readonly Mock<IAppProvider> appProvider = new Mock<IAppProvider>();
private readonly Mock<ISchemaEntityWithSchema> schemaEntity = new Mock<ISchemaEntityWithSchema>(); private readonly Mock<ISchemaEntity> schemaEntity = new Mock<ISchemaEntity>();
private readonly Mock<IAppEntity> appEntity = new Mock<IAppEntity>(); private readonly Mock<IAppEntity> appEntity = new Mock<IAppEntity>();
private readonly ContentData data = new ContentData().AddField("my-field", new ContentFieldData().SetValue(1)); private readonly ContentData data = new ContentData().AddField("my-field", new ContentFieldData().SetValue(1));
private readonly LanguagesConfig languagesConfig = LanguagesConfig.Create(Language.DE); private readonly LanguagesConfig languagesConfig = LanguagesConfig.Create(Language.DE);

28
tests/Squidex.Write.Tests/Contents/ContentDomainObjectTests.cs

@ -42,7 +42,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Create_should_throw_if_created() public void Create_should_throw_exception_if_created()
{ {
sut.Create(new CreateContent { Data = data }); sut.Create(new CreateContent { Data = data });
@ -53,7 +53,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Create_should_throw_if_command_is_not_valid() public void Create_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -85,7 +85,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Update_should_throw_if_not_created() public void Update_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -94,7 +94,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Update_should_throw_if_content_is_deleted() public void Update_should_throw_exception_if_content_is_deleted()
{ {
CreateContent(); CreateContent();
DeleteContent(); DeleteContent();
@ -106,7 +106,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Update_should_throw_if_command_is_not_valid() public void Update_should_throw_exception_if_command_is_not_valid()
{ {
CreateContent(); CreateContent();
@ -141,7 +141,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Patch_should_throw_if_not_created() public void Patch_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -150,7 +150,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Patch_should_throw_if_content_is_deleted() public void Patch_should_throw_exception_if_content_is_deleted()
{ {
CreateContent(); CreateContent();
DeleteContent(); DeleteContent();
@ -162,7 +162,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Patch_should_throw_if_command_is_not_valid() public void Patch_should_throw_exception_if_command_is_not_valid()
{ {
CreateContent(); CreateContent();
@ -197,7 +197,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Publish_should_throw_if_not_created() public void Publish_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -206,7 +206,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Publish_should_throw_if_content_is_deleted() public void Publish_should_throw_exception_if_content_is_deleted()
{ {
CreateContent(); CreateContent();
DeleteContent(); DeleteContent();
@ -233,7 +233,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Unpublish_should_throw_if_not_created() public void Unpublish_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -242,7 +242,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Unpublish_should_throw_if_content_is_deleted() public void Unpublish_should_throw_exception_if_content_is_deleted()
{ {
CreateContent(); CreateContent();
DeleteContent(); DeleteContent();
@ -270,7 +270,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Delete_should_throw_if_not_created() public void Delete_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -279,7 +279,7 @@ namespace Squidex.Write.Contents
} }
[Fact] [Fact]
public void Delete_should_throw_if_already_deleted() public void Delete_should_throw_exception_if_already_deleted()
{ {
CreateContent(); CreateContent();
DeleteContent(); DeleteContent();

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

@ -39,12 +39,12 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public async Task Create_should_throw_if_a_name_with_same_name_already_exists() public async Task Create_should_throw_exception_if_a_name_with_same_name_already_exists()
{ {
var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId }); var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId });
schemaProvider.Setup(x => x.FindSchemaByNameAsync(AppId, SchemaName)) schemaProvider.Setup(x => x.FindSchemaByNameAsync(AppId, SchemaName))
.Returns(Task.FromResult(new Mock<ISchemaEntityWithSchema>().Object)) .Returns(Task.FromResult(new Mock<ISchemaEntity>().Object))
.Verifiable(); .Verifiable();
await TestCreate(schema, async _ => await TestCreate(schema, async _ =>
@ -61,7 +61,7 @@ namespace Squidex.Write.Schemas
var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId }); var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId });
schemaProvider.Setup(x => x.FindSchemaByNameAsync(AppId, SchemaName)) schemaProvider.Setup(x => x.FindSchemaByNameAsync(AppId, SchemaName))
.Returns(Task.FromResult<ISchemaEntityWithSchema>(null)) .Returns(Task.FromResult<ISchemaEntity>(null))
.Verifiable(); .Verifiable();
await TestCreate(schema, async _ => await TestCreate(schema, async _ =>

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

@ -37,7 +37,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Create_should_throw_if_created() public void Create_should_throw_exception_if_created()
{ {
sut.Create(new CreateSchema { Name = SchemaName }); sut.Create(new CreateSchema { Name = SchemaName });
@ -48,7 +48,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Create_should_throw_if_command_is_not_valid() public void Create_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -56,6 +56,27 @@ namespace Squidex.Write.Schemas
}); });
} }
[Fact]
public void Create_should_throw_exception_if_fields_are_not_valid()
{
var properties = new SchemaProperties();
var fields = new List<CreateSchemaField>
{
new CreateSchemaField
{
Name = null,
Properties = null,
Partitioning = "invalid"
}
};
Assert.Throws<ValidationException>(() =>
{
sut.Create(CreateCommand(new CreateSchema { Name = SchemaName, Properties = properties, Fields = fields }));
});
}
[Fact] [Fact]
public void Create_should_create_schema_and_create_events() public void Create_should_create_schema_and_create_events()
{ {
@ -67,12 +88,31 @@ namespace Squidex.Write.Schemas
sut.GetUncomittedEvents() sut.GetUncomittedEvents()
.ShouldHaveSameEvents( .ShouldHaveSameEvents(
CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties }) CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties, Fields = new List<SchemaCreatedField>() })
); );
} }
[Fact] [Fact]
public void Update_should_throw_if_not_created() public void Create_should_create_schema_with_initial_fields()
{
var properties = new SchemaProperties();
var fields = new List<CreateSchemaField>
{
new CreateSchemaField { Name = "field1", Properties = new GeolocationFieldProperties() },
new CreateSchemaField { Name = "field2", Properties = new StringFieldProperties() }
};
sut.Create(CreateCommand(new CreateSchema { Name = SchemaName, Properties = properties, Fields = fields }));
var @event = (SchemaCreated)sut.GetUncomittedEvents().Single().Payload;
Assert.Equal(SchemaName, sut.Schema.Name);
Assert.Equal(2, @event.Fields.Count);
}
[Fact]
public void Update_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -81,7 +121,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Update_should_throw_if_schema_is_deleted() public void Update_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -93,7 +133,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Update_should_throw_if_command_is_not_valid() public void Update_should_throw_exception_if_command_is_not_valid()
{ {
CreateSchema(); CreateSchema();
@ -121,7 +161,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Reorder_should_throw_if_not_created() public void Reorder_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -130,7 +170,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Reorder_should_throw_if_schema_is_deleted() public void Reorder_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -142,7 +182,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Reorder_should_throw_if_command_is_not_valid() public void Reorder_should_throw_exception_if_command_is_not_valid()
{ {
CreateSchema(); CreateSchema();
@ -173,7 +213,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Publish_should_throw_if_not_created() public void Publish_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -182,7 +222,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Publish_should_throw_if_schema_is_deleted() public void Publish_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -209,7 +249,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Unpublish_should_throw_if_not_created() public void Unpublish_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -218,7 +258,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Unpublish_should_throw_if_schema_is_deleted() public void Unpublish_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -246,7 +286,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Delete_should_throw_if_not_created() public void Delete_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -255,7 +295,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void Delete_should_throw_if_already_deleted() public void Delete_should_throw_exception_if_already_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -282,7 +322,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void AddField_should_throw_if_not_created() public void AddField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -291,7 +331,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void AddField_should_throw_if_command_is_not_valid() public void AddField_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -300,7 +340,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void AddField_should_throw_if_command_contains_invalid_partitioning() public void AddField_should_throw_exception_if_command_contains_invalid_partitioning()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -309,7 +349,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void AddField_should_throw_if_schema_is_deleted() public void AddField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -338,7 +378,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void UpdateField_should_throw_if_not_created() public void UpdateField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -347,7 +387,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void UpdateField_should_throw_if_command_is_not_valid() public void UpdateField_should_throw_exception_if_command_is_not_valid()
{ {
Assert.Throws<ValidationException>(() => Assert.Throws<ValidationException>(() =>
{ {
@ -356,7 +396,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void UpdateField_should_throw_if_field_is_not_found() public void UpdateField_should_throw_exception_if_field_is_not_found()
{ {
CreateSchema(); CreateSchema();
@ -367,7 +407,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void UpdateField_should_throw_if_schema_is_deleted() public void UpdateField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -397,7 +437,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void HideField_should_throw_if_not_created() public void HideField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -406,7 +446,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void HideField_should_throw_if_field_is_not_found() public void HideField_should_throw_exception_if_field_is_not_found()
{ {
CreateSchema(); CreateSchema();
@ -417,7 +457,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void HideField_should_throw_if_schema_is_deleted() public void HideField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -445,7 +485,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void ShowField_should_throw_if_not_created() public void ShowField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -454,7 +494,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void ShowField_should_throw_if_field_is_not_found() public void ShowField_should_throw_exception_if_field_is_not_found()
{ {
CreateSchema(); CreateSchema();
@ -465,7 +505,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void ShowField_should_throw_if_schema_is_deleted() public void ShowField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -494,7 +534,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void DisableField_should_throw_if_not_created() public void DisableField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -503,7 +543,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void DisableField_should_throw_if_field_is_not_found() public void DisableField_should_throw_exception_if_field_is_not_found()
{ {
CreateSchema(); CreateSchema();
@ -514,7 +554,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void DisableField_should_throw_if_schema_is_deleted() public void DisableField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -542,7 +582,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void EnableField_should_throw_if_not_created() public void EnableField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -551,7 +591,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void EnableField_should_throw_if_field_is_not_found() public void EnableField_should_throw_exception_if_field_is_not_found()
{ {
CreateSchema(); CreateSchema();
@ -562,7 +602,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void EnableField_should_throw_if_schema_is_deleted() public void EnableField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();
@ -591,7 +631,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void DeleteField_should_throw_if_not_created() public void DeleteField_should_throw_exception_if_not_created()
{ {
Assert.Throws<DomainException>(() => Assert.Throws<DomainException>(() =>
{ {
@ -600,7 +640,7 @@ namespace Squidex.Write.Schemas
} }
[Fact] [Fact]
public void DeleteField_should_throw_if_schema_is_deleted() public void DeleteField_should_throw_exception_if_schema_is_deleted()
{ {
CreateSchema(); CreateSchema();
DeleteSchema(); DeleteSchema();

Loading…
Cancel
Save