Browse Source

Import feature

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

2
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<IMongoCollection<MongoContentEntity>, ISchemaEntityWithSchema, Task> action)
private async Task ForSchemaAsync(Guid schemaId, Func<IMongoCollection<MongoContentEntity>, ISchemaEntity, Task> action)
{
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
{
public sealed class MongoSchemaEntity : MongoEntity, ISchemaEntityWithSchema
public sealed class MongoSchemaEntity : MongoEntity, ISchemaEntity
{
private Lazy<Schema> 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<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();
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));
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 =
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<ISchemaEntityWithSchema> FindSchemaAsync(Guid schemaId)
public async Task<ISchemaEntity> FindSchemaAsync(Guid schemaId)
{
var entity =
await Collection.Find(s => s.Id == schemaId)

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));

6
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; }
}
}

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<ISchemaEntityWithSchema>> QueryAllWithSchemaAsync(Guid appId);
Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name);
Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid appId, string name);
Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid schemaId);
Task<ISchemaEntity> FindSchemaAsync(Guid schemaId);
}
}

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

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

36
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);
}
}
}
}

45
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<FieldDto>();
@ -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());

11
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; }
/// <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; }
/// <summary>
/// Optional label for the editor.
/// The schema properties.
/// </summary>
[StringLength(100)]
public string Label { get; set; }
/// <summary>
/// Hints to describe the schema.
/// </summary>
[StringLength(1000)]
public string Hints { get; set; }
[Required]
public SchemaPropertiesDto Properties { get; set; }
/// <summary>
/// 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; }
/// <summary>
/// Optional label for the editor.
/// The schema properties.
/// </summary>
[StringLength(100)]
public string Label { get; set; }
[Required]
public SchemaPropertiesDto Properties { get; set; }
/// <summary>
/// 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 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<IActionResult> PostSchema(string app, [FromBody] CreateSchemaDto request)
{
var command = SimpleMapper.Map(request, new CreateSchema());
var command = request.ToCommand();
await CommandBus.PublishAsync(command);

2
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);

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

