From cb6f9bf5125547bc5c0f4bb513abe68c3d84489e Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Mon, 22 May 2017 22:07:42 +0200 Subject: [PATCH] Import feature --- src/Squidex.Core/Schemas/FieldRegistry.cs | 2 + .../Contents/MongoContentRepository.cs | 2 +- .../Schemas/MongoSchemaEntity.cs | 10 +- .../Schemas/MongoSchemaRepository.cs | 13 +- .../Contents/Builders/EdmModelBuilder.cs | 2 +- src/Squidex.Read/Schemas/ISchemaEntity.cs | 6 +- .../Schemas/ISchemaEntityWithSchema.cs | 17 --- .../Schemas/Repositories/ISchemaRepository.cs | 6 +- .../Schemas/Services/ISchemaProvider.cs | 4 +- .../Implementations/CachingSchemaProvider.cs | 8 +- .../Schemas/Commands/CreateSchema.cs | 36 +++++- .../Models/Converters/SchemaConverter.cs | 45 ++++++- .../Api/Schemas/Models/CreateSchemaDto.cs | 11 ++ .../Schemas/Models/CreateSchemaFieldDto.cs | 44 +++++++ .../Api/Schemas/Models/SchemaDetailsDto.cs | 12 +- .../Api/Schemas/Models/SchemaDto.cs | 6 +- .../Api/Schemas/Models/SchemaPropertiesDto.cs | 27 +++++ .../Api/Schemas/SchemasController.cs | 6 +- .../ContentApi/ContentSwaggerController.cs | 2 +- .../Generator/SchemasSwaggerGenerator.cs | 4 +- .../content/content-field.component.html | 4 +- .../contents/contents-page.component.html | 2 +- .../pages/schemas/schemas-page.component.html | 2 +- .../app/features/schemas/pages/messages.ts | 4 +- .../schema/schema-edit-form.component.html | 2 +- .../schema/schema-edit-form.component.ts | 15 +-- .../pages/schema/schema-page.component.html | 6 +- .../pages/schema/schema-page.component.ts | 20 +-- .../schemas/pages/schema/schema-properties.ts | 15 --- .../pages/schemas/schema-form.component.html | 11 ++ .../pages/schemas/schema-form.component.scss | 13 +- .../pages/schemas/schema-form.component.ts | 23 +++- .../pages/schemas/schemas-page.component.html | 2 +- .../pages/schemas/schemas-page.component.ts | 2 +- .../shared/services/schemas.service.spec.ts | 23 ++-- .../app/shared/services/schemas.service.ts | 24 ++-- .../Schemas/FieldRegistryTests.cs | 2 +- .../Squidex.Core.Tests/Schemas/SchemaTests.cs | 32 ++--- .../CQRS/Commands/AggregateHandlerTests.cs | 4 +- .../DefaultDomainObjectFactoryTests.cs | 2 +- .../GuardTests.cs | 4 +- .../LanguageTests.cs | 6 +- .../NamedIdTest.cs | 6 +- .../RefTokenTests.cs | 2 +- .../Reflection/PropertiesTypeAccessorTests.cs | 8 +- .../Reflection/SimpleMapperTests.cs | 4 +- .../TypeNameRegistryTests.cs | 10 +- .../BackgroundUsageTrackerTests.cs | 6 +- .../MongoDb/Contents/ODataQueryTests.cs | 2 +- .../Schemas/CachingSchemaProviderTests.cs | 12 +- .../Apps/AppCommandHandlerTests.cs | 8 +- .../Apps/AppDomainObjectTests.cs | 62 +++++----- .../Assets/AssetDomainObjectTests.cs | 18 +-- .../Contents/ContentCommandHandlerTests.cs | 2 +- .../Contents/ContentDomainObjectTests.cs | 28 ++--- .../Schemas/SchemaCommandHandlerTests.cs | 6 +- .../Schemas/SchemaDomainObjectTests.cs | 114 ++++++++++++------ 57 files changed, 484 insertions(+), 285 deletions(-) delete mode 100644 src/Squidex.Read/Schemas/ISchemaEntityWithSchema.cs create mode 100644 src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaFieldDto.cs create mode 100644 src/Squidex/Controllers/Api/Schemas/Models/SchemaPropertiesDto.cs delete mode 100644 src/Squidex/app/features/schemas/pages/schema/schema-properties.ts diff --git a/src/Squidex.Core/Schemas/FieldRegistry.cs b/src/Squidex.Core/Schemas/FieldRegistry.cs index 30c621086..22e19c539 100644 --- a/src/Squidex.Core/Schemas/FieldRegistry.cs +++ b/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) { + Guard.NotNull(properties, nameof(properties)); + var registered = fieldsByPropertyType.GetOrDefault(properties.GetType()); if (registered == null) diff --git a/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs b/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs index 3fb01734c..cb10e6331 100644 --- a/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs +++ b/src/Squidex.Read.MongoDb/Contents/MongoContentRepository.cs @@ -139,7 +139,7 @@ namespace Squidex.Read.MongoDb.Contents return result; } - private async Task ForSchemaAsync(Guid schemaId, Func, ISchemaEntityWithSchema, Task> action) + private async Task ForSchemaAsync(Guid schemaId, Func, ISchemaEntity, Task> action) { var collection = GetCollection(schemaId); diff --git a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs index 8e34fb03c..232f98c74 100644 --- a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs +++ b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs @@ -17,7 +17,7 @@ using Squidex.Read.Schemas; namespace Squidex.Read.MongoDb.Schemas { - public sealed class MongoSchemaEntity : MongoEntity, ISchemaEntityWithSchema + public sealed class MongoSchemaEntity : MongoEntity, ISchemaEntity { private Lazy schema; @@ -25,10 +25,6 @@ namespace Squidex.Read.MongoDb.Schemas [BsonElement] public string Name { get; set; } - [BsonRequired] - [BsonElement] - public string Label { get; set; } - [BsonRequired] [BsonElement] public string Schema { get; set; } @@ -57,15 +53,13 @@ namespace Squidex.Read.MongoDb.Schemas [BsonElement] public bool IsDeleted { get; set; } - Schema ISchemaEntityWithSchema.Schema + Schema ISchemaEntity.Schema { get { return schema.Value; } } public void SerializeSchema(Schema newSchema, SchemaJsonSerializer serializer) { - Label = newSchema.Properties.Label ?? newSchema.Name; - Schema = serializer.Serialize(newSchema).ToString(); schema = new Lazy(() => newSchema); diff --git a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs b/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs index c3767a308..5fffdfc17 100644 --- a/src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs +++ b/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(); - return entities.OfType().ToList(); - } - - public async Task> QueryAllWithSchemaAsync(Guid appId) - { - var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync(); - entities.ForEach(x => x.DeserializeSchema(serializer)); - return entities.OfType().ToList(); + return entities.OfType().ToList(); } - public async Task FindSchemaAsync(Guid appId, string name) + public async Task FindSchemaAsync(Guid appId, string name) { var entity = await Collection.Find(s => s.Name == name && s.AppId == appId && !s.IsDeleted) @@ -74,7 +67,7 @@ namespace Squidex.Read.MongoDb.Schemas return entity; } - public async Task FindSchemaAsync(Guid schemaId) + public async Task FindSchemaAsync(Guid schemaId) { var entity = await Collection.Find(s => s.Id == schemaId) diff --git a/src/Squidex.Read/Contents/Builders/EdmModelBuilder.cs b/src/Squidex.Read/Contents/Builders/EdmModelBuilder.cs index 31e77a48c..58d5a16fc 100644 --- a/src/Squidex.Read/Contents/Builders/EdmModelBuilder.cs +++ b/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)); diff --git a/src/Squidex.Read/Schemas/ISchemaEntity.cs b/src/Squidex.Read/Schemas/ISchemaEntity.cs index d8ae691da..8a32e0e7a 100644 --- a/src/Squidex.Read/Schemas/ISchemaEntity.cs +++ b/src/Squidex.Read/Schemas/ISchemaEntity.cs @@ -6,16 +6,18 @@ // All rights reserved. // ========================================================================== +using Squidex.Core.Schemas; + namespace Squidex.Read.Schemas { public interface ISchemaEntity : IAppRefEntity, IEntityWithCreatedBy, IEntityWithLastModifiedBy, IEntityWithVersion { string Name { get; } - string Label { get; } - bool IsPublished { get; } bool IsDeleted { get; } + + Schema Schema { get; } } } diff --git a/src/Squidex.Read/Schemas/ISchemaEntityWithSchema.cs b/src/Squidex.Read/Schemas/ISchemaEntityWithSchema.cs deleted file mode 100644 index 78f3abf0e..000000000 --- a/src/Squidex.Read/Schemas/ISchemaEntityWithSchema.cs +++ /dev/null @@ -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; } - } -} diff --git a/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs b/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs index 8766bc530..9da0047ea 100644 --- a/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs +++ b/src/Squidex.Read/Schemas/Repositories/ISchemaRepository.cs @@ -16,10 +16,8 @@ namespace Squidex.Read.Schemas.Repositories { Task> QueryAllAsync(Guid appId); - Task> QueryAllWithSchemaAsync(Guid appId); + Task FindSchemaAsync(Guid appId, string name); - Task FindSchemaAsync(Guid appId, string name); - - Task FindSchemaAsync(Guid schemaId); + Task FindSchemaAsync(Guid schemaId); } } diff --git a/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs b/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs index ef3234afe..74bc52473 100644 --- a/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs +++ b/src/Squidex.Read/Schemas/Services/ISchemaProvider.cs @@ -13,8 +13,8 @@ namespace Squidex.Read.Schemas.Services { public interface ISchemaProvider { - Task FindSchemaByIdAsync(Guid id, bool provideDeleted = false); + Task FindSchemaByIdAsync(Guid id, bool provideDeleted = false); - Task FindSchemaByNameAsync(Guid appId, string name); + Task FindSchemaByNameAsync(Guid appId, string name); } } diff --git a/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs b/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs index baba6aff1..ff14fb5d6 100644 --- a/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs +++ b/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs @@ -45,11 +45,11 @@ namespace Squidex.Read.Schemas.Services.Implementations this.repository = repository; } - public async Task FindSchemaByIdAsync(Guid id, bool provideDeleted = false) + public async Task FindSchemaByIdAsync(Guid id, bool provideDeleted = false) { var cacheKey = BuildIdCacheKey(id); - if (!Cache.TryGetValue(cacheKey, out ISchemaEntityWithSchema result)) + if (!Cache.TryGetValue(cacheKey, out ISchemaEntity result)) { result = await repository.FindSchemaAsync(id); @@ -69,13 +69,13 @@ namespace Squidex.Read.Schemas.Services.Implementations return result; } - public async Task FindSchemaByNameAsync(Guid appId, string name) + public async Task FindSchemaByNameAsync(Guid appId, string name) { Guard.NotNullOrEmpty(name, nameof(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); diff --git a/src/Squidex.Write/Schemas/Commands/CreateSchema.cs b/src/Squidex.Write/Schemas/Commands/CreateSchema.cs index fa8d0cb15..b443e4bad 100644 --- a/src/Squidex.Write/Schemas/Commands/CreateSchema.cs +++ b/src/Squidex.Write/Schemas/Commands/CreateSchema.cs @@ -18,13 +18,36 @@ namespace Squidex.Write.Schemas.Commands { public class CreateSchema : AppCommand, IValidatable, IAggregateCommand { + private SchemaProperties properties; + private SchemaFields fields; + 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 { @@ -47,6 +70,13 @@ namespace Squidex.Write.Schemas.Commands { errors.Add(new ValidationError("Properties must be specified", nameof(Properties))); } + + var index = 0; + + foreach (var field in Fields) + { + field.Validate(index++, errors); + } } } } \ No newline at end of file diff --git a/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs b/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs index bcea41fcb..179b4f4cf 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/Converters/SchemaConverter.cs @@ -12,6 +12,9 @@ using System.Linq; using Squidex.Core.Schemas; using Squidex.Infrastructure.Reflection; using Squidex.Read.Schemas; +using Squidex.Write.Schemas.Commands; + +// ReSharper disable InvertIf 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.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(); @@ -76,6 +90,31 @@ namespace Squidex.Controllers.Api.Schemas.Models.Converters 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) { var result = SimpleMapper.Map(source, new BooleanFieldPropertiesDto()); diff --git a/src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs index 7a52afacd..b4da5cba2 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaDto.cs @@ -6,6 +6,7 @@ // All rights reserved. // ========================================================================== +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Squidex.Controllers.Api.Schemas.Models @@ -18,5 +19,15 @@ namespace Squidex.Controllers.Api.Schemas.Models [Required] [RegularExpression("^[a-z0-9]+(\\-[a-z0-9]+)*$")] public string Name { get; set; } + + /// + /// The optional properties. + /// + public SchemaPropertiesDto Properties { get; set; } + + /// + /// Optional fields. + /// + public List Fields { get; set; } } } diff --git a/src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaFieldDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/CreateSchemaFieldDto.cs new file mode 100644 index 000000000..521948698 --- /dev/null +++ b/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 + { + /// + /// The name of the field. Must be unique within the schema. + /// + [Required] + [RegularExpression("^[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*$")] + public string Name { get; set; } + + /// + /// Defines if the field is hidden. + /// + public bool IsHidden { get; set; } + + /// + /// Defines if the field is disabled. + /// + public bool IsDisabled { get; set; } + + /// + /// Determines the optional partitioning of the field. + /// + public string Partitioning { get; set; } + + /// + /// The field properties. + /// + [Required] + public FieldPropertiesDto Properties { get; set; } + } +} + diff --git a/src/Squidex/Controllers/Api/Schemas/Models/SchemaDetailsDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/SchemaDetailsDto.cs index 6d0e1b28c..a3ddd50e2 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/SchemaDetailsDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/SchemaDetailsDto.cs @@ -40,16 +40,10 @@ namespace Squidex.Controllers.Api.Schemas.Models public List Fields { get; set; } /// - /// Optional label for the editor. + /// The schema properties. /// - [StringLength(100)] - public string Label { get; set; } - - /// - /// Hints to describe the schema. - /// - [StringLength(1000)] - public string Hints { get; set; } + [Required] + public SchemaPropertiesDto Properties { get; set; } /// /// The user that has created the schema. diff --git a/src/Squidex/Controllers/Api/Schemas/Models/SchemaDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/SchemaDto.cs index f01171462..3091ae743 100644 --- a/src/Squidex/Controllers/Api/Schemas/Models/SchemaDto.cs +++ b/src/Squidex/Controllers/Api/Schemas/Models/SchemaDto.cs @@ -28,10 +28,10 @@ namespace Squidex.Controllers.Api.Schemas.Models public string Name { get; set; } /// - /// Optional label for the editor. + /// The schema properties. /// - [StringLength(100)] - public string Label { get; set; } + [Required] + public SchemaPropertiesDto Properties { get; set; } /// /// Indicates if the schema is published. diff --git a/src/Squidex/Controllers/Api/Schemas/Models/SchemaPropertiesDto.cs b/src/Squidex/Controllers/Api/Schemas/Models/SchemaPropertiesDto.cs new file mode 100644 index 000000000..e36928c49 --- /dev/null +++ b/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 + { + /// + /// Optional label for the editor. + /// + [StringLength(100)] + public string Label { get; set; } + + /// + /// Hints to describe the schema. + /// + [StringLength(1000)] + public string Hints { get; set; } + } +} diff --git a/src/Squidex/Controllers/Api/Schemas/SchemasController.cs b/src/Squidex/Controllers/Api/Schemas/SchemasController.cs index 381b74062..4aee89835 100644 --- a/src/Squidex/Controllers/Api/Schemas/SchemasController.cs +++ b/src/Squidex/Controllers/Api/Schemas/SchemasController.cs @@ -55,7 +55,7 @@ namespace Squidex.Controllers.Api.Schemas { 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); } @@ -82,7 +82,7 @@ namespace Squidex.Controllers.Api.Schemas return NotFound(); } - var model = entity.ToModel(); + var model = entity.ToDetailsModel(); Response.Headers["ETag"] = new StringValues(entity.Version.ToString()); @@ -107,7 +107,7 @@ namespace Squidex.Controllers.Api.Schemas [ApiCosts(1)] public async Task PostSchema(string app, [FromBody] CreateSchemaDto request) { - var command = SimpleMapper.Map(request, new CreateSchema()); + var command = request.ToCommand(); await CommandBus.PublishAsync(command); diff --git a/src/Squidex/Controllers/ContentApi/ContentSwaggerController.cs b/src/Squidex/Controllers/ContentApi/ContentSwaggerController.cs index 1f8752cb7..095127eb3 100644 --- a/src/Squidex/Controllers/ContentApi/ContentSwaggerController.cs +++ b/src/Squidex/Controllers/ContentApi/ContentSwaggerController.cs @@ -56,7 +56,7 @@ namespace Squidex.Controllers.ContentApi return NotFound(); } - var schemas = await schemaRepository.QueryAllWithSchemaAsync(appEntity.Id); + var schemas = await schemaRepository.QueryAllAsync(appEntity.Id); var swaggerDocument = await schemasSwaggerGenerator.Generate(appEntity, schemas); diff --git a/src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs b/src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs index 17d31207f..1f65b01f7 100644 --- a/src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs +++ b/src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs @@ -61,7 +61,7 @@ namespace Squidex.Controllers.ContentApi.Generator schemaQueryDescription = SwaggerHelper.LoadDocs("schemaquery"); } - public async Task Generate(IAppEntity targetApp, IEnumerable schemas) + public async Task Generate(IAppEntity targetApp, IEnumerable schemas) { app = targetApp; @@ -159,7 +159,7 @@ namespace Squidex.Controllers.ContentApi.Generator } } - private void GenerateSchemasOperations(IEnumerable schemas) + private void GenerateSchemasOperations(IEnumerable schemas) { foreach (var schema in schemas.Where(x => x.IsPublished).Select(x => x.Schema)) { diff --git a/src/Squidex/app/features/content/pages/content/content-field.component.html b/src/Squidex/app/features/content/pages/content/content-field.component.html index 539997329..179b8f1bd 100644 --- a/src/Squidex/app/features/content/pages/content/content-field.component.html +++ b/src/Squidex/app/features/content/pages/content/content-field.component.html @@ -1,6 +1,6 @@
Disabled @@ -12,7 +12,7 @@
- +
diff --git a/src/Squidex/app/features/content/pages/contents/contents-page.component.html b/src/Squidex/app/features/content/pages/contents/contents-page.component.html index ec55b49c4..22c899b07 100644 --- a/src/Squidex/app/features/content/pages/contents/contents-page.component.html +++ b/src/Squidex/app/features/content/pages/contents/contents-page.component.html @@ -44,7 +44,7 @@ - {{field|displayName:'properties.label':'name'}} + {{field | displayName:'properties.label':'name'}} Updated diff --git a/src/Squidex/app/features/content/pages/schemas/schemas-page.component.html b/src/Squidex/app/features/content/pages/schemas/schemas-page.component.html index 5a6358b71..cdedec251 100644 --- a/src/Squidex/app/features/content/pages/schemas/schemas-page.component.html +++ b/src/Squidex/app/features/content/pages/schemas/schemas-page.component.html @@ -24,7 +24,7 @@
diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts index ebb130d5a..5293f97c2 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts @@ -22,13 +22,13 @@ import { ModalView, NotificationService, SchemaDetailsDto, + SchemaPropertiesDto, SchemasService, UpdateFieldDto, ValidatorsEx, Version } from 'shared'; -import { SchemaPropertiesDto } from './schema-properties'; import { SchemaDeleted, SchemaUpdated } from './../messages'; @Component({ @@ -51,10 +51,11 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { ]; public schemaExport: any; - public schemaFields = ImmutableArray.empty(); public schemaName: string; - public schemaProperties: SchemaPropertiesDto; + public schemaFields = ImmutableArray.empty(); public schemaVersion = new Version(''); + public schemaProperties: SchemaPropertiesDto; + public schemaInformation: any; public confirmDeleteDialog = new ModalView(); @@ -99,8 +100,9 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { .subscribe((schema: SchemaDetailsDto) => { this.schemaName = schema.name; this.schemaFields = ImmutableArray.of(schema.fields); - this.schemaProperties = new SchemaPropertiesDto(schema.name, schema.label, schema.hints); this.schemaVersion = schema.version; + this.schemaProperties = schema.properties; + this.schemaInformation = { properties: schema.properties, name: schema.name }; this.isPublished = schema.isPublished; @@ -269,6 +271,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { private updateProperties(properties: SchemaPropertiesDto) { this.schemaProperties = properties; + this.schemaInformation = { properties: properties, name: this.schemaName }; this.notify(); this.export(); @@ -304,15 +307,16 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { } return copy; - }) + }), + properties: {} }; if (this.schemaProperties.label) { - result.label = this.schemaProperties.label; + result.properties.label = this.schemaProperties.label; } if (this.schemaProperties.hints) { - result.hints = this.schemaProperties.hints; + result.properties.hints = this.schemaProperties.hints; } this.schemaExport = result; @@ -320,7 +324,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { private notify() { 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)); } } diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-properties.ts b/src/Squidex/app/features/schemas/pages/schema/schema-properties.ts deleted file mode 100644 index dfae6e664..000000000 --- a/src/Squidex/app/features/schemas/pages/schema/schema-properties.ts +++ /dev/null @@ -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 - ) { - } -} \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html index 61d52405c..ba4a6a919 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html +++ b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.html @@ -20,6 +20,17 @@
+
+ + + + +
+
diff --git a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.scss b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.scss index fbb752506..646a4d224 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.scss +++ b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.scss @@ -1,2 +1,13 @@ @import '_vars'; -@import '_mixins'; \ No newline at end of file +@import '_mixins'; + +.btn-link { + margin-top: -1rem; + margin-left: -.5rem; +} + +:host /deep/ .editor { + height: 15rem !important; + margin-bottom: .5rem; + margin-top: 0; +} \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts index d22c8dadc..9376c6363 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts +++ b/src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts @@ -11,10 +11,10 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { ApiUrlConfig, AuthService, - CreateSchemaDto, DateTime, fadeAnimation, SchemaDto, + SchemaPropertiesDto, SchemasService, ValidatorsEx, Version @@ -40,6 +40,8 @@ export class SchemaFormComponent { @Output() public cancelled = new EventEmitter(); + public showImport = false; + public creationError = ''; public createFormSubmitted = false; public createForm: FormGroup = @@ -49,7 +51,8 @@ export class SchemaFormComponent { Validators.required, 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).') - ]] + ]], + import: [{}] }); public schemaName = @@ -64,6 +67,12 @@ export class SchemaFormComponent { ) { } + public toggleImport() { + this.showImport = !this.showImport; + + return false; + } + public cancel() { this.reset(); this.cancelled.emit(); @@ -78,12 +87,14 @@ export class SchemaFormComponent { const schemaVersion = new Version(); 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) .subscribe(dto => { this.reset(); - this.created.emit(this.createSchemaDto(dto.id, schemaName, schemaVersion)); + this.created.emit(this.createSchemaDto(dto.id, requestDto.properties || {}, schemaName, schemaVersion)); }, error => { this.createForm.enable(); this.creationError = error.displayMessage; @@ -97,10 +108,10 @@ export class SchemaFormComponent { 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 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); } } \ No newline at end of file diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html index d597f4996..390ed6ece 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html +++ b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html @@ -30,7 +30,7 @@
- {{schema|displayName}} + {{schema | displayName:'properties.label':'name'}}
diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts index 7efc33e06..8359c9d54 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts +++ b/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( schema.id, schema.name, - message.label, + message.properties, message.isPublished, schema.createdBy, me, schema.created, DateTime.now(), diff --git a/src/Squidex/app/shared/services/schemas.service.spec.ts b/src/Squidex/app/shared/services/schemas.service.spec.ts index 0b0371eb5..492aa4f8c 100644 --- a/src/Squidex/app/shared/services/schemas.service.spec.ts +++ b/src/Squidex/app/shared/services/schemas.service.spec.ts @@ -20,6 +20,7 @@ import { FieldDto, SchemaDetailsDto, SchemaDto, + SchemaPropertiesDto, SchemasService, UpdateFieldDto, UpdateSchemaDto, @@ -49,7 +50,10 @@ describe('SchemasService', () => { { id: 'id1', name: 'name1', - label: 'label1', + properties: { + label: 'label1', + hints: 'hints1' + }, isPublished: true, created: '2016-12-12T10:10', createdBy: 'Created1', @@ -61,7 +65,10 @@ describe('SchemasService', () => { { id: 'id2', name: 'name2', - label: 'label2', + properties: { + label: 'label2', + hints: 'hints2' + }, isPublished: true, created: '2016-10-12T10:10', createdBy: 'Created2', @@ -83,11 +90,11 @@ describe('SchemasService', () => { }).unsubscribe(); 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('2017-12-12T10:10'), 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('2017-10-12T10:10'), new Version('22')) @@ -104,8 +111,10 @@ describe('SchemasService', () => { body: { id: 'id1', name: 'name1', - label: 'label1', - hints: 'hints1', + properties: { + label: 'label1', + hints: 'hints1' + }, isPublished: true, created: '2016-12-12T10:10', createdBy: 'Created1', @@ -197,7 +206,7 @@ describe('SchemasService', () => { }).unsubscribe(); 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('2017-12-12T10:10'), new Version('11'), diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index 252f3b208..9f8a2c9bd 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -59,7 +59,7 @@ export class SchemaDto { constructor( public readonly id: string, public readonly name: string, - public readonly label: string | null, + public readonly properties: SchemaPropertiesDto, public readonly isPublished: boolean, public readonly createdBy: string, public readonly lastModifiedBy: string, @@ -74,8 +74,7 @@ export class SchemaDetailsDto { constructor( public readonly id: string, public readonly name: string, - public readonly label: string, - public readonly hints: string, + public readonly properties: SchemaPropertiesDto, public readonly isPublished: boolean, public readonly createdBy: 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 { constructor( public readonly label?: string, @@ -242,10 +249,11 @@ export class SchemasService { const items: any[] = response; return items.map(item => { + const properties = new SchemaPropertiesDto(item.properties.label, item.properties.hints); + return new SchemaDto( item.id, - item.name, - item.label, + item.name, properties, item.isPublished, item.createdBy, item.lastModifiedBy, @@ -278,11 +286,11 @@ export class SchemasService { propertiesDto); }); + const properties = new SchemaPropertiesDto(response.properties.label, response.properties.hints); + return new SchemaDetailsDto( response.id, - response.name, - response.label, - response.hints, + response.name, properties, response.isPublished, response.createdBy, response.lastModifiedBy, diff --git a/tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs b/tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs index 603dc62cf..88d3605fd 100644 --- a/tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs +++ b/tests/Squidex.Core.Tests/Schemas/FieldRegistryTests.cs @@ -33,7 +33,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.CreateField(1, "name", Partitioning.Invariant, new InvalidProperties())); } diff --git a/tests/Squidex.Core.Tests/Schemas/SchemaTests.cs b/tests/Squidex.Core.Tests/Schemas/SchemaTests.cs index f3eb94012..12d4b5c63 100644 --- a/tests/Squidex.Core.Tests/Schemas/SchemaTests.cs +++ b/tests/Squidex.Core.Tests/Schemas/SchemaTests.cs @@ -47,7 +47,7 @@ namespace Squidex.Core.Schemas } [Fact] - public void Should_throw_if_creating_schema_with_invalid_name() + public void Should_throw_exception_if_creating_schema_with_invalid_name() { Assert.Throws(() => Schema.Create("Invalid Name", new SchemaProperties())); } @@ -71,7 +71,7 @@ namespace Squidex.Core.Schemas } [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(); @@ -90,7 +90,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.HideField(1)); } @@ -108,7 +108,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.ShowField(2)); } @@ -125,7 +125,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.DisableField(1)); } @@ -143,7 +143,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.EnableField(1)); } @@ -159,7 +159,7 @@ namespace Squidex.Core.Schemas } [Fact] - public void Should_throw_if_new_field_already_exists() + public void Should_throw_exception_if_new_field_already_exists() { AddField(); @@ -169,7 +169,7 @@ namespace Squidex.Core.Schemas } [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(); @@ -177,7 +177,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.RenameField(1, "new-name")); } @@ -193,7 +193,7 @@ namespace Squidex.Core.Schemas } [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); } @@ -209,7 +209,7 @@ namespace Squidex.Core.Schemas } [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(); @@ -217,7 +217,7 @@ namespace Squidex.Core.Schemas } [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(() => sut.UpdateField(1, new NumberFieldProperties())); } @@ -231,7 +231,7 @@ namespace Squidex.Core.Schemas } [Fact] - public void Should_throw_if_schema_is_already_published() + public void Should_throw_exception_if_schema_is_already_published() { sut = sut.Publish(); @@ -248,7 +248,7 @@ namespace Squidex.Core.Schemas } [Fact] - public void Should_throw_if_schema_is_not_published() + public void Should_throw_exception_if_schema_is_not_published() { Assert.Throws(() => sut.Unpublish()); } @@ -269,7 +269,7 @@ namespace Squidex.Core.Schemas } [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 field2 = new StringField(2, "2", Partitioning.Invariant); @@ -281,7 +281,7 @@ namespace Squidex.Core.Schemas } [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 field2 = new StringField(2, "2", Partitioning.Invariant); diff --git a/tests/Squidex.Infrastructure.Tests/CQRS/Commands/AggregateHandlerTests.cs b/tests/Squidex.Infrastructure.Tests/CQRS/Commands/AggregateHandlerTests.cs index ecc495b05..beb5c30af 100644 --- a/tests/Squidex.Infrastructure.Tests/CQRS/Commands/AggregateHandlerTests.cs +++ b/tests/Squidex.Infrastructure.Tests/CQRS/Commands/AggregateHandlerTests.cs @@ -83,7 +83,7 @@ namespace Squidex.Infrastructure.CQRS.Commands } [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(() => sut.CreateAsync(new CommandContext(new Mock().Object), x => TaskHelper.False)); } @@ -139,7 +139,7 @@ namespace Squidex.Infrastructure.CQRS.Commands } [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(() => sut.UpdateAsync(new CommandContext(new Mock().Object), x => TaskHelper.False)); } diff --git a/tests/Squidex.Infrastructure.Tests/CQRS/Commands/DefaultDomainObjectFactoryTests.cs b/tests/Squidex.Infrastructure.Tests/CQRS/Commands/DefaultDomainObjectFactoryTests.cs index 531a3edef..d2a443dcc 100644 --- a/tests/Squidex.Infrastructure.Tests/CQRS/Commands/DefaultDomainObjectFactoryTests.cs +++ b/tests/Squidex.Infrastructure.Tests/CQRS/Commands/DefaultDomainObjectFactoryTests.cs @@ -52,7 +52,7 @@ namespace Squidex.Infrastructure.CQRS.Commands } [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(); diff --git a/tests/Squidex.Infrastructure.Tests/GuardTests.cs b/tests/Squidex.Infrastructure.Tests/GuardTests.cs index 1c11571bc..8ecd3aec9 100644 --- a/tests/Squidex.Infrastructure.Tests/GuardTests.cs +++ b/tests/Squidex.Infrastructure.Tests/GuardTests.cs @@ -347,13 +347,13 @@ namespace Squidex.Infrastructure } [Fact] - public void Valid_should_throw_if_null() + public void Valid_should_throw_exception_if_null() { Assert.Throws(() => Guard.Valid(null, "Parameter", () => "Message")); } [Fact] - public void Valid_should_throw_if_invalid() + public void Valid_should_throw_exception_if_invalid() { Assert.Throws(() => Guard.Valid(new MyValidatableInvalid(), "Parameter", () => "Message")); } diff --git a/tests/Squidex.Infrastructure.Tests/LanguageTests.cs b/tests/Squidex.Infrastructure.Tests/LanguageTests.cs index 18c3ce24a..1a7e89c3c 100644 --- a/tests/Squidex.Infrastructure.Tests/LanguageTests.cs +++ b/tests/Squidex.Infrastructure.Tests/LanguageTests.cs @@ -19,19 +19,19 @@ namespace Squidex.Infrastructure [Theory] [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(() => Language.GetLanguage(key)); } [Fact] - public void Should_throw_if_getting_by_null_key() + public void Should_throw_exception_if_getting_by_null_key() { Assert.Throws(() => Language.GetLanguage(null)); } [Fact] - public void Should_throw_if_getting_by_unsupported_language() + public void Should_throw_exception_if_getting_by_unsupported_language() { Assert.Throws(() => Language.GetLanguage("xy")); } diff --git a/tests/Squidex.Infrastructure.Tests/NamedIdTest.cs b/tests/Squidex.Infrastructure.Tests/NamedIdTest.cs index 88ec83c87..bb7627835 100644 --- a/tests/Squidex.Infrastructure.Tests/NamedIdTest.cs +++ b/tests/Squidex.Infrastructure.Tests/NamedIdTest.cs @@ -126,20 +126,20 @@ namespace Squidex.Infrastructure } [Fact] - public void Should_throw_if_string_id_is_not_valid() + public void Should_throw_exception_if_string_id_is_not_valid() { JsonHelper.DoesNotDeserialize>("123", new NamedStringIdConverter()); } [Fact] - public void Should_throw_if_long_id_is_not_valid() + public void Should_throw_exception_if_long_id_is_not_valid() { JsonHelper.DoesNotDeserialize>("123", new NamedLongIdConverter()); JsonHelper.DoesNotDeserialize>("invalid-long,name", new NamedLongIdConverter()); } [Fact] - public void Should_throw_if_guid_id_is_not_valid() + public void Should_throw_exception_if_guid_id_is_not_valid() { JsonHelper.DoesNotDeserialize>("123", new NamedGuidIdConverter()); JsonHelper.DoesNotDeserialize>("invalid-guid,name", new NamedGuidIdConverter()); diff --git a/tests/Squidex.Infrastructure.Tests/RefTokenTests.cs b/tests/Squidex.Infrastructure.Tests/RefTokenTests.cs index a727ebfdb..0260cede6 100644 --- a/tests/Squidex.Infrastructure.Tests/RefTokenTests.cs +++ b/tests/Squidex.Infrastructure.Tests/RefTokenTests.cs @@ -22,7 +22,7 @@ namespace Squidex.Infrastructure [InlineData(" ")] [InlineData(":")] [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(() => RefToken.Parse(input)); } diff --git a/tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs b/tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs index 00c6e92d1..1417041bd 100644 --- a/tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs +++ b/tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs @@ -63,13 +63,13 @@ namespace Squidex.Infrastructure.Reflection } [Fact] - public void Should_throw_if_setting_unknown_property() + public void Should_throw_exception_if_setting_unknown_property() { Assert.Throws(() => accessor.SetValue(target, "Unknown", 123)); } [Fact] - public void Should_throw_if_setting_readonly() + public void Should_throw_exception_if_setting_readonly() { Assert.Throws(() => accessor.SetValue(target, "Read", 123)); } @@ -91,13 +91,13 @@ namespace Squidex.Infrastructure.Reflection } [Fact] - public void Should_throw_if_getting_unknown_property() + public void Should_throw_exception_if_getting_unknown_property() { Assert.Throws(() => accessor.GetValue(target, "Unknown")); } [Fact] - public void Should_throw_if_getting_readonly_property() + public void Should_throw_exception_if_getting_readonly_property() { Assert.Throws(() => accessor.GetValue(target, "Write")); } diff --git a/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs b/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs index 67b5a4ac6..0a7dc20ab 100644 --- a/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs +++ b/tests/Squidex.Infrastructure.Tests/Reflection/SimpleMapperTests.cs @@ -61,13 +61,13 @@ namespace Squidex.Infrastructure.Reflection } [Fact] - public void Should_throw_if_mapping_with_null_source() + public void Should_throw_exception_if_mapping_with_null_source() { Assert.Throws(() => SimpleMapper.Map((MyClass1)null, new MyClass2())); } [Fact] - public void Should_throw_if_mapping_with_null_target() + public void Should_throw_exception_if_mapping_with_null_target() { Assert.Throws(() => SimpleMapper.Map(new MyClass1(), (MyClass2)null)); } diff --git a/tests/Squidex.Infrastructure.Tests/TypeNameRegistryTests.cs b/tests/Squidex.Infrastructure.Tests/TypeNameRegistryTests.cs index 3e851e4e7..3f6ab1eea 100644 --- a/tests/Squidex.Infrastructure.Tests/TypeNameRegistryTests.cs +++ b/tests/Squidex.Infrastructure.Tests/TypeNameRegistryTests.cs @@ -58,14 +58,14 @@ namespace Squidex.Infrastructure } [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"); } [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"); @@ -73,7 +73,7 @@ namespace Squidex.Infrastructure } [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"); @@ -81,13 +81,13 @@ namespace Squidex.Infrastructure } [Fact] - public void Should_throw_if_name_is_not_supported() + public void Should_throw_exception_if_name_is_not_supported() { Assert.Throws(() => sut.GetType("unsupported")); } [Fact] - public void Should_throw_if_type_is_not_supported() + public void Should_throw_exception_if_type_is_not_supported() { Assert.Throws(() => sut.GetName()); } diff --git a/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs b/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs index 26e72d4d1..c0091a2bb 100644 --- a/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs +++ b/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs @@ -29,7 +29,7 @@ namespace Squidex.Infrastructure.UsageTracking } [Fact] - public Task Should_throw_if_tracking_on_disposed_object() + public Task Should_throw_exception_if_tracking_on_disposed_object() { sut.Dispose(); @@ -37,7 +37,7 @@ namespace Squidex.Infrastructure.UsageTracking } [Fact] - public Task Should_throw_if_querying_on_disposed_object() + public Task Should_throw_exception_if_querying_on_disposed_object() { sut.Dispose(); @@ -45,7 +45,7 @@ namespace Squidex.Infrastructure.UsageTracking } [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(); diff --git a/tests/Squidex.Read.Tests/MongoDb/Contents/ODataQueryTests.cs b/tests/Squidex.Read.Tests/MongoDb/Contents/ODataQueryTests.cs index 31db38866..73828c0f2 100644 --- a/tests/Squidex.Read.Tests/MongoDb/Contents/ODataQueryTests.cs +++ b/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 schemaEntity = new Mock(); + var schemaEntity = new Mock(); schemaEntity.Setup(x => x.Id).Returns(Guid.NewGuid()); schemaEntity.Setup(x => x.Version).Returns(3); schemaEntity.Setup(x => x.Schema).Returns(schema); diff --git a/tests/Squidex.Read.Tests/Schemas/CachingSchemaProviderTests.cs b/tests/Squidex.Read.Tests/Schemas/CachingSchemaProviderTests.cs index 1041f0400..e3460f3f6 100644 --- a/tests/Squidex.Read.Tests/Schemas/CachingSchemaProviderTests.cs +++ b/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 Mock repository = new Mock(); private readonly CachingSchemaProvider sut; - private readonly ISchemaEntityWithSchema schemaV1; - private readonly ISchemaEntityWithSchema schemaV2; + private readonly ISchemaEntity schemaV1; + private readonly ISchemaEntity schemaV2; private readonly NamedId schemaId = new NamedId(Guid.NewGuid(), "my-schema"); private readonly NamedId appId = new NamedId(Guid.NewGuid(), "my-app"); public CachingSchemaProviderTests() { - var schemaV1Mock = new Mock(); - var schemaV2Mock = new Mock(); + var schemaV1Mock = new Mock(); + var schemaV2Mock = new Mock(); schemaV1Mock.Setup(x => x.Id).Returns(schemaId.Id); 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)); } - private async Task ProvideSchemaById(ISchemaEntityWithSchema schema) + private async Task ProvideSchemaById(ISchemaEntity schema) { 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)); } diff --git a/tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs b/tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs index d4b596cd0..aaee8877e 100644 --- a/tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs +++ b/tests/Squidex.Write.Tests/Apps/AppCommandHandlerTests.cs @@ -48,7 +48,7 @@ namespace Squidex.Write.Apps } [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 }); @@ -82,7 +82,7 @@ namespace Squidex.Write.Apps } [Fact] - public async Task AssignContributor_should_throw_if_user_not_found() + public async Task AssignContributor_should_throw_exception_if_user_not_found() { CreateApp(); @@ -97,7 +97,7 @@ namespace Squidex.Write.Apps } [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 }); @@ -116,7 +116,7 @@ namespace Squidex.Write.Apps } [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(); diff --git a/tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs b/tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs index 5572fd1d0..e09d898b1 100644 --- a/tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs +++ b/tests/Squidex.Write.Tests/Apps/AppDomainObjectTests.cs @@ -35,7 +35,7 @@ namespace Squidex.Write.Apps } [Fact] - public void Create_should_throw_if_created() + public void Create_should_throw_exception_if_created() { CreateApp(); @@ -46,7 +46,7 @@ namespace Squidex.Write.Apps } [Fact] - public void Create_should_throw_if_command_is_not_valid() + public void Create_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -70,7 +70,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AssignContributor_should_throw_if_not_created() + public void AssignContributor_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -79,7 +79,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AssignContributor_should_throw_if_command_is_not_valid() + public void AssignContributor_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -88,7 +88,7 @@ namespace Squidex.Write.Apps } [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(); @@ -99,7 +99,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AssignContributor_should_throw_if_user_already_contributor() + public void AssignContributor_should_throw_exception_if_user_already_contributor() { CreateApp(); sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = PermissionLevel.Editor })); @@ -124,7 +124,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveContributor_should_throw_if_not_created() + public void RemoveContributor_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -133,7 +133,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveContributor_should_throw_if_command_is_not_valid() + public void RemoveContributor_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -142,7 +142,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveContributor_should_throw_if_all_owners_removed() + public void RemoveContributor_should_throw_exception_if_all_owners_removed() { CreateApp(); @@ -153,7 +153,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveContributor_should_throw_if_contributor_not_found() + public void RemoveContributor_should_throw_exception_if_contributor_not_found() { CreateApp(); @@ -178,7 +178,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AttachClient_should_throw_if_not_created() + public void AttachClient_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -187,7 +187,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AttachClient_should_throw_if_command_is_not_valid() + public void AttachClient_should_throw_exception_if_command_is_not_valid() { CreateApp(); @@ -203,7 +203,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AttachClient_should_throw_if_id_already_exists() + public void AttachClient_should_throw_exception_if_id_already_exists() { CreateApp(); @@ -229,7 +229,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RevokeClient_should_throw_if_not_created() + public void RevokeClient_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -238,7 +238,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RevokeClient_should_throw_if_command_is_not_valid() + public void RevokeClient_should_throw_exception_if_command_is_not_valid() { CreateApp(); @@ -254,7 +254,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RevokeClient_should_throw_if_client_not_found() + public void RevokeClient_should_throw_exception_if_client_not_found() { CreateApp(); @@ -279,7 +279,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RenameClient_should_throw_if_not_created() + public void RenameClient_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -288,7 +288,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RenameClient_should_throw_if_command_is_not_valid() + public void RenameClient_should_throw_exception_if_command_is_not_valid() { CreateApp(); @@ -304,7 +304,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RenameClient_should_throw_if_client_not_found() + public void RenameClient_should_throw_exception_if_client_not_found() { CreateApp(); @@ -315,7 +315,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RenameClient_should_throw_if_same_client_name() + public void RenameClient_should_throw_exception_if_same_client_name() { CreateApp(); CreateClient(); @@ -343,7 +343,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AddLanguage_should_throw_if_not_created() + public void AddLanguage_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -352,7 +352,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AddLanguage_should_throw_if_command_is_not_valid() + public void AddLanguage_should_throw_exception_if_command_is_not_valid() { CreateApp(); @@ -363,7 +363,7 @@ namespace Squidex.Write.Apps } [Fact] - public void AddLanguage_should_throw_if_language_already_exists() + public void AddLanguage_should_throw_exception_if_language_already_exists() { CreateApp(); @@ -387,7 +387,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveLanguage_should_throw_if_not_created() + public void RemoveLanguage_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -396,7 +396,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveLanguage_should_throw_if_command_is_not_valid() + public void RemoveLanguage_should_throw_exception_if_command_is_not_valid() { CreateApp(); @@ -407,7 +407,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveLanguage_should_throw_if_language_not_found() + public void RemoveLanguage_should_throw_exception_if_language_not_found() { CreateApp(); @@ -418,7 +418,7 @@ namespace Squidex.Write.Apps } [Fact] - public void RemoveLanguage_should_throw_if_master_language() + public void RemoveLanguage_should_throw_exception_if_master_language() { CreateApp(); @@ -443,7 +443,7 @@ namespace Squidex.Write.Apps } [Fact] - public void UpdateLanguage_should_throw_if_not_created() + public void UpdateLanguage_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -452,7 +452,7 @@ namespace Squidex.Write.Apps } [Fact] - public void UpdateLanguage_should_throw_if_command_is_not_valid() + public void UpdateLanguage_should_throw_exception_if_command_is_not_valid() { CreateApp(); @@ -463,7 +463,7 @@ namespace Squidex.Write.Apps } [Fact] - public void UpdateLanguage_should_throw_if_language_not_found() + public void UpdateLanguage_should_throw_exception_if_language_not_found() { CreateApp(); @@ -474,7 +474,7 @@ namespace Squidex.Write.Apps } [Fact] - public void UpdateLanguage_should_throw_if_master_language() + public void UpdateLanguage_should_throw_exception_if_master_language() { CreateApp(); diff --git a/tests/Squidex.Write.Tests/Assets/AssetDomainObjectTests.cs b/tests/Squidex.Write.Tests/Assets/AssetDomainObjectTests.cs index f0f12aa01..823767b78 100644 --- a/tests/Squidex.Write.Tests/Assets/AssetDomainObjectTests.cs +++ b/tests/Squidex.Write.Tests/Assets/AssetDomainObjectTests.cs @@ -34,7 +34,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Create_should_throw_if_created() + public void Create_should_throw_exception_if_created() { sut.Create(new CreateAsset { File = file }); @@ -65,7 +65,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Update_should_throw_if_not_created() + public void Update_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -74,7 +74,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Update_should_throw_if_asset_is_deleted() + public void Update_should_throw_exception_if_asset_is_deleted() { CreateAsset(); DeleteAsset(); @@ -107,7 +107,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Rename_should_throw_if_not_created() + public void Rename_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -116,7 +116,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Rename_should_throw_if_asset_is_deleted() + public void Rename_should_throw_exception_if_asset_is_deleted() { CreateAsset(); DeleteAsset(); @@ -128,7 +128,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Rename_should_throw_if_command_is_not_valid() + public void Rename_should_throw_exception_if_command_is_not_valid() { CreateAsset(); @@ -139,7 +139,7 @@ namespace Squidex.Write.Assets } [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(); @@ -163,7 +163,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Delete_should_throw_if_not_created() + public void Delete_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -172,7 +172,7 @@ namespace Squidex.Write.Assets } [Fact] - public void Delete_should_throw_if_already_deleted() + public void Delete_should_throw_exception_if_already_deleted() { CreateAsset(); DeleteAsset(); diff --git a/tests/Squidex.Write.Tests/Contents/ContentCommandHandlerTests.cs b/tests/Squidex.Write.Tests/Contents/ContentCommandHandlerTests.cs index 99a23e5a0..5f4c23a82 100644 --- a/tests/Squidex.Write.Tests/Contents/ContentCommandHandlerTests.cs +++ b/tests/Squidex.Write.Tests/Contents/ContentCommandHandlerTests.cs @@ -32,7 +32,7 @@ namespace Squidex.Write.Contents private readonly ContentDomainObject content; private readonly Mock schemaProvider = new Mock(); private readonly Mock appProvider = new Mock(); - private readonly Mock schemaEntity = new Mock(); + private readonly Mock schemaEntity = new Mock(); private readonly Mock appEntity = new Mock(); private readonly ContentData data = new ContentData().AddField("my-field", new ContentFieldData().SetValue(1)); private readonly LanguagesConfig languagesConfig = LanguagesConfig.Create(Language.DE); diff --git a/tests/Squidex.Write.Tests/Contents/ContentDomainObjectTests.cs b/tests/Squidex.Write.Tests/Contents/ContentDomainObjectTests.cs index 14610e0fc..da80b5134 100644 --- a/tests/Squidex.Write.Tests/Contents/ContentDomainObjectTests.cs +++ b/tests/Squidex.Write.Tests/Contents/ContentDomainObjectTests.cs @@ -42,7 +42,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Create_should_throw_if_created() + public void Create_should_throw_exception_if_created() { sut.Create(new CreateContent { Data = data }); @@ -53,7 +53,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Create_should_throw_if_command_is_not_valid() + public void Create_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -85,7 +85,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Update_should_throw_if_not_created() + public void Update_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -94,7 +94,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Update_should_throw_if_content_is_deleted() + public void Update_should_throw_exception_if_content_is_deleted() { CreateContent(); DeleteContent(); @@ -106,7 +106,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Update_should_throw_if_command_is_not_valid() + public void Update_should_throw_exception_if_command_is_not_valid() { CreateContent(); @@ -141,7 +141,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Patch_should_throw_if_not_created() + public void Patch_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -150,7 +150,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Patch_should_throw_if_content_is_deleted() + public void Patch_should_throw_exception_if_content_is_deleted() { CreateContent(); DeleteContent(); @@ -162,7 +162,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Patch_should_throw_if_command_is_not_valid() + public void Patch_should_throw_exception_if_command_is_not_valid() { CreateContent(); @@ -197,7 +197,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Publish_should_throw_if_not_created() + public void Publish_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -206,7 +206,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Publish_should_throw_if_content_is_deleted() + public void Publish_should_throw_exception_if_content_is_deleted() { CreateContent(); DeleteContent(); @@ -233,7 +233,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Unpublish_should_throw_if_not_created() + public void Unpublish_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -242,7 +242,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Unpublish_should_throw_if_content_is_deleted() + public void Unpublish_should_throw_exception_if_content_is_deleted() { CreateContent(); DeleteContent(); @@ -270,7 +270,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Delete_should_throw_if_not_created() + public void Delete_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -279,7 +279,7 @@ namespace Squidex.Write.Contents } [Fact] - public void Delete_should_throw_if_already_deleted() + public void Delete_should_throw_exception_if_already_deleted() { CreateContent(); DeleteContent(); diff --git a/tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs b/tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs index 08e8f91af..50a38d209 100644 --- a/tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs +++ b/tests/Squidex.Write.Tests/Schemas/SchemaCommandHandlerTests.cs @@ -39,12 +39,12 @@ namespace Squidex.Write.Schemas } [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 }); schemaProvider.Setup(x => x.FindSchemaByNameAsync(AppId, SchemaName)) - .Returns(Task.FromResult(new Mock().Object)) + .Returns(Task.FromResult(new Mock().Object)) .Verifiable(); await TestCreate(schema, async _ => @@ -61,7 +61,7 @@ namespace Squidex.Write.Schemas var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId }); schemaProvider.Setup(x => x.FindSchemaByNameAsync(AppId, SchemaName)) - .Returns(Task.FromResult(null)) + .Returns(Task.FromResult(null)) .Verifiable(); await TestCreate(schema, async _ => diff --git a/tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs b/tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs index 733e29dfc..648df7c5c 100644 --- a/tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs +++ b/tests/Squidex.Write.Tests/Schemas/SchemaDomainObjectTests.cs @@ -37,7 +37,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Create_should_throw_if_created() + public void Create_should_throw_exception_if_created() { sut.Create(new CreateSchema { Name = SchemaName }); @@ -48,7 +48,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Create_should_throw_if_command_is_not_valid() + public void Create_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -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 + { + new CreateSchemaField + { + Name = null, + Properties = null, + Partitioning = "invalid" + } + }; + + Assert.Throws(() => + { + sut.Create(CreateCommand(new CreateSchema { Name = SchemaName, Properties = properties, Fields = fields })); + }); + } + [Fact] public void Create_should_create_schema_and_create_events() { @@ -67,12 +88,31 @@ namespace Squidex.Write.Schemas sut.GetUncomittedEvents() .ShouldHaveSameEvents( - CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties }) + CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties, Fields = new List() }) ); } [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 + { + 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(() => { @@ -81,7 +121,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Update_should_throw_if_schema_is_deleted() + public void Update_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -93,7 +133,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Update_should_throw_if_command_is_not_valid() + public void Update_should_throw_exception_if_command_is_not_valid() { CreateSchema(); @@ -121,7 +161,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Reorder_should_throw_if_not_created() + public void Reorder_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -130,7 +170,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Reorder_should_throw_if_schema_is_deleted() + public void Reorder_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -142,7 +182,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Reorder_should_throw_if_command_is_not_valid() + public void Reorder_should_throw_exception_if_command_is_not_valid() { CreateSchema(); @@ -173,7 +213,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Publish_should_throw_if_not_created() + public void Publish_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -182,7 +222,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Publish_should_throw_if_schema_is_deleted() + public void Publish_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -209,7 +249,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Unpublish_should_throw_if_not_created() + public void Unpublish_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -218,7 +258,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Unpublish_should_throw_if_schema_is_deleted() + public void Unpublish_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -246,7 +286,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Delete_should_throw_if_not_created() + public void Delete_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -255,7 +295,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void Delete_should_throw_if_already_deleted() + public void Delete_should_throw_exception_if_already_deleted() { CreateSchema(); DeleteSchema(); @@ -282,7 +322,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void AddField_should_throw_if_not_created() + public void AddField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -291,7 +331,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void AddField_should_throw_if_command_is_not_valid() + public void AddField_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -300,7 +340,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void AddField_should_throw_if_command_contains_invalid_partitioning() + public void AddField_should_throw_exception_if_command_contains_invalid_partitioning() { Assert.Throws(() => { @@ -309,7 +349,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void AddField_should_throw_if_schema_is_deleted() + public void AddField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -338,7 +378,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void UpdateField_should_throw_if_not_created() + public void UpdateField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -347,7 +387,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void UpdateField_should_throw_if_command_is_not_valid() + public void UpdateField_should_throw_exception_if_command_is_not_valid() { Assert.Throws(() => { @@ -356,7 +396,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void UpdateField_should_throw_if_field_is_not_found() + public void UpdateField_should_throw_exception_if_field_is_not_found() { CreateSchema(); @@ -367,7 +407,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void UpdateField_should_throw_if_schema_is_deleted() + public void UpdateField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -397,7 +437,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void HideField_should_throw_if_not_created() + public void HideField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -406,7 +446,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void HideField_should_throw_if_field_is_not_found() + public void HideField_should_throw_exception_if_field_is_not_found() { CreateSchema(); @@ -417,7 +457,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void HideField_should_throw_if_schema_is_deleted() + public void HideField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -445,7 +485,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void ShowField_should_throw_if_not_created() + public void ShowField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -454,7 +494,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void ShowField_should_throw_if_field_is_not_found() + public void ShowField_should_throw_exception_if_field_is_not_found() { CreateSchema(); @@ -465,7 +505,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void ShowField_should_throw_if_schema_is_deleted() + public void ShowField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -494,7 +534,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void DisableField_should_throw_if_not_created() + public void DisableField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -503,7 +543,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void DisableField_should_throw_if_field_is_not_found() + public void DisableField_should_throw_exception_if_field_is_not_found() { CreateSchema(); @@ -514,7 +554,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void DisableField_should_throw_if_schema_is_deleted() + public void DisableField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -542,7 +582,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void EnableField_should_throw_if_not_created() + public void EnableField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -551,7 +591,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void EnableField_should_throw_if_field_is_not_found() + public void EnableField_should_throw_exception_if_field_is_not_found() { CreateSchema(); @@ -562,7 +602,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void EnableField_should_throw_if_schema_is_deleted() + public void EnableField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema(); @@ -591,7 +631,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void DeleteField_should_throw_if_not_created() + public void DeleteField_should_throw_exception_if_not_created() { Assert.Throws(() => { @@ -600,7 +640,7 @@ namespace Squidex.Write.Schemas } [Fact] - public void DeleteField_should_throw_if_schema_is_deleted() + public void DeleteField_should_throw_exception_if_schema_is_deleted() { CreateSchema(); DeleteSchema();