@ -61,7 +61,7 @@ namespace Squidex.Controllers.ContentApi.Generator
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;
@ -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))
{

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">
<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>
<span class="field-disabled" *ngIf="field.isDisabled">Disabled</span>
@ -12,7 +12,7 @@
<div *ngFor="let partition of fieldPartitions">
<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 *ngSwitchCase="'Number'">

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

@ -44,7 +44,7 @@
<thead>
<tr>
<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>
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">
<li class="nav-item" *ngFor="let schema of schemasFiltered | async">
<a class="nav-link" [routerLink]="[schema.name]" routerLinkActive="active">
{{schema|displayName}}
{{schema | displayName}}
<i class="icon-angle-right"></i>
</a>
</li>

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

@ -5,10 +5,12 @@
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { SchemaPropertiesDto } from 'shared';
export class SchemaUpdated {
constructor(
public readonly name: string,
public readonly label: string,
public readonly properties: SchemaPropertiesDto,
public readonly isPublished: boolean,
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">
<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 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 {
Notification,
NotificationService,
SchemaPropertiesDto,
SchemasService,
Version
} from 'shared';
import { SchemaPropertiesDto } from './schema-properties';
@Component({
selector: 'sqx-schema-edit-form',
styleUrls: ['./schema-edit-form.component.scss'],
@ -30,7 +29,10 @@ export class SchemaEditFormComponent implements OnInit {
public cancelled = new EventEmitter();
@Input()
public schema: SchemaPropertiesDto;
public name: string;
@Input()
public properties: SchemaPropertiesDto;
@Input()
public version: Version;
@ -41,7 +43,6 @@ export class SchemaEditFormComponent implements OnInit {
public editFormSubmitted = false;
public editForm: FormGroup =
this.formBuilder.group({
name: '',
label: ['',
[
Validators.maxLength(100)
@ -60,7 +61,7 @@ export class SchemaEditFormComponent implements OnInit {
}
public ngOnInit() {
this.editForm.patchValue(this.schema);
this.editForm.patchValue(this.properties);
}
public cancel() {
@ -76,10 +77,10 @@ export class SchemaEditFormComponent implements OnInit {
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 => {
this.reset();
this.saved.emit(new SchemaPropertiesDto(this.schema.name, requestDto.label, requestDto.hints));
this.saved.emit(new SchemaPropertiesDto(requestDto.label, requestDto.hints));
}, error => {
this.editForm.enable();
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="float-right">
<button type="button" class="btn btn-link btn-sm btn-export" (click)="exportSchemaDialog.show()">
Export
JSON
</button>
<div class="btn-group btn-group-sm" data-toggle="buttons">
@ -30,7 +30,7 @@
</div>
<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>
</div>
@ -132,7 +132,7 @@
</div>
<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>

20
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<FieldDto>();
public schemaName: string;
public schemaProperties: SchemaPropertiesDto;
public schemaFields = ImmutableArray.empty<FieldDto>();
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));
}
}

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>
</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">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</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 '_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 {
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);
}
}

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">
<div class="row">
<div class="col col-4">
<span class="schema-name">{{schema|displayName}}</span>
<span class="schema-name">{{schema | displayName:'properties.label':'name'}}</span>
</div>
<div class="col col-4">
<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(
schema.id,
schema.name,
message.label,
message.properties,
message.isPublished,
schema.createdBy, me,
schema.created, DateTime.now(),

23
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'),

24
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,

2
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<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]
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()));
}
@ -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<DomainObjectNotFoundException>(() => 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<DomainObjectNotFoundException>(() => 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<DomainObjectNotFoundException>(() => 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<DomainObjectNotFoundException>(() => 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<DomainObjectNotFoundException>(() => 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<DomainObjectNotFoundException>(() => 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<DomainException>(() => 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);

4
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<ArgumentException>(() => sut.CreateAsync<MyDomainObject>(new CommandContext(new Mock<ICommand>().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<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]
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>();

4
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<ArgumentNullException>(() => Guard.Valid(null, "Parameter", () => "Message"));
}
[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"));
}

6
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<ArgumentException>(() => 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<ArgumentNullException>(() => 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<NotSupportedException>(() => Language.GetLanguage("xy"));
}

6
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<NamedId<string>>("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<NamedId<long>>("123", new NamedLongIdConverter());
JsonHelper.DoesNotDeserialize<NamedId<long>>("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<NamedId<Guid>>("123", 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("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));
}

8
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<ArgumentException>(() => accessor.SetValue(target, "Unknown", 123));
}
[Fact]
public void Should_throw_if_setting_readonly()
public void Should_throw_exception_if_setting_readonly()
{
Assert.Throws<NotSupportedException>(() => 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<ArgumentException>(() => accessor.GetValue(target, "Unknown"));
}
[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"));
}

4
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<ArgumentNullException>(() => 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<ArgumentNullException>(() => SimpleMapper.Map(new MyClass1(), (MyClass2)null));
}

10
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<TypeNameNotFoundException>(() => 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<TypeNameNotFoundException>(() => sut.GetName<Guid>());
}

6
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();

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 schemaEntity = new Mock<ISchemaEntityWithSchema>();
var schemaEntity = new Mock<ISchemaEntity>();
schemaEntity.Setup(x => x.Id).Returns(Guid.NewGuid());
schemaEntity.Setup(x => x.Version).Returns(3);
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 Mock<ISchemaRepository> repository = new Mock<ISchemaRepository>();
private readonly CachingSchemaProvider sut;
private readonly ISchemaEntityWithSchema schemaV1;
private readonly ISchemaEntityWithSchema schemaV2;
private readonly ISchemaEntity schemaV1;
private readonly ISchemaEntity schemaV2;
private readonly NamedId<Guid> schemaId = new NamedId<Guid>(Guid.NewGuid(), "my-schema");
private readonly NamedId<Guid> appId = new NamedId<Guid>(Guid.NewGuid(), "my-app");
public CachingSchemaProviderTests()
{
var schemaV1Mock = new Mock<ISchemaEntityWithSchema>();
var schemaV2Mock = new Mock<ISchemaEntityWithSchema>();
var schemaV1Mock = new Mock<ISchemaEntity>();
var schemaV2Mock = new Mock<ISchemaEntity>();
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));
}

8
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();

62
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<ValidationException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<ValidationException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<ValidationException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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();

18
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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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();

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

@ -32,7 +32,7 @@ namespace Squidex.Write.Contents
private readonly ContentDomainObject content;
private readonly Mock<ISchemaProvider> schemaProvider = new Mock<ISchemaProvider>();
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 ContentData data = new ContentData().AddField("my-field", new ContentFieldData().SetValue(1));
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]
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<ValidationException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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();

6
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<ISchemaEntityWithSchema>().Object))
.Returns(Task.FromResult(new Mock<ISchemaEntity>().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<ISchemaEntityWithSchema>(null))
.Returns(Task.FromResult<ISchemaEntity>(null))
.Verifiable();
await TestCreate(schema, async _ =>

114
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<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]
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<SchemaCreatedField>() })
);
}
[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>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<ValidationException>(() =>
{
@ -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<ValidationException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<ValidationException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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<DomainException>(() =>
{
@ -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();

Loading…
Cancel
Save