diff --git a/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj b/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj index 33909b134..452047bfa 100644 --- a/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj +++ b/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 Squidex.Domain.Apps.Core @@ -8,10 +8,10 @@ True - - + + - + diff --git a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index 2178c9023..a109f585f 100644 --- a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 Squidex.Domain.Apps.Core @@ -14,18 +14,18 @@ - - + + - - + + - - + + ..\..\Squidex.ruleset diff --git a/src/Squidex.Domain.Apps.Core/Apps/AppClientPermission.cs b/src/Squidex.Domain.Apps.Core/Apps/AppClientPermission.cs deleted file mode 100644 index 33749b3e1..000000000 --- a/src/Squidex.Domain.Apps.Core/Apps/AppClientPermission.cs +++ /dev/null @@ -1,16 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Apps -{ - public enum AppClientPermission - { - Developer, - Editor, - Reader - } -} diff --git a/src/Squidex.Domain.Apps.Core/Apps/AppContributorPermission.cs b/src/Squidex.Domain.Apps.Core/Apps/AppContributorPermission.cs deleted file mode 100644 index a1916542f..000000000 --- a/src/Squidex.Domain.Apps.Core/Apps/AppContributorPermission.cs +++ /dev/null @@ -1,16 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Apps -{ - public enum AppContributorPermission - { - Owner, - Developer, - Editor - } -} diff --git a/src/Squidex.Domain.Apps.Core/Apps/AppPermission.cs b/src/Squidex.Domain.Apps.Core/Apps/AppPermission.cs deleted file mode 100644 index db1c13474..000000000 --- a/src/Squidex.Domain.Apps.Core/Apps/AppPermission.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Apps -{ - public enum AppPermission - { - Owner, - Developer, - Editor, - Reader - } -} diff --git a/src/Squidex.Domain.Apps.Core/Apps/RoleExtension.cs b/src/Squidex.Domain.Apps.Core/Apps/RoleExtension.cs deleted file mode 100644 index 4a92c3cf9..000000000 --- a/src/Squidex.Domain.Apps.Core/Apps/RoleExtension.cs +++ /dev/null @@ -1,29 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Apps -{ - public static class RoleExtension - { - public static AppPermission ToAppPermission(this AppClientPermission clientPermission) - { - Guard.Enum(clientPermission, nameof(clientPermission)); - - return (AppPermission)Enum.Parse(typeof(AppPermission), clientPermission.ToString()); - } - - public static AppPermission ToAppPermission(this AppContributorPermission contributorPermission) - { - Guard.Enum(contributorPermission, nameof(contributorPermission)); - - return (AppPermission)Enum.Parse(typeof(AppPermission), contributorPermission.ToString()); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/ContentEnricher.cs b/src/Squidex.Domain.Apps.Core/ContentEnricher.cs deleted file mode 100644 index c2d117770..000000000 --- a/src/Squidex.Domain.Apps.Core/ContentEnricher.cs +++ /dev/null @@ -1,71 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Squidex.Domain.Apps.Core.Contents; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core -{ - public sealed class ContentEnricher - { - private readonly Schema schema; - private readonly PartitionResolver partitionResolver; - - public ContentEnricher(Schema schema, PartitionResolver partitionResolver) - { - Guard.NotNull(schema, nameof(schema)); - Guard.NotNull(partitionResolver, nameof(partitionResolver)); - - this.schema = schema; - - this.partitionResolver = partitionResolver; - } - - public void Enrich(ContentData data) - { - Guard.NotNull(data, nameof(data)); - - foreach (var field in schema.Fields) - { - var fieldKey = data.GetKey(field); - var fieldData = data.GetOrCreate(fieldKey, k => new ContentFieldData()); - var fieldPartition = partitionResolver(field.Partitioning); - - foreach (var partitionItem in fieldPartition) - { - Enrich(field, fieldData, partitionItem); - } - - if (fieldData.Count > 0) - { - data[fieldKey] = fieldData; - } - } - } - - private static void Enrich(Field field, ContentFieldData fieldData, IFieldPartitionItem partitionItem) - { - Guard.NotNull(fieldData, nameof(fieldData)); - - var defaultValue = field.RawProperties.GetDefaultValue(); - - if (field.RawProperties.IsRequired || defaultValue.IsNull()) - { - return; - } - - var key = partitionItem.Key; - - if (!fieldData.TryGetValue(key, out var value) || field.RawProperties.ShouldApplyDefaultValue(value)) - { - fieldData.AddValue(key, defaultValue); - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/ContentExtensions.cs b/src/Squidex.Domain.Apps.Core/ContentExtensions.cs deleted file mode 100644 index 4d0a78900..000000000 --- a/src/Squidex.Domain.Apps.Core/ContentExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Threading.Tasks; -using Squidex.Domain.Apps.Core.Contents; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core -{ - public static class ContentExtensions - { - public static void Enrich(this ContentData data, Schema schema, PartitionResolver partitionResolver) - { - var enricher = new ContentEnricher(schema, partitionResolver); - - enricher.Enrich(data); - } - - public static async Task ValidateAsync(this NamedContentData data, ValidationContext context, Schema schema, PartitionResolver partitionResolver, IList errors) - { - var validator = new ContentValidator(schema, partitionResolver, context); - - await validator.ValidateAsync(data); - - foreach (var error in validator.Errors) - { - errors.Add(error); - } - } - - public static async Task ValidatePartialAsync(this NamedContentData data, ValidationContext context, Schema schema, PartitionResolver partitionResolver, IList errors) - { - var validator = new ContentValidator(schema, partitionResolver, context); - - await validator.ValidatePartialAsync(data); - - foreach (var error in validator.Errors) - { - errors.Add(error); - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/ContentValidator.cs b/src/Squidex.Domain.Apps.Core/ContentValidator.cs deleted file mode 100644 index 5e752e541..000000000 --- a/src/Squidex.Domain.Apps.Core/ContentValidator.cs +++ /dev/null @@ -1,141 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading.Tasks; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Contents; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; - -#pragma warning disable 168 - -namespace Squidex.Domain.Apps.Core -{ - public sealed class ContentValidator - { - private readonly Schema schema; - private readonly PartitionResolver partitionResolver; - private readonly ValidationContext context; - private readonly ConcurrentBag errors = new ConcurrentBag(); - - public IReadOnlyCollection Errors - { - get { return errors; } - } - - public ContentValidator(Schema schema, PartitionResolver partitionResolver, ValidationContext context) - { - Guard.NotNull(schema, nameof(schema)); - Guard.NotNull(partitionResolver, nameof(partitionResolver)); - - this.schema = schema; - this.context = context; - this.partitionResolver = partitionResolver; - } - - public Task ValidatePartialAsync(NamedContentData data) - { - Guard.NotNull(data, nameof(data)); - - var tasks = new List(); - - foreach (var fieldData in data) - { - var fieldName = fieldData.Key; - - if (!schema.FieldsByName.TryGetValue(fieldData.Key, out var field)) - { - errors.AddError(" is not a known field.", fieldName); - } - else - { - tasks.Add(ValidateFieldPartialAsync(field, fieldData.Value)); - } - } - - return Task.WhenAll(tasks); - } - - private Task ValidateFieldPartialAsync(Field field, ContentFieldData fieldData) - { - var partitioning = field.Partitioning; - var partition = partitionResolver(partitioning); - - var tasks = new List(); - - foreach (var partitionValues in fieldData) - { - if (partition.TryGetItem(partitionValues.Key, out var item)) - { - tasks.Add(field.ValidateAsync(partitionValues.Value, context.Optional(item.IsOptional), m => errors.AddError(m, field, item))); - } - else - { - errors.AddError($" has an unsupported {partitioning.Key} value '{partitionValues.Key}'.", field); - } - } - - return Task.WhenAll(tasks); - } - - public Task ValidateAsync(NamedContentData data) - { - Guard.NotNull(data, nameof(data)); - - ValidateUnknownFields(data); - - var tasks = new List(); - - foreach (var field in schema.FieldsByName.Values) - { - var fieldData = data.GetOrCreate(field.Name, k => new ContentFieldData()); - - tasks.Add(ValidateFieldAsync(field, fieldData)); - } - - return Task.WhenAll(tasks); - } - - private void ValidateUnknownFields(NamedContentData data) - { - foreach (var fieldData in data) - { - if (!schema.FieldsByName.ContainsKey(fieldData.Key)) - { - errors.AddError(" is not a known field.", fieldData.Key); - } - } - } - - private Task ValidateFieldAsync(Field field, ContentFieldData fieldData) - { - var partitioning = field.Partitioning; - var partition = partitionResolver(partitioning); - - var tasks = new List(); - - foreach (var partitionValues in fieldData) - { - if (!partition.TryGetItem(partitionValues.Key, out var _)) - { - errors.AddError($" has an unsupported {partitioning.Key} value '{partitionValues.Key}'.", field); - } - } - - foreach (var item in partition) - { - var value = fieldData.GetOrCreate(item.Key, k => JValue.CreateNull()); - - tasks.Add(field.ValidateAsync(value, context.Optional(item.IsOptional), m => errors.AddError(m, field, item))); - } - - return Task.WhenAll(tasks); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Contents/ContentData.cs b/src/Squidex.Domain.Apps.Core/Contents/ContentData.cs deleted file mode 100644 index 595c6139b..000000000 --- a/src/Squidex.Domain.Apps.Core/Contents/ContentData.cs +++ /dev/null @@ -1,122 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Linq; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core.Contents -{ - public abstract class ContentData : Dictionary, IEquatable> - { - public IEnumerable> ValidValues - { - get { return this.Where(x => x.Value != null); } - } - - protected ContentData(IEqualityComparer comparer) - : base(comparer) - { - } - - protected ContentData(IDictionary copy, IEqualityComparer comparer) - : base(copy, comparer) - { - } - - protected static TResult Merge(TResult source, TResult target) where TResult : ContentData - { - if (ReferenceEquals(target, source)) - { - return source; - } - - foreach (var otherValue in source) - { - var fieldValue = target.GetOrAdd(otherValue.Key, x => new ContentFieldData()); - - foreach (var value in otherValue.Value) - { - fieldValue[value.Key] = value.Value; - } - } - - return target; - } - - protected static TResult Clean(TResult source, TResult target) where TResult : ContentData - { - foreach (var fieldValue in source.ValidValues) - { - var resultValue = new ContentFieldData(); - - foreach (var partitionValue in fieldValue.Value.Where(x => !x.Value.IsNull())) - { - resultValue[partitionValue.Key] = partitionValue.Value; - } - - if (resultValue.Count > 0) - { - target[fieldValue.Key] = resultValue; - } - } - - return target; - } - - public IEnumerable GetReferencedIds(Schema schema) - { - Guard.NotNull(schema, nameof(schema)); - - var foundReferences = new HashSet(); - - foreach (var field in schema.Fields) - { - if (field is IReferenceField referenceField) - { - var fieldKey = GetKey(field); - var fieldData = this.GetOrDefault(fieldKey); - - if (fieldData == null) - { - continue; - } - - foreach (var partitionValue in fieldData.Where(x => x.Value != null)) - { - var ids = referenceField.GetReferencedIds(partitionValue.Value); - - foreach (var id in ids.Where(x => foundReferences.Add(x))) - { - yield return id; - } - } - } - } - } - - public override bool Equals(object obj) - { - return Equals(obj as ContentData); - } - - public bool Equals(ContentData other) - { - return other != null && (ReferenceEquals(this, other) || this.EqualsDictionary(other)); - } - - public override int GetHashCode() - { - return this.DictionaryHashCode(); - } - - public abstract T GetKey(Field field); - } -} diff --git a/src/Squidex.Domain.Apps.Core/Contents/ContentFieldData.cs b/src/Squidex.Domain.Apps.Core/Contents/ContentFieldData.cs deleted file mode 100644 index b1ba92b7e..000000000 --- a/src/Squidex.Domain.Apps.Core/Contents/ContentFieldData.cs +++ /dev/null @@ -1,55 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Contents -{ - public sealed class ContentFieldData : Dictionary, IEquatable - { - private static readonly JTokenEqualityComparer JTokenEqualityComparer = new JTokenEqualityComparer(); - - public ContentFieldData() - : base(StringComparer.OrdinalIgnoreCase) - { - } - - public ContentFieldData SetValue(JToken value) - { - this[InvariantPartitioning.Instance.Master.Key] = value; - - return this; - } - - public ContentFieldData AddValue(string key, JToken value) - { - Guard.NotNullOrEmpty(key, nameof(key)); - - this[key] = value; - - return this; - } - - public override bool Equals(object obj) - { - return Equals(obj as ContentFieldData); - } - - public bool Equals(ContentFieldData other) - { - return other != null && (ReferenceEquals(this, other) || this.EqualsDictionary(other, EqualityComparer.Default, JTokenEqualityComparer)); - } - - public override int GetHashCode() - { - return this.DictionaryHashCode(EqualityComparer.Default, JTokenEqualityComparer); - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Contents/IdContentData.cs b/src/Squidex.Domain.Apps.Core/Contents/IdContentData.cs deleted file mode 100644 index 3c1c5ca57..000000000 --- a/src/Squidex.Domain.Apps.Core/Contents/IdContentData.cs +++ /dev/null @@ -1,130 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core.Contents -{ - public sealed class IdContentData : ContentData, IEquatable - { - public IdContentData() - : base(EqualityComparer.Default) - { - } - - public IdContentData(IdContentData copy) - : base(copy, EqualityComparer.Default) - { - } - - public IdContentData MergeInto(IdContentData target) - { - return Merge(this, target); - } - - public IdContentData ToCleaned() - { - return Clean(this, new IdContentData()); - } - - public IdContentData AddField(long id, ContentFieldData data) - { - Guard.GreaterThan(id, 0, nameof(id)); - - this[id] = data; - - return this; - } - - public IdContentData ToCleanedReferences(Schema schema, ISet deletedReferencedIds) - { - var result = new IdContentData(this); - - foreach (var field in schema.Fields) - { - if (field is IReferenceField referenceField) - { - var fieldKey = GetKey(field); - var fieldData = this.GetOrDefault(fieldKey); - - if (fieldData == null) - { - continue; - } - - foreach (var partitionValue in fieldData.Where(x => !x.Value.IsNull()).ToList()) - { - var newValue = referenceField.RemoveDeletedReferences(partitionValue.Value, deletedReferencedIds); - - fieldData[partitionValue.Key] = newValue; - } - } - } - - return result; - } - - public NamedContentData ToNameModel(Schema schema, bool decodeJsonField) - { - Guard.NotNull(schema, nameof(schema)); - - var result = new NamedContentData(); - - foreach (var fieldValue in this) - { - if (!schema.FieldsById.TryGetValue(fieldValue.Key, out var field)) - { - continue; - } - - if (decodeJsonField && field is JsonField) - { - var encodedValue = new ContentFieldData(); - - foreach (var partitionValue in fieldValue.Value) - { - if (partitionValue.Value.IsNull()) - { - encodedValue[partitionValue.Key] = null; - } - else - { - var value = Encoding.UTF8.GetString(Convert.FromBase64String(partitionValue.Value.ToString())); - - encodedValue[partitionValue.Key] = JToken.Parse(value); - } - } - - result[field.Name] = encodedValue; - } - else - { - result[field.Name] = fieldValue.Value; - } - } - - return result; - } - - public bool Equals(IdContentData other) - { - return base.Equals(other); - } - - public override long GetKey(Field field) - { - return field.Id; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Contents/NamedContentData.cs b/src/Squidex.Domain.Apps.Core/Contents/NamedContentData.cs deleted file mode 100644 index 17dac8d0f..000000000 --- a/src/Squidex.Domain.Apps.Core/Contents/NamedContentData.cs +++ /dev/null @@ -1,191 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core.Contents -{ - public sealed class NamedContentData : ContentData, IEquatable - { - public NamedContentData() - : base(StringComparer.OrdinalIgnoreCase) - { - } - - public NamedContentData MergeInto(NamedContentData target) - { - return Merge(this, target); - } - - public NamedContentData ToCleaned() - { - return Clean(this, new NamedContentData()); - } - - public NamedContentData AddField(string name, ContentFieldData data) - { - Guard.NotNullOrEmpty(name, nameof(name)); - - this[name] = data; - - return this; - } - - public IdContentData ToIdModel(Schema schema, bool encodeJsonField) - { - Guard.NotNull(schema, nameof(schema)); - - var result = new IdContentData(); - - foreach (var fieldValue in this) - { - if (!schema.FieldsByName.TryGetValue(fieldValue.Key, out var field)) - { - continue; - } - - var fieldId = field.Id; - - if (encodeJsonField && field is JsonField) - { - var encodedValue = new ContentFieldData(); - - foreach (var partitionValue in fieldValue.Value) - { - if (partitionValue.Value.IsNull()) - { - encodedValue[partitionValue.Key] = null; - } - else - { - var value = Convert.ToBase64String(Encoding.UTF8.GetBytes(partitionValue.Value.ToString())); - - encodedValue[partitionValue.Key] = value; - } - } - - result[fieldId] = encodedValue; - } - else - { - result[fieldId] = fieldValue.Value; - } - } - - return result; - } - - public NamedContentData ToApiModel(Schema schema, LanguagesConfig languagesConfig, bool excludeHidden = true) - { - Guard.NotNull(schema, nameof(schema)); - Guard.NotNull(languagesConfig, nameof(languagesConfig)); - - var codeForInvariant = InvariantPartitioning.Instance.Master.Key; - var codeForMasterLanguage = languagesConfig.Master.Language.Iso2Code; - - var result = new NamedContentData(); - - foreach (var fieldValue in this) - { - if (!schema.FieldsByName.TryGetValue(fieldValue.Key, out var field) || (excludeHidden && field.IsHidden)) - { - continue; - } - - var fieldResult = new ContentFieldData(); - var fieldValues = fieldValue.Value; - - if (field.Partitioning.Equals(Partitioning.Language)) - { - foreach (var languageConfig in languagesConfig) - { - var languageCode = languageConfig.Key; - - if (fieldValues.TryGetValue(languageCode, out var value)) - { - fieldResult.Add(languageCode, value); - } - else if (languageConfig == languagesConfig.Master && fieldValues.TryGetValue(codeForInvariant, out value)) - { - fieldResult.Add(languageCode, value); - } - } - } - else - { - if (fieldValues.TryGetValue(codeForInvariant, out var value)) - { - fieldResult.Add(codeForInvariant, value); - } - else if (fieldValues.TryGetValue(codeForMasterLanguage, out value)) - { - fieldResult.Add(codeForInvariant, value); - } - else if (fieldValues.Count > 0) - { - fieldResult.Add(codeForInvariant, fieldValues.Values.First()); - } - } - - result.Add(GetKey(field), fieldResult); - } - - return result; - } - - public object ToLanguageModel(LanguagesConfig languagesConfig, IReadOnlyCollection languagePreferences = null) - { - Guard.NotNull(languagesConfig, nameof(languagesConfig)); - - if (languagePreferences == null || languagePreferences.Count == 0) - { - return this; - } - - if (languagePreferences.Count == 1 && languagesConfig.TryGetConfig(languagePreferences.First(), out var languageConfig)) - { - languagePreferences = languagePreferences.Union(languageConfig.LanguageFallbacks).ToList(); - } - - var result = new Dictionary(); - - foreach (var fieldValue in this) - { - var fieldValues = fieldValue.Value; - - foreach (var language in languagePreferences) - { - if (fieldValues.TryGetValue(language, out var value) && value != null) - { - result[fieldValue.Key] = value; - - break; - } - } - } - - return result; - } - - public bool Equals(NamedContentData other) - { - return base.Equals(other); - } - - public override string GetKey(Field field) - { - return field.Name; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Contents/Status.cs b/src/Squidex.Domain.Apps.Core/Contents/Status.cs deleted file mode 100644 index c20e0c4eb..000000000 --- a/src/Squidex.Domain.Apps.Core/Contents/Status.cs +++ /dev/null @@ -1,16 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Contents -{ - public enum Status - { - Draft, - Archived, - Published - } -} diff --git a/src/Squidex.Domain.Apps.Core/Contents/StatusFlow.cs b/src/Squidex.Domain.Apps.Core/Contents/StatusFlow.cs deleted file mode 100644 index 005b2d4b3..000000000 --- a/src/Squidex.Domain.Apps.Core/Contents/StatusFlow.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Linq; - -namespace Squidex.Domain.Apps.Core.Contents -{ - public static class StatusFlow - { - private static readonly Dictionary Flow = new Dictionary - { - [Status.Draft] = new[] { Status.Published, Status.Archived }, - [Status.Archived] = new[] { Status.Draft }, - [Status.Published] = new[] { Status.Draft, Status.Archived } - }; - - public static bool Exists(Status status) - { - return Flow.ContainsKey(status); - } - - public static bool CanChange(Status status, Status toStatus) - { - return Flow.TryGetValue(status, out var state) && state.Contains(toStatus); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/FieldExtensions.cs b/src/Squidex.Domain.Apps.Core/FieldExtensions.cs deleted file mode 100644 index 902a96fb1..000000000 --- a/src/Squidex.Domain.Apps.Core/FieldExtensions.cs +++ /dev/null @@ -1,57 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Concurrent; -using System.Threading.Tasks; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core -{ - public static class FieldExtensions - { - public static void AddError(this ConcurrentBag errors, string message, Field field, IFieldPartitionItem partitionItem = null) - { - AddError(errors, message, !string.IsNullOrWhiteSpace(field.RawProperties.Label) ? field.RawProperties.Label : field.Name, field.Name, partitionItem); - } - - public static void AddError(this ConcurrentBag errors, string message, string fieldName, IFieldPartitionItem partitionItem = null) - { - AddError(errors, message, fieldName, fieldName, partitionItem); - } - - public static void AddError(this ConcurrentBag errors, string message, string displayName, string fieldName, IFieldPartitionItem partitionItem = null) - { - if (partitionItem != null && partitionItem != InvariantPartitioning.Instance.Master) - { - displayName += $" ({partitionItem.Key})"; - } - - errors.Add(new ValidationError(message.Replace("", displayName), fieldName)); - } - - public static async Task ValidateAsync(this Field field, JToken value, ValidationContext context, Action addError) - { - try - { - var typedValue = value.IsNull() ? null : field.ConvertValue(value); - - foreach (var validator in field.Validators) - { - await validator.ValidateAsync(typedValue, context, addError); - } - } - catch - { - addError(" is not a valid value."); - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/IFieldPartitionItem.cs b/src/Squidex.Domain.Apps.Core/IFieldPartitionItem.cs deleted file mode 100644 index 4dd332cc1..000000000 --- a/src/Squidex.Domain.Apps.Core/IFieldPartitionItem.cs +++ /dev/null @@ -1,22 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; - -namespace Squidex.Domain.Apps.Core -{ - public interface IFieldPartitionItem - { - string Key { get; } - - string Name { get; } - - bool IsOptional { get; } - - IEnumerable Fallback { get; } - } -} diff --git a/src/Squidex.Domain.Apps.Core/IFieldPartitioning.cs b/src/Squidex.Domain.Apps.Core/IFieldPartitioning.cs deleted file mode 100644 index 9537a4fce..000000000 --- a/src/Squidex.Domain.Apps.Core/IFieldPartitioning.cs +++ /dev/null @@ -1,18 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; - -namespace Squidex.Domain.Apps.Core -{ - public interface IFieldPartitioning : IReadOnlyCollection - { - IFieldPartitionItem Master { get; } - - bool TryGetItem(string key, out IFieldPartitionItem item); - } -} diff --git a/src/Squidex.Domain.Apps.Core/InvariantPartitioning.cs b/src/Squidex.Domain.Apps.Core/InvariantPartitioning.cs deleted file mode 100644 index f9c439b56..000000000 --- a/src/Squidex.Domain.Apps.Core/InvariantPartitioning.cs +++ /dev/null @@ -1,72 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace Squidex.Domain.Apps.Core -{ - public sealed class InvariantPartitioning : IFieldPartitioning, IFieldPartitionItem - { - public static readonly InvariantPartitioning Instance = new InvariantPartitioning(); - - public int Count - { - get { return 1; } - } - - public IFieldPartitionItem Master - { - get { return this; } - } - - string IFieldPartitionItem.Key - { - get { return "iv"; } - } - - string IFieldPartitionItem.Name - { - get { return "Invariant"; } - } - - bool IFieldPartitionItem.IsOptional - { - get { return false; } - } - - IEnumerable IFieldPartitionItem.Fallback - { - get { return Enumerable.Empty(); } - } - - private InvariantPartitioning() - { - } - - public bool TryGetItem(string key, out IFieldPartitionItem item) - { - var isFound = string.Equals(key, "iv", StringComparison.OrdinalIgnoreCase); - - item = isFound ? this : null; - - return isFound; - } - - IEnumerator IEnumerable.GetEnumerator() - { - yield return this; - } - - IEnumerator IEnumerable.GetEnumerator() - { - yield return this; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/LanguageConfig.cs b/src/Squidex.Domain.Apps.Core/LanguageConfig.cs deleted file mode 100644 index b9350ed5a..000000000 --- a/src/Squidex.Domain.Apps.Core/LanguageConfig.cs +++ /dev/null @@ -1,58 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core -{ - public sealed class LanguageConfig : IFieldPartitionItem - { - public bool IsOptional { get; } - - public Language Language { get; } - - public ImmutableList LanguageFallbacks { get; } - - public string Key - { - get { return Language.Iso2Code; } - } - - public string Name - { - get { return Language.EnglishName; } - } - - IEnumerable IFieldPartitionItem.Fallback - { - get { return LanguageFallbacks.Select(x => x.Iso2Code); } - } - - public LanguageConfig(Language language, bool isOptional, params Language[] fallback) - : this(language, isOptional, fallback?.ToImmutableList()) - { - } - - public LanguageConfig(Language language, bool isOptional, IEnumerable fallback) - : this(language, isOptional, fallback?.ToImmutableList()) - { - } - - public LanguageConfig(Language language, bool isOptional = false, ImmutableList fallback = null) - { - Guard.NotNull(language, nameof(language)); - - IsOptional = isOptional; - - Language = language; - LanguageFallbacks = fallback ?? ImmutableList.Empty; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/LanguagesConfig.cs b/src/Squidex.Domain.Apps.Core/LanguagesConfig.cs deleted file mode 100644 index e966392a9..000000000 --- a/src/Squidex.Domain.Apps.Core/LanguagesConfig.cs +++ /dev/null @@ -1,218 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core -{ - public sealed class LanguagesConfig : IFieldPartitioning - { - private readonly ImmutableDictionary languages; - private readonly LanguageConfig master; - - public static readonly LanguagesConfig Empty = Create(); - - public LanguageConfig Master - { - get { return master; } - } - - public int Count - { - get { return languages.Count; } - } - - IFieldPartitionItem IFieldPartitioning.Master - { - get { return Master; } - } - - IEnumerator IEnumerable.GetEnumerator() - { - return languages.Values.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return languages.Values.GetEnumerator(); - } - - private LanguagesConfig(ImmutableDictionary languages, LanguageConfig master) - { - this.languages = ValidateLanguages(languages); - - this.master = master; - } - - public static LanguagesConfig Create(ICollection languageConfigs) - { - Guard.NotNull(languageConfigs, nameof(languageConfigs)); - - var validated = ValidateLanguages(languageConfigs.ToImmutableDictionary(c => c.Language)); - - return new LanguagesConfig(validated, languageConfigs.FirstOrDefault()); - } - - public static LanguagesConfig Create(params Language[] languages) - { - Guard.NotNull(languages, nameof(languages)); - - var languageConfigs = languages.Select(l => new LanguageConfig(l)).ToList(); - - return Create(languageConfigs); - } - - public LanguagesConfig MakeMaster(Language language) - { - ThrowIfNotFound(language); - - return new LanguagesConfig(languages, languages[language]); - } - - public LanguagesConfig Add(Language language) - { - ThrowIfFound(language, () => $"Cannot add language '{language.Iso2Code}'."); - - var newLanguages = languages.Add(language, new LanguageConfig(language)); - - return new LanguagesConfig(newLanguages, master ?? newLanguages.Values.First()); - } - - public LanguagesConfig Update(Language language, bool isOptional, bool isMaster, IEnumerable fallback) - { - ThrowIfNotFound(language); - - if (isOptional) - { - ThrowIfMaster(language, isMaster, () => $"Cannot cannot make language '{language.Iso2Code}' optional"); - } - - var newLanguage = new LanguageConfig(language, isOptional, fallback); - var newLanguages = ValidateLanguages(languages.SetItem(language, newLanguage)); - - return new LanguagesConfig(newLanguages, isMaster ? newLanguage : master); - } - - public LanguagesConfig Remove(Language language) - { - ThrowIfNotFound(language); - ThrowIfMaster(language, false, () => $"Cannot remove language '{language.Iso2Code}'"); - - var newLanguages = languages.Remove(language); - - foreach (var languageConfig in newLanguages.Values) - { - if (languageConfig.LanguageFallbacks.Contains(language)) - { - newLanguages = - newLanguages.SetItem(languageConfig.Language, - new LanguageConfig( - languageConfig.Language, - languageConfig.IsOptional, - languageConfig.LanguageFallbacks.Remove(language))); - } - } - - return new LanguagesConfig(newLanguages, master); - } - - public bool Contains(Language language) - { - return language != null && languages.ContainsKey(language); - } - - public bool TryGetConfig(Language language, out LanguageConfig config) - { - return languages.TryGetValue(language, out config); - } - - public bool TryGetItem(string key, out IFieldPartitionItem item) - { - if (Language.IsValidLanguage(key) && languages.TryGetValue(key, out var value)) - { - item = value; - - return true; - } - - item = null; - - return false; - } - - private static ImmutableDictionary ValidateLanguages(ImmutableDictionary languages) - { - var errors = new List(); - - foreach (var languageConfig in languages.Values) - { - foreach (var fallback in languageConfig.LanguageFallbacks) - { - if (!languages.ContainsKey(fallback)) - { - var message = $"Config for language '{languageConfig.Language.Iso2Code}' contains unsupported fallback language '{fallback.Iso2Code}'"; - - errors.Add(new ValidationError(message)); - } - } - } - - if (errors.Count > 0) - { - throw new ValidationException("Cannot configure language.", errors); - } - - return languages; - } - - private void ThrowIfNotFound(Language language) - { - if (!Contains(language)) - { - throw new DomainObjectNotFoundException(language, "Languages", typeof(LanguagesConfig)); - } - } - - private void ThrowIfFound(Language language, Func message) - { - if (Contains(language)) - { - var error = new ValidationError("Language is already part of the app.", "Language"); - - throw new ValidationException(message(), error); - } - } - - private void ThrowIfMaster(Language language, bool isMaster, Func message) - { - if (master?.Language == language || isMaster) - { - var error = new ValidationError("Language is the master language.", "Language"); - - throw new ValidationException(message(), error); - } - } - - public PartitionResolver ToResolver() - { - return partitioning => - { - if (partitioning.Equals(Partitioning.Invariant)) - { - return InvariantPartitioning.Instance; - } - - return this; - }; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Partitioning.cs b/src/Squidex.Domain.Apps.Core/Partitioning.cs deleted file mode 100644 index f6600ede5..000000000 --- a/src/Squidex.Domain.Apps.Core/Partitioning.cs +++ /dev/null @@ -1,49 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core -{ - public delegate IFieldPartitioning PartitionResolver(Partitioning key); - - public sealed class Partitioning : IEquatable - { - public static readonly Partitioning Invariant = new Partitioning("invariant"); - public static readonly Partitioning Language = new Partitioning("language"); - - public string Key { get; } - - public Partitioning(string key) - { - Guard.NotNullOrEmpty(key, nameof(key)); - - Key = key; - } - - public override bool Equals(object obj) - { - return Equals(obj as Partitioning); - } - - public bool Equals(Partitioning other) - { - return string.Equals(other?.Key, Key, StringComparison.OrdinalIgnoreCase); - } - - public override int GetHashCode() - { - return Key.GetHashCode(); - } - - public override string ToString() - { - return Key; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/PartitioningExtensions.cs b/src/Squidex.Domain.Apps.Core/PartitioningExtensions.cs deleted file mode 100644 index 089fc0ae6..000000000 --- a/src/Squidex.Domain.Apps.Core/PartitioningExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; - -namespace Squidex.Domain.Apps.Core -{ - public static class PartitioningExtensions - { - private static readonly HashSet AllowedPartitions = new HashSet(StringComparer.OrdinalIgnoreCase) - { - Partitioning.Language.Key, - Partitioning.Invariant.Key - }; - - public static bool IsValidPartitioning(this string value) - { - return value == null || AllowedPartitions.Contains(value); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/AssetsField.cs b/src/Squidex.Domain.Apps.Core/Schemas/AssetsField.cs deleted file mode 100644 index 1291ce652..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/AssetsField.cs +++ /dev/null @@ -1,79 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class AssetsField : Field, IReferenceField - { - private static readonly ImmutableList EmptyIds = ImmutableList.Empty; - - public AssetsField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new AssetsFieldProperties()) - { - } - - public AssetsField(long id, string name, Partitioning partitioning, AssetsFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired || Properties.MinItems.HasValue || Properties.MaxItems.HasValue) - { - yield return new CollectionValidator(Properties.IsRequired, Properties.MinItems, Properties.MaxItems); - } - - yield return new AssetsValidator(); - } - - public IEnumerable GetReferencedIds(JToken value) - { - IEnumerable result = null; - try - { - result = value?.ToObject>(); - } - catch - { - result = EmptyIds; - } - - return result ?? EmptyIds; - } - - public JToken RemoveDeletedReferences(JToken value, ISet deletedReferencedIds) - { - if (value == null || value.Type == JTokenType.Null) - { - return null; - } - - var oldAssetIds = GetReferencedIds(value).ToArray(); - var newAssetIds = oldAssetIds.Where(x => !deletedReferencedIds.Contains(x)).ToList(); - - return newAssetIds.Count != oldAssetIds.Length ? JToken.FromObject(newAssetIds) : value; - } - - public override object ConvertValue(JToken value) - { - return value.ToObject>(); - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/AssetsFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/AssetsFieldProperties.cs deleted file mode 100644 index fab566c36..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/AssetsFieldProperties.cs +++ /dev/null @@ -1,57 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(AssetsField))] - public sealed class AssetsFieldProperties : FieldProperties - { - private int? minItems; - private int? maxItems; - - public int? MinItems - { - get - { - return minItems; - } - set - { - ThrowIfFrozen(); - - minItems = value; - } - } - - public int? MaxItems - { - get - { - return maxItems; - } - set - { - ThrowIfFrozen(); - - maxItems = value; - } - } - - public override JToken GetDefaultValue() - { - return new JArray(); - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/BooleanField.cs b/src/Squidex.Domain.Apps.Core/Schemas/BooleanField.cs deleted file mode 100644 index 1a8019a69..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/BooleanField.cs +++ /dev/null @@ -1,44 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class BooleanField : Field - { - public BooleanField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new BooleanFieldProperties()) - { - } - - public BooleanField(long id, string name, Partitioning partitioning, BooleanFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired) - { - yield return new RequiredValidator(); - } - } - - public override object ConvertValue(JToken value) - { - return (bool?)value; - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/BooleanFieldEditor.cs b/src/Squidex.Domain.Apps.Core/Schemas/BooleanFieldEditor.cs deleted file mode 100644 index 08374e9a6..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/BooleanFieldEditor.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public enum BooleanFieldEditor - { - Checkbox, - Toggle - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/BooleanFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/BooleanFieldProperties.cs deleted file mode 100644 index ec5b79610..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/BooleanFieldProperties.cs +++ /dev/null @@ -1,57 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(BooleanField))] - public sealed class BooleanFieldProperties : FieldProperties - { - private BooleanFieldEditor editor; - private bool? defaultValue; - - public bool? DefaultValue - { - get - { - return defaultValue; - } - set - { - ThrowIfFrozen(); - - defaultValue = value; - } - } - - public BooleanFieldEditor Editor - { - get - { - return editor; - } - set - { - ThrowIfFrozen(); - - editor = value; - } - } - - public override JToken GetDefaultValue() - { - return DefaultValue; - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/CloneableBase.cs b/src/Squidex.Domain.Apps.Core/Schemas/CloneableBase.cs deleted file mode 100644 index 59114e71d..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/CloneableBase.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public abstract class CloneableBase - { - protected T Clone(Action updater) where T : CloneableBase - { - var clone = (T)MemberwiseClone(); - - updater(clone); - - return clone; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeCalculatedDefaultValue.cs b/src/Squidex.Domain.Apps.Core/Schemas/DateTimeCalculatedDefaultValue.cs deleted file mode 100644 index 41f2b9534..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeCalculatedDefaultValue.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public enum DateTimeCalculatedDefaultValue - { - Now, - Today - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeField.cs b/src/Squidex.Domain.Apps.Core/Schemas/DateTimeField.cs deleted file mode 100644 index 85ea8cf51..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeField.cs +++ /dev/null @@ -1,64 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using NodaTime; -using NodaTime.Text; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class DateTimeField : Field - { - public DateTimeField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new DateTimeFieldProperties()) - { - } - - public DateTimeField(long id, string name, Partitioning partitioning, DateTimeFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired) - { - yield return new RequiredValidator(); - } - - if (Properties.MinValue.HasValue || Properties.MaxValue.HasValue) - { - yield return new RangeValidator(Properties.MinValue, Properties.MaxValue); - } - } - - public override object ConvertValue(JToken value) - { - if (value.Type == JTokenType.String) - { - var parseResult = InstantPattern.General.Parse(value.ToString()); - - if (!parseResult.Success) - { - throw parseResult.Exception; - } - - return parseResult.Value; - } - - throw new InvalidCastException("Invalid json type, expected string."); - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeFieldEditor.cs b/src/Squidex.Domain.Apps.Core/Schemas/DateTimeFieldEditor.cs deleted file mode 100644 index ffe493a8f..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeFieldEditor.cs +++ /dev/null @@ -1,15 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public enum DateTimeFieldEditor - { - Date, - DateTime - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/DateTimeFieldProperties.cs deleted file mode 100644 index 3873185e9..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/DateTimeFieldProperties.cs +++ /dev/null @@ -1,115 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Newtonsoft.Json.Linq; -using NodaTime; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(DateTimeField))] - public sealed class DateTimeFieldProperties : FieldProperties - { - private DateTimeFieldEditor editor; - private DateTimeCalculatedDefaultValue? calculatedDefaultValue; - private Instant? maxValue; - private Instant? minValue; - private Instant? defaultValue; - - public Instant? MaxValue - { - get - { - return maxValue; - } - set - { - ThrowIfFrozen(); - - maxValue = value; - } - } - - public Instant? MinValue - { - get - { - return minValue; - } - set - { - ThrowIfFrozen(); - - minValue = value; - } - } - - public Instant? DefaultValue - { - get - { - return defaultValue; - } - set - { - ThrowIfFrozen(); - - defaultValue = value; - } - } - - public DateTimeCalculatedDefaultValue? CalculatedDefaultValue - { - get - { - return calculatedDefaultValue; - } - set - { - ThrowIfFrozen(); - - calculatedDefaultValue = value; - } - } - - public DateTimeFieldEditor Editor - { - get - { - return editor; - } - set - { - ThrowIfFrozen(); - - editor = value; - } - } - - public override JToken GetDefaultValue() - { - if (CalculatedDefaultValue == DateTimeCalculatedDefaultValue.Now) - { - return DateTime.UtcNow.ToString("o"); - } - else if (CalculatedDefaultValue == DateTimeCalculatedDefaultValue.Today) - { - return DateTime.UtcNow.Date.ToString("o"); - } - else - { - return DefaultValue?.ToString(); - } - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Edm/EdmSchemaExtensions.cs b/src/Squidex.Domain.Apps.Core/Schemas/Edm/EdmSchemaExtensions.cs deleted file mode 100644 index ff38f0e67..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Edm/EdmSchemaExtensions.cs +++ /dev/null @@ -1,59 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Linq; -using Microsoft.OData.Edm; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas.Edm -{ - public static class EdmSchemaExtensions - { - public static string EscapeEdmField(this string field) - { - return field.Replace("-", "_"); - } - - public static string UnescapeEdmField(this string field) - { - return field.Replace("_", "-"); - } - - public static EdmComplexType BuildEdmType(this Schema schema, PartitionResolver partitionResolver, Func typeResolver) - { - Guard.NotNull(typeResolver, nameof(typeResolver)); - Guard.NotNull(partitionResolver, nameof(partitionResolver)); - - var schemaName = schema.Name.ToPascalCase(); - - var edmType = new EdmComplexType("Squidex", schemaName); - - foreach (var field in schema.FieldsByName.Values.Where(x => !x.IsHidden)) - { - var edmValueType = EdmTypeVisitor.CreateEdmType(field); - - if (edmValueType == null) - { - continue; - } - - var partitionType = typeResolver(new EdmComplexType("Squidex", $"{schemaName}{field.Name.ToPascalCase()}Property")); - var partition = partitionResolver(field.Partitioning); - - foreach (var partitionItem in partition) - { - partitionType.AddStructuralProperty(partitionItem.Key, edmValueType); - } - - edmType.AddStructuralProperty(field.Name.EscapeEdmField(), new EdmComplexTypeReference(partitionType, false)); - } - - return edmType; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Edm/EdmTypeVisitor.cs b/src/Squidex.Domain.Apps.Core/Schemas/Edm/EdmTypeVisitor.cs deleted file mode 100644 index 4b80bfffa..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Edm/EdmTypeVisitor.cs +++ /dev/null @@ -1,75 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Microsoft.OData.Edm; - -namespace Squidex.Domain.Apps.Core.Schemas.Edm -{ - public sealed class EdmTypeVisitor : IFieldVisitor - { - private static readonly EdmTypeVisitor Instance = new EdmTypeVisitor(); - - private EdmTypeVisitor() - { - } - - public static IEdmTypeReference CreateEdmType(Field field) - { - return field.Accept(Instance); - } - - public IEdmTypeReference Visit(AssetsField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.String, field); - } - - public IEdmTypeReference Visit(BooleanField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.Boolean, field); - } - - public IEdmTypeReference Visit(DateTimeField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.DateTimeOffset, field); - } - - public IEdmTypeReference Visit(GeolocationField field) - { - return null; - } - - public IEdmTypeReference Visit(JsonField field) - { - return null; - } - - public IEdmTypeReference Visit(NumberField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.Double, field); - } - - public IEdmTypeReference Visit(ReferencesField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.String, field); - } - - public IEdmTypeReference Visit(StringField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.String, field); - } - - public IEdmTypeReference Visit(TagsField field) - { - return CreatePrimitive(EdmPrimitiveTypeKind.String, field); - } - - private static IEdmTypeReference CreatePrimitive(EdmPrimitiveTypeKind kind, Field field) - { - return EdmCoreModel.Instance.GetPrimitive(kind, !field.RawProperties.IsRequired); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Field.cs b/src/Squidex.Domain.Apps.Core/Schemas/Field.cs deleted file mode 100644 index 0f4b9b863..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Field.cs +++ /dev/null @@ -1,130 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public abstract class Field : CloneableBase - { - private readonly Lazy> validators; - private readonly long fieldId; - private readonly Partitioning partitioning; - private readonly string fieldName; - private bool isDisabled; - private bool isHidden; - private bool isLocked; - - public long Id - { - get { return fieldId; } - } - - public string Name - { - get { return fieldName; } - } - - public bool IsLocked - { - get { return isLocked; } - } - - public bool IsHidden - { - get { return isHidden; } - } - - public bool IsDisabled - { - get { return isDisabled; } - } - - public Partitioning Partitioning - { - get { return partitioning; } - } - - public IReadOnlyList Validators - { - get { return validators.Value; } - } - - public abstract FieldProperties RawProperties { get; } - - protected Field(long id, string name, Partitioning partitioning) - { - Guard.NotNullOrEmpty(name, nameof(name)); - Guard.NotNull(partitioning, nameof(partitioning)); - Guard.GreaterThan(id, 0, nameof(id)); - - fieldId = id; - fieldName = name; - - this.partitioning = partitioning; - - validators = new Lazy>(() => new List(CreateValidators())); - } - - protected abstract Field UpdateInternal(FieldProperties newProperties); - - protected abstract IEnumerable CreateValidators(); - - public abstract object ConvertValue(JToken value); - - public Field Lock() - { - return Clone(clone => - { - clone.isLocked = true; - }); - } - - public Field Hide() - { - return Clone(clone => - { - clone.isHidden = true; - }); - } - - public Field Show() - { - return Clone(clone => - { - clone.isHidden = false; - }); - } - - public Field Disable() - { - return Clone(clone => - { - clone.isDisabled = true; - }); - } - - public Field Enable() - { - return Clone(clone => - { - clone.isDisabled = false; - }); - } - - public Field Update(FieldProperties newProperties) - { - return UpdateInternal(newProperties); - } - - public abstract T Accept(IFieldVisitor visitor); - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/FieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/FieldProperties.cs deleted file mode 100644 index 73ad8b34e..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/FieldProperties.cs +++ /dev/null @@ -1,70 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public abstract class FieldProperties : NamedElementPropertiesBase - { - private bool isRequired; - private bool isListField; - private string placeholder; - - public bool IsRequired - { - get - { - return isRequired; - } - set - { - ThrowIfFrozen(); - - isRequired = value; - } - } - - public bool IsListField - { - get - { - return isListField; - } - set - { - ThrowIfFrozen(); - - isListField = value; - } - } - - public string Placeholder - { - get - { - return placeholder; - } - set - { - ThrowIfFrozen(); - - placeholder = value; - } - } - - public abstract JToken GetDefaultValue(); - - public abstract T Accept(IFieldPropertiesVisitor visitor); - - public virtual bool ShouldApplyDefaultValue(JToken value) - { - return value.IsNull(); - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/FieldRegistry.cs b/src/Squidex.Domain.Apps.Core/Schemas/FieldRegistry.cs deleted file mode 100644 index 1aa8e964b..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/FieldRegistry.cs +++ /dev/null @@ -1,115 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class FieldRegistry - { - private delegate Field FactoryFunction(long id, string name, Partitioning partitioning, FieldProperties properties); - - private readonly TypeNameRegistry typeNameRegistry; - private readonly Dictionary fieldsByPropertyType = new Dictionary(); - - private sealed class Registered - { - private readonly FactoryFunction fieldFactory; - private readonly Type propertiesType; - - public Type PropertiesType - { - get { return propertiesType; } - } - - public Registered(FactoryFunction fieldFactory, Type propertiesType) - { - this.fieldFactory = fieldFactory; - this.propertiesType = propertiesType; - } - - public Field CreateField(long id, string name, Partitioning partitioning, FieldProperties properties) - { - return fieldFactory(id, name, partitioning, properties); - } - } - - public FieldRegistry(TypeNameRegistry typeNameRegistry) - { - Guard.NotNull(typeNameRegistry, nameof(typeNameRegistry)); - - this.typeNameRegistry = typeNameRegistry; - - Add( - (id, name, partitioning, properties) => - new BooleanField(id, name, partitioning, (BooleanFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new NumberField(id, name, partitioning, (NumberFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new StringField(id, name, partitioning, (StringFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new JsonField(id, name, partitioning, (JsonFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new AssetsField(id, name, partitioning, (AssetsFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new GeolocationField(id, name, partitioning, (GeolocationFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new ReferencesField(id, name, partitioning, (ReferencesFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new DateTimeField(id, name, partitioning, (DateTimeFieldProperties)properties)); - - Add( - (id, name, partitioning, properties) => - new TagsField(id, name, partitioning, (TagsFieldProperties)properties)); - - typeNameRegistry.MapObsolete(typeof(ReferencesFieldProperties), "DateTime"); - - typeNameRegistry.MapObsolete(typeof(DateTimeFieldProperties), "References"); - } - - private void Add(FactoryFunction fieldFactory) - { - Guard.NotNull(fieldFactory, nameof(fieldFactory)); - - typeNameRegistry.Map(typeof(TFieldProperties)); - - var registered = new Registered(fieldFactory, typeof(TFieldProperties)); - - fieldsByPropertyType[registered.PropertiesType] = registered; - } - - 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) - { - throw new InvalidOperationException($"The field property '{properties.GetType()}' is not supported."); - } - - return registered.CreateField(id, name, partitioning, properties); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Field{T}.cs b/src/Squidex.Domain.Apps.Core/Schemas/Field{T}.cs deleted file mode 100644 index 55a3588a0..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Field{T}.cs +++ /dev/null @@ -1,55 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Squidex.Infrastructure; -namespace Squidex.Domain.Apps.Core.Schemas -{ - public abstract class Field : Field where T : FieldProperties - { - private T properties; - - public T Properties - { - get { return properties; } - } - - public override FieldProperties RawProperties - { - get { return properties; } - } - - protected Field(long id, string name, Partitioning partitioning, T properties) - : base(id, name, partitioning) - { - Guard.NotNull(properties, nameof(properties)); - - this.properties = ValidateProperties(properties); - } - - protected override Field UpdateInternal(FieldProperties newProperties) - { - var typedProperties = ValidateProperties(newProperties); - - return Clone>(clone => clone.properties = typedProperties); - } - - private T ValidateProperties(FieldProperties newProperties) - { - Guard.NotNull(newProperties, nameof(newProperties)); - - newProperties.Freeze(); - - if (!(newProperties is T typedProperties)) - { - throw new ArgumentException($"Properties must be of type '{typeof(T)}", nameof(newProperties)); - } - - return typedProperties; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/GeolocationField.cs b/src/Squidex.Domain.Apps.Core/Schemas/GeolocationField.cs deleted file mode 100644 index 8e242f3fc..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/GeolocationField.cs +++ /dev/null @@ -1,63 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class GeolocationField : Field - { - public GeolocationField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new GeolocationFieldProperties()) - { - } - - public GeolocationField(long id, string name, Partitioning partitioning, GeolocationFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired) - { - yield return new RequiredValidator(); - } - } - - public override object ConvertValue(JToken value) - { - var geolocation = (JObject)value; - - foreach (var property in geolocation.Properties()) - { - if (!string.Equals(property.Name, "latitude", StringComparison.OrdinalIgnoreCase) && - !string.Equals(property.Name, "longitude", StringComparison.OrdinalIgnoreCase)) - { - throw new InvalidCastException("Geolocation can only have latitude and longitude property."); - } - } - - var lat = (double)geolocation["latitude"]; - var lon = (double)geolocation["longitude"]; - - Guard.Between(lat, -90, 90, "latitude"); - Guard.Between(lon, -180, 180, "longitude"); - - return value; - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/GeolocationFieldEditor.cs b/src/Squidex.Domain.Apps.Core/Schemas/GeolocationFieldEditor.cs deleted file mode 100644 index 6a1b70099..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/GeolocationFieldEditor.cs +++ /dev/null @@ -1,14 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public enum GeolocationFieldEditor - { - Map - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/GeolocationFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/GeolocationFieldProperties.cs deleted file mode 100644 index 6ba7b7c20..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/GeolocationFieldProperties.cs +++ /dev/null @@ -1,42 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(GeolocationField))] - public sealed class GeolocationFieldProperties : FieldProperties - { - private GeolocationFieldEditor editor; - - public GeolocationFieldEditor Editor - { - get - { - return editor; - } - set - { - ThrowIfFrozen(); - - editor = value; - } - } - - public override JToken GetDefaultValue() - { - return null; - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/IFieldPropertiesVisitor.cs b/src/Squidex.Domain.Apps.Core/Schemas/IFieldPropertiesVisitor.cs deleted file mode 100644 index 108269359..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/IFieldPropertiesVisitor.cs +++ /dev/null @@ -1,30 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public interface IFieldPropertiesVisitor - { - T Visit(AssetsFieldProperties properties); - - T Visit(BooleanFieldProperties properties); - - T Visit(DateTimeFieldProperties properties); - - T Visit(GeolocationFieldProperties properties); - - T Visit(JsonFieldProperties properties); - - T Visit(NumberFieldProperties properties); - - T Visit(ReferencesFieldProperties properties); - - T Visit(StringFieldProperties properties); - - T Visit(TagsFieldProperties properties); - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/IFieldVisitor.cs b/src/Squidex.Domain.Apps.Core/Schemas/IFieldVisitor.cs deleted file mode 100644 index fd4ce2589..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/IFieldVisitor.cs +++ /dev/null @@ -1,30 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public interface IFieldVisitor - { - T Visit(AssetsField field); - - T Visit(BooleanField field); - - T Visit(DateTimeField field); - - T Visit(GeolocationField field); - - T Visit(JsonField field); - - T Visit(NumberField field); - - T Visit(ReferencesField field); - - T Visit(StringField field); - - T Visit(TagsField field); - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/IReferenceField.cs b/src/Squidex.Domain.Apps.Core/Schemas/IReferenceField.cs deleted file mode 100644 index 1859c3a1f..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/IReferenceField.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public interface IReferenceField - { - IEnumerable GetReferencedIds(JToken value); - - JToken RemoveDeletedReferences(JToken value, ISet deletedReferencedIds); - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Json/JsonFieldModel.cs b/src/Squidex.Domain.Apps.Core/Schemas/Json/JsonFieldModel.cs deleted file mode 100644 index e4c04fdf8..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Json/JsonFieldModel.cs +++ /dev/null @@ -1,35 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json; - -namespace Squidex.Domain.Apps.Core.Schemas.Json -{ - public sealed class JsonFieldModel - { - [JsonProperty] - public long Id { get; set; } - - [JsonProperty] - public bool IsHidden { get; set; } - - [JsonProperty] - public bool IsLocked { get; set; } - - [JsonProperty] - public bool IsDisabled { get; set; } - - [JsonProperty] - public string Name { get; set; } - - [JsonProperty] - public string Partitioning { get; set; } - - [JsonProperty] - public FieldProperties Properties { get; set; } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Json/JsonSchemaModel.cs b/src/Squidex.Domain.Apps.Core/Schemas/Json/JsonSchemaModel.cs deleted file mode 100644 index a4d0428a9..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Json/JsonSchemaModel.cs +++ /dev/null @@ -1,86 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Newtonsoft.Json; - -namespace Squidex.Domain.Apps.Core.Schemas.Json -{ - public sealed class JsonSchemaModel - { - [JsonProperty] - public string Name { get; set; } - - [JsonProperty] - public bool IsPublished { get; set; } - - [JsonProperty] - public SchemaProperties Properties { get; set; } - - [JsonProperty] - public List Fields { get; set; } - - public JsonSchemaModel() - { - } - - public JsonSchemaModel(Schema schema) - { - Name = schema.Name; - - Properties = schema.Properties; - - Fields = - schema.Fields?.Select(x => - new JsonFieldModel - { - Id = x.Id, - Name = x.Name, - IsHidden = x.IsHidden, - IsLocked = x.IsLocked, - IsDisabled = x.IsDisabled, - Partitioning = x.Partitioning.Key, - Properties = x.RawProperties - }).ToList(); - - IsPublished = schema.IsPublished; - } - - public Schema ToSchema(FieldRegistry fieldRegistry) - { - var fields = Fields?.Select(fieldModel => - { - var parititonKey = new Partitioning(fieldModel.Partitioning); - - var field = fieldRegistry.CreateField(fieldModel.Id, fieldModel.Name, parititonKey, fieldModel.Properties); - - if (fieldModel.IsDisabled) - { - field = field.Disable(); - } - - if (fieldModel.IsLocked) - { - field = field.Lock(); - } - - if (fieldModel.IsHidden) - { - field = field.Hide(); - } - - return field; - }).ToImmutableList() ?? ImmutableList.Empty; - - var schema = new Schema(Name, IsPublished, Properties, fields); - - return schema; - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Json/SchemaConverter.cs b/src/Squidex.Domain.Apps.Core/Schemas/Json/SchemaConverter.cs deleted file mode 100644 index 92aa2ccf3..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Json/SchemaConverter.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Newtonsoft.Json; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas.Json -{ - public sealed class SchemaConverter : JsonConverter - { - private readonly FieldRegistry fieldRegistry; - - public SchemaConverter(FieldRegistry fieldRegistry) - { - Guard.NotNull(fieldRegistry, nameof(fieldRegistry)); - - this.fieldRegistry = fieldRegistry; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - serializer.Serialize(writer, new JsonSchemaModel((Schema)value)); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - return serializer.Deserialize(reader).ToSchema(fieldRegistry); - } - - public override bool CanConvert(Type objectType) - { - return objectType == typeof(Schema); - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/JsonField.cs b/src/Squidex.Domain.Apps.Core/Schemas/JsonField.cs deleted file mode 100644 index d603f7ec1..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/JsonField.cs +++ /dev/null @@ -1,44 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class JsonField : Field - { - public JsonField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new JsonFieldProperties()) - { - } - - public JsonField(long id, string name, Partitioning partitioning, JsonFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired) - { - yield return new RequiredValidator(); - } - } - - public override object ConvertValue(JToken value) - { - return value; - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/JsonFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/JsonFieldProperties.cs deleted file mode 100644 index 607286b4a..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/JsonFieldProperties.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(JsonField))] - public sealed class JsonFieldProperties : FieldProperties - { - public override JToken GetDefaultValue() - { - return JValue.CreateNull(); - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/ContentSchemaBuilder.cs b/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/ContentSchemaBuilder.cs deleted file mode 100644 index f7fa85fcd..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/ContentSchemaBuilder.cs +++ /dev/null @@ -1,55 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using NJsonSchema; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas.JsonSchema -{ - public sealed class ContentSchemaBuilder - { - public JsonSchema4 CreateContentSchema(Schema schema, JsonSchema4 dataSchema) - { - Guard.NotNull(schema, nameof(schema)); - Guard.NotNull(dataSchema, nameof(dataSchema)); - - var schemaName = schema.Properties.Label.WithFallback(schema.Name); - - var contentSchema = new JsonSchema4 - { - Properties = - { - ["id"] = CreateProperty($"The id of the {schemaName} content."), - ["data"] = CreateProperty($"The data of the {schemaName}.", dataSchema), - ["version"] = CreateProperty($"The version of the {schemaName}.", JsonObjectType.Number), - ["created"] = CreateProperty($"The date and time when the {schemaName} content has been created.", "date-time"), - ["createdBy"] = CreateProperty($"The user that has created the {schemaName} content."), - ["lastModified"] = CreateProperty($"The date and time when the {schemaName} content has been modified last.", "date-time"), - ["lastModifiedBy"] = CreateProperty($"The user that has updated the {schemaName} content last.") - }, - Type = JsonObjectType.Object - }; - - return contentSchema; - } - - private static JsonProperty CreateProperty(string description, JsonSchema4 dataSchema) - { - return new JsonProperty { Description = description, IsRequired = true, Type = JsonObjectType.Object, Reference = dataSchema }; - } - - private static JsonProperty CreateProperty(string description, JsonObjectType type) - { - return new JsonProperty { Description = description, IsRequired = true, Type = type }; - } - - private static JsonProperty CreateProperty(string description, string format = null) - { - return new JsonProperty { Description = description, Format = format, IsRequired = true, Type = JsonObjectType.String }; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/JsonSchemaExtensions.cs b/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/JsonSchemaExtensions.cs deleted file mode 100644 index 437983c5c..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/JsonSchemaExtensions.cs +++ /dev/null @@ -1,70 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Linq; -using NJsonSchema; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas.JsonSchema -{ - public static class JsonSchemaExtensions - { - public static JsonSchema4 BuildJsonSchema(this Schema schema, PartitionResolver partitionResolver, Func schemaResolver) - { - Guard.NotNull(schemaResolver, nameof(schemaResolver)); - Guard.NotNull(partitionResolver, nameof(partitionResolver)); - - var schemaName = schema.Name.ToPascalCase(); - - var jsonTypeVisitor = new JsonTypeVisitor(schemaResolver); - var jsonSchema = new JsonSchema4 { Type = JsonObjectType.Object }; - - foreach (var field in schema.Fields.Where(x => !x.IsHidden)) - { - var partitionProperty = CreateProperty(field); - var partitionObject = new JsonSchema4 { Type = JsonObjectType.Object, AllowAdditionalProperties = false }; - var partition = partitionResolver(field.Partitioning); - - foreach (var partitionItem in partition) - { - var partitionItemProperty = field.Accept(jsonTypeVisitor); - - partitionItemProperty.Description = partitionItem.Name; - partitionObject.Properties.Add(partitionItem.Key, partitionItemProperty); - } - - partitionProperty.Reference = schemaResolver($"{schemaName}{field.Name.ToPascalCase()}Property", partitionObject); - - jsonSchema.Properties.Add(field.Name, partitionProperty); - } - - return jsonSchema; - } - - public static JsonProperty CreateProperty(Field field) - { - var jsonProperty = new JsonProperty { IsRequired = field.RawProperties.IsRequired, Type = JsonObjectType.Object }; - - if (!string.IsNullOrWhiteSpace(field.RawProperties.Hints)) - { - jsonProperty.Description = field.RawProperties.Hints; - } - else - { - jsonProperty.Description = field.Name; - } - - if (!string.IsNullOrWhiteSpace(field.RawProperties.Hints)) - { - jsonProperty.Description += $" ({field.RawProperties.Hints})."; - } - - return jsonProperty; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/JsonTypeVisitor.cs b/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/JsonTypeVisitor.cs deleted file mode 100644 index 1a68defea..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/JsonSchema/JsonTypeVisitor.cs +++ /dev/null @@ -1,161 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.ObjectModel; -using NJsonSchema; - -namespace Squidex.Domain.Apps.Core.Schemas.JsonSchema -{ - public sealed class JsonTypeVisitor : IFieldVisitor - { - private readonly Func schemaResolver; - - public JsonTypeVisitor(Func schemaResolver) - { - this.schemaResolver = schemaResolver; - } - - public JsonProperty Visit(AssetsField field) - { - return CreateProperty(field, jsonProperty => - { - var itemSchema = schemaResolver("AssetItem", new JsonSchema4 { Type = JsonObjectType.String }); - - jsonProperty.Type = JsonObjectType.Array; - jsonProperty.Item = itemSchema; - }); - } - - public JsonProperty Visit(BooleanField field) - { - return CreateProperty(field, jsonProperty => - { - jsonProperty.Type = JsonObjectType.Boolean; - }); - } - - public JsonProperty Visit(DateTimeField field) - { - return CreateProperty(field, jsonProperty => - { - jsonProperty.Type = JsonObjectType.String; - jsonProperty.Format = JsonFormatStrings.DateTime; - }); - } - - public JsonProperty Visit(GeolocationField field) - { - return CreateProperty(field, jsonProperty => - { - var geolocationSchema = new JsonSchema4 - { - AllowAdditionalProperties = false - }; - - geolocationSchema.Properties.Add("latitude", new JsonProperty - { - Type = JsonObjectType.Number, - Minimum = -90, - Maximum = 90, - IsRequired = true - }); - - geolocationSchema.Properties.Add("longitude", new JsonProperty - { - Type = JsonObjectType.Number, - Minimum = -180, - Maximum = 180, - IsRequired = true - }); - - var schemaReference = schemaResolver("GeolocationDto", geolocationSchema); - - jsonProperty.Type = JsonObjectType.Object; - jsonProperty.Reference = schemaReference; - }); - } - - public JsonProperty Visit(JsonField field) - { - return CreateProperty(field, jsonProperty => - { - jsonProperty.Type = JsonObjectType.Object; - }); - } - - public JsonProperty Visit(NumberField field) - { - return CreateProperty(field, jsonProperty => - { - jsonProperty.Type = JsonObjectType.Number; - - if (field.Properties.MinValue.HasValue) - { - jsonProperty.Minimum = (decimal)field.Properties.MinValue.Value; - } - - if (field.Properties.MaxValue.HasValue) - { - jsonProperty.Maximum = (decimal)field.Properties.MaxValue.Value; - } - }); - } - - public JsonProperty Visit(ReferencesField field) - { - return CreateProperty(field, jsonProperty => - { - var itemSchema = schemaResolver("ReferenceItem", new JsonSchema4 { Type = JsonObjectType.String }); - - jsonProperty.Type = JsonObjectType.Array; - jsonProperty.Item = itemSchema; - }); - } - - public JsonProperty Visit(StringField field) - { - return CreateProperty(field, jsonProperty => - { - jsonProperty.Type = JsonObjectType.String; - - jsonProperty.MinLength = field.Properties.MinLength; - jsonProperty.MaxLength = field.Properties.MaxLength; - - if (field.Properties.AllowedValues != null) - { - var names = jsonProperty.EnumerationNames = jsonProperty.EnumerationNames ?? new Collection(); - - foreach (var value in field.Properties.AllowedValues) - { - names.Add(value); - } - } - }); - } - - public JsonProperty Visit(TagsField field) - { - return CreateProperty(field, jsonProperty => - { - var itemSchema = schemaResolver("TagsItem", new JsonSchema4 { Type = JsonObjectType.String }); - - jsonProperty.Type = JsonObjectType.Array; - jsonProperty.Item = itemSchema; - }); - } - - private static JsonProperty CreateProperty(Field field, Action updater) - { - var property = new JsonProperty { IsRequired = field.RawProperties.IsRequired }; - - updater(property); - - return property; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/NamedElementPropertiesBase.cs b/src/Squidex.Domain.Apps.Core/Schemas/NamedElementPropertiesBase.cs deleted file mode 100644 index c5d667baf..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/NamedElementPropertiesBase.cs +++ /dev/null @@ -1,60 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public abstract class NamedElementPropertiesBase - { - private string label; - private string hints; - - protected bool IsFrozen { get; private set; } - - public string Label - { - get - { - return label; - } - set - { - ThrowIfFrozen(); - - label = value; - } - } - - public string Hints - { - get - { - return hints; - } - set - { - ThrowIfFrozen(); - - hints = value; - } - } - - protected void ThrowIfFrozen() - { - if (IsFrozen) - { - throw new InvalidOperationException("Object is frozen."); - } - } - - public void Freeze() - { - IsFrozen = true; - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/NumberField.cs b/src/Squidex.Domain.Apps.Core/Schemas/NumberField.cs deleted file mode 100644 index a56ecca26..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/NumberField.cs +++ /dev/null @@ -1,55 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class NumberField : Field - { - public NumberField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new NumberFieldProperties()) - { - } - - public NumberField(long id, string name, Partitioning partitioning, NumberFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired) - { - yield return new RequiredValidator(); - } - - if (Properties.MinValue.HasValue || Properties.MaxValue.HasValue) - { - yield return new RangeValidator(Properties.MinValue, Properties.MaxValue); - } - - if (Properties.AllowedValues != null) - { - yield return new AllowedValuesValidator(Properties.AllowedValues.ToArray()); - } - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - - public override object ConvertValue(JToken value) - { - return (double?)value; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/NumberFieldEditor.cs b/src/Squidex.Domain.Apps.Core/Schemas/NumberFieldEditor.cs deleted file mode 100644 index 2562a734f..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/NumberFieldEditor.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public enum NumberFieldEditor - { - Input, - Radio, - Dropdown, - Stars - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/NumberFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/NumberFieldProperties.cs deleted file mode 100644 index fe6e53f28..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/NumberFieldProperties.cs +++ /dev/null @@ -1,103 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Immutable; -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(NumberField))] - public sealed class NumberFieldProperties : FieldProperties - { - private double? maxValue; - private double? minValue; - private double? defaultValue; - private ImmutableList allowedValues; - private NumberFieldEditor editor; - - public double? MaxValue - { - get - { - return maxValue; - } - set - { - ThrowIfFrozen(); - - maxValue = value; - } - } - - public double? MinValue - { - get - { - return minValue; - } - set - { - ThrowIfFrozen(); - - minValue = value; - } - } - - public double? DefaultValue - { - get - { - return defaultValue; - } - set - { - ThrowIfFrozen(); - - defaultValue = value; - } - } - - public ImmutableList AllowedValues - { - get - { - return allowedValues; - } - set - { - ThrowIfFrozen(); - - allowedValues = value; - } - } - - public NumberFieldEditor Editor - { - get - { - return editor; - } - set - { - ThrowIfFrozen(); - - editor = value; - } - } - - public override JToken GetDefaultValue() - { - return DefaultValue; - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/ReferencesField.cs b/src/Squidex.Domain.Apps.Core/Schemas/ReferencesField.cs deleted file mode 100644 index 9e4b755c7..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/ReferencesField.cs +++ /dev/null @@ -1,87 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class ReferencesField : Field, IReferenceField - { - private static readonly ImmutableList EmptyIds = ImmutableList.Empty; - - public ReferencesField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new ReferencesFieldProperties()) - { - } - - public ReferencesField(long id, string name, Partitioning partitioning, ReferencesFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired || Properties.MinItems.HasValue || Properties.MaxItems.HasValue) - { - yield return new CollectionValidator(Properties.IsRequired, Properties.MinItems, Properties.MaxItems); - } - - if (Properties.SchemaId != Guid.Empty) - { - yield return new ReferencesValidator(Properties.SchemaId); - } - } - - public IEnumerable GetReferencedIds(JToken value) - { - IEnumerable result = null; - try - { - result = value?.ToObject>(); - } - catch - { - result = EmptyIds; - } - - return (result ?? EmptyIds).Union(new[] { Properties.SchemaId }); - } - - public JToken RemoveDeletedReferences(JToken value, ISet deletedReferencedIds) - { - if (value == null || value.Type == JTokenType.Null) - { - return null; - } - - if (deletedReferencedIds.Contains(Properties.SchemaId)) - { - return new JArray(); - } - - var oldReferenceIds = GetReferencedIds(value).TakeWhile(x => x != Properties.SchemaId).ToArray(); - var newReferenceIds = oldReferenceIds.Where(x => !deletedReferencedIds.Contains(x)).ToList(); - - return newReferenceIds.Count != oldReferenceIds.Length ? JToken.FromObject(newReferenceIds) : value; - } - - public override object ConvertValue(JToken value) - { - return value.ToObject>(); - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/ReferencesFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/ReferencesFieldProperties.cs deleted file mode 100644 index 7cd89ddf1..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/ReferencesFieldProperties.cs +++ /dev/null @@ -1,73 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(ReferencesField))] - public sealed class ReferencesFieldProperties : FieldProperties - { - private int? minItems; - private int? maxItems; - private Guid schemaId; - - public int? MinItems - { - get - { - return minItems; - } - set - { - ThrowIfFrozen(); - - minItems = value; - } - } - - public int? MaxItems - { - get - { - return maxItems; - } - set - { - ThrowIfFrozen(); - - maxItems = value; - } - } - - public Guid SchemaId - { - get - { - return schemaId; - } - set - { - ThrowIfFrozen(); - - schemaId = value; - } - } - - public override JToken GetDefaultValue() - { - return new JArray(); - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Schema.cs b/src/Squidex.Domain.Apps.Core/Schemas/Schema.cs deleted file mode 100644 index b8a200b5b..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Schema.cs +++ /dev/null @@ -1,170 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class Schema - { - private readonly string name; - private readonly SchemaProperties properties; - private readonly ImmutableList fields; - private readonly ImmutableDictionary fieldsById; - private readonly ImmutableDictionary fieldsByName; - private readonly bool isPublished; - - public string Name - { - get { return name; } - } - - public bool IsPublished - { - get { return isPublished; } - } - - public ImmutableList Fields - { - get { return fields; } - } - - public ImmutableDictionary FieldsById - { - get { return fieldsById; } - } - - public ImmutableDictionary FieldsByName - { - get { return fieldsByName; } - } - - public SchemaProperties Properties - { - get { return properties; } - } - - public Schema(string name, bool isPublished, SchemaProperties properties, ImmutableList fields) - { - Guard.NotNull(fields, nameof(fields)); - Guard.NotNull(properties, nameof(properties)); - Guard.NotNullOrEmpty(name, nameof(name)); - - fieldsById = fields.ToImmutableDictionary(x => x.Id); - fieldsByName = fields.ToImmutableDictionary(x => x.Name, StringComparer.OrdinalIgnoreCase); - - this.name = name; - - this.fields = fields; - - this.properties = properties; - this.properties.Freeze(); - - this.isPublished = isPublished; - } - - public static Schema Create(string name, SchemaProperties newProperties) - { - return new Schema(name, false, newProperties, ImmutableList.Empty); - } - - public Schema Update(SchemaProperties newProperties) - { - Guard.NotNull(newProperties, nameof(newProperties)); - - return new Schema(name, isPublished, newProperties, fields); - } - - public Schema UpdateField(long fieldId, FieldProperties newProperties) - { - return UpdateField(fieldId, field => field.Update(newProperties)); - } - - public Schema LockField(long fieldId) - { - return UpdateField(fieldId, field => field.Lock()); - } - - public Schema DisableField(long fieldId) - { - return UpdateField(fieldId, field => field.Disable()); - } - - public Schema EnableField(long fieldId) - { - return UpdateField(fieldId, field => field.Enable()); - } - - public Schema HideField(long fieldId) - { - return UpdateField(fieldId, field => field.Hide()); - } - - public Schema ShowField(long fieldId) - { - return UpdateField(fieldId, field => field.Show()); - } - - public Schema Publish() - { - return new Schema(name, true, properties, fields); - } - - public Schema Unpublish() - { - return new Schema(name, false, properties, fields); - } - - public Schema DeleteField(long fieldId) - { - var newFields = fields.Where(x => x.Id != fieldId).ToImmutableList(); - - return new Schema(name, isPublished, properties, newFields); - } - - public Schema UpdateField(long fieldId, Func updater) - { - Guard.NotNull(updater, nameof(updater)); - - var newFields = fields.Select(f => f.Id == fieldId ? updater(f) ?? f : f).ToImmutableList(); - - return new Schema(name, isPublished, properties, newFields); - } - - public Schema ReorderFields(List ids) - { - Guard.NotNull(ids, nameof(ids)); - - if (ids.Count != fields.Count || ids.Any(x => !fieldsById.ContainsKey(x))) - { - throw new ArgumentException("Ids must cover all fields.", nameof(ids)); - } - - var newFields = fields.OrderBy(f => ids.IndexOf(f.Id)).ToImmutableList(); - - return new Schema(name, isPublished, properties, newFields); - } - - public Schema AddField(Field field) - { - Guard.NotNull(field, nameof(field)); - - if (fieldsByName.ContainsKey(field.Name) || fieldsById.ContainsKey(field.Id)) - { - throw new ArgumentException($"A field with name '{field.Name}' already exists.", nameof(field)); - } - - var newFields = fields.Add(field); - - return new Schema(name, isPublished, properties, newFields); - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/SchemaProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/SchemaProperties.cs deleted file mode 100644 index eebe181e1..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/SchemaProperties.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class SchemaProperties : NamedElementPropertiesBase - { - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/StringField.cs b/src/Squidex.Domain.Apps.Core/Schemas/StringField.cs deleted file mode 100644 index 972ea2835..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/StringField.cs +++ /dev/null @@ -1,60 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class StringField : Field - { - public StringField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new StringFieldProperties()) - { - } - - public StringField(long id, string name, Partitioning partitioning, StringFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired) - { - yield return new RequiredStringValidator(); - } - - if (Properties.MinLength.HasValue || Properties.MaxLength.HasValue) - { - yield return new StringLengthValidator(Properties.MinLength, Properties.MaxLength); - } - - if (!string.IsNullOrWhiteSpace(Properties.Pattern)) - { - yield return new PatternValidator(Properties.Pattern, Properties.PatternMessage); - } - - if (Properties.AllowedValues != null) - { - yield return new AllowedValuesValidator(Properties.AllowedValues.ToArray()); - } - } - - public override object ConvertValue(JToken value) - { - return value.ToString(); - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/StringFieldEditor.cs b/src/Squidex.Domain.Apps.Core/Schemas/StringFieldEditor.cs deleted file mode 100644 index cdb515d5d..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/StringFieldEditor.cs +++ /dev/null @@ -1,19 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public enum StringFieldEditor - { - Input, - Markdown, - Dropdown, - Radio, - RichText, - TextArea - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/StringFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/StringFieldProperties.cs deleted file mode 100644 index daaea426f..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/StringFieldProperties.cs +++ /dev/null @@ -1,139 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Immutable; -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Json; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(StringField))] - public sealed class StringFieldProperties : FieldProperties - { - private int? minLength; - private int? maxLength; - private string pattern; - private string patternMessage; - private string defaultValue; - private ImmutableList allowedValues; - private StringFieldEditor editor; - - public int? MinLength - { - get - { - return minLength; - } - set - { - ThrowIfFrozen(); - - minLength = value; - } - } - - public int? MaxLength - { - get - { - return maxLength; - } - set - { - ThrowIfFrozen(); - - maxLength = value; - } - } - - public string DefaultValue - { - get - { - return defaultValue; - } - set - { - ThrowIfFrozen(); - - defaultValue = value; - } - } - - public string Pattern - { - get - { - return pattern; - } - set - { - ThrowIfFrozen(); - - pattern = value; - } - } - - public string PatternMessage - { - get - { - return patternMessage; - } - set - { - ThrowIfFrozen(); - - patternMessage = value; - } - } - - public ImmutableList AllowedValues - { - get - { - return allowedValues; - } - set - { - ThrowIfFrozen(); - - allowedValues = value; - } - } - - public StringFieldEditor Editor - { - get - { - return editor; - } - set - { - ThrowIfFrozen(); - - editor = value; - } - } - - public override JToken GetDefaultValue() - { - return DefaultValue; - } - - public override bool ShouldApplyDefaultValue(JToken value) - { - return value.IsNull() || (value is JValue jValue && Equals(jValue.Value, string.Empty)); - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/TagsField.cs b/src/Squidex.Domain.Apps.Core/Schemas/TagsField.cs deleted file mode 100644 index c225a8be9..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/TagsField.cs +++ /dev/null @@ -1,49 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Collections.Immutable; -using Newtonsoft.Json.Linq; -using Squidex.Domain.Apps.Core.Schemas.Validators; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class TagsField : Field - { - private static readonly ImmutableList EmptyTags = ImmutableList.Empty; - - public TagsField(long id, string name, Partitioning partitioning) - : this(id, name, partitioning, new TagsFieldProperties()) - { - } - - public TagsField(long id, string name, Partitioning partitioning, TagsFieldProperties properties) - : base(id, name, partitioning, properties) - { - } - - protected override IEnumerable CreateValidators() - { - if (Properties.IsRequired || Properties.MinItems.HasValue || Properties.MaxItems.HasValue) - { - yield return new CollectionValidator(Properties.IsRequired, Properties.MinItems, Properties.MaxItems); - } - - yield return new CollectionItemValidator(new RequiredStringValidator()); - } - - public override object ConvertValue(JToken value) - { - return value.ToObject>(); - } - - public override T Accept(IFieldVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/TagsFieldProperties.cs b/src/Squidex.Domain.Apps.Core/Schemas/TagsFieldProperties.cs deleted file mode 100644 index 4a01f28d0..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/TagsFieldProperties.cs +++ /dev/null @@ -1,57 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Newtonsoft.Json.Linq; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - [TypeName(nameof(TagsField))] - public sealed class TagsFieldProperties : FieldProperties - { - private int? minItems; - private int? maxItems; - - public int? MinItems - { - get - { - return minItems; - } - set - { - ThrowIfFrozen(); - - minItems = value; - } - } - - public int? MaxItems - { - get - { - return maxItems; - } - set - { - ThrowIfFrozen(); - - maxItems = value; - } - } - - public override JToken GetDefaultValue() - { - return new JArray(); - } - - public override T Accept(IFieldPropertiesVisitor visitor) - { - return visitor.Visit(this); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/ValidationContext.cs b/src/Squidex.Domain.Apps.Core/Schemas/ValidationContext.cs deleted file mode 100644 index e356d3614..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/ValidationContext.cs +++ /dev/null @@ -1,58 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public sealed class ValidationContext - { - private readonly Func, Guid, Task>> checkContent; - private readonly Func, Task>> checkAsset; - - public bool IsOptional { get; } - - public ValidationContext( - Func, Guid, Task>> checkContent, - Func, Task>> checkAsset) - : this(checkContent, checkAsset, false) - { - } - - private ValidationContext( - Func, Guid, Task>> checkContent, - Func, Task>> checkAsset, - bool isOptional) - { - Guard.NotNull(checkAsset, nameof(checkAsset)); - Guard.NotNull(checkContent, nameof(checkAsset)); - - this.checkContent = checkContent; - this.checkAsset = checkAsset; - - IsOptional = isOptional; - } - - public ValidationContext Optional(bool isOptional) - { - return isOptional == IsOptional ? this : new ValidationContext(checkContent, checkAsset, isOptional); - } - - public Task> GetInvalidContentIdsAsync(IEnumerable contentIds, Guid schemaId) - { - return checkContent(contentIds, schemaId); - } - - public Task> GetInvalidAssetIdsAsync(IEnumerable assetId) - { - return checkAsset(assetId); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/AllowedValuesValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/AllowedValuesValidator.cs deleted file mode 100644 index 4cacb5f39..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/AllowedValuesValidator.cs +++ /dev/null @@ -1,44 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Linq; -using System.Threading.Tasks; -using Squidex.Infrastructure; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public sealed class AllowedValuesValidator : IValidator - { - private readonly T[] allowedValues; - - public AllowedValuesValidator(params T[] allowedValues) - { - Guard.NotNull(allowedValues, nameof(allowedValues)); - - this.allowedValues = allowedValues; - } - - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value == null) - { - return TaskHelper.Done; - } - - var typedValue = (T)value; - - if (!allowedValues.Contains(typedValue)) - { - addError(" is not an allowed value."); - } - - return TaskHelper.Done; - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/AssetsValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/AssetsValidator.cs deleted file mode 100644 index ec843f437..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/AssetsValidator.cs +++ /dev/null @@ -1,29 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public sealed class AssetsValidator : IValidator - { - public async Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value is ICollection assetIds) - { - var invalidIds = await context.GetInvalidAssetIdsAsync(assetIds); - - foreach (var invalidId in invalidIds) - { - addError($" contains invalid asset '{invalidId}'."); - } - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/CollectionItemValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/CollectionItemValidator.cs deleted file mode 100644 index 7127853c2..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/CollectionItemValidator.cs +++ /dev/null @@ -1,47 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public sealed class CollectionItemValidator : IValidator - { - private readonly IValidator[] itemValidators; - - public CollectionItemValidator(params IValidator[] itemValidators) - { - Guard.NotNull(itemValidators, nameof(itemValidators)); - Guard.NotEmpty(itemValidators, nameof(itemValidators)); - - this.itemValidators = itemValidators; - } - - public async Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value is ICollection items) - { - var innerContext = context.Optional(false); - - var index = 1; - - foreach (var item in items) - { - foreach (var itemValidator in itemValidators) - { - await itemValidator.ValidateAsync(item, innerContext, e => addError(e.Replace("", $" item #{index}"))); - } - - index++; - } - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/CollectionValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/CollectionValidator.cs deleted file mode 100644 index e7fc6c9bf..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/CollectionValidator.cs +++ /dev/null @@ -1,53 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public sealed class CollectionValidator : IValidator - { - private readonly bool isRequired; - private readonly int? minItems; - private readonly int? maxItems; - - public CollectionValidator(bool isRequired, int? minItems = null, int? maxItems = null) - { - this.isRequired = isRequired; - this.minItems = minItems; - this.maxItems = maxItems; - } - - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (!(value is ICollection items) || items.Count == 0) - { - if (isRequired && !context.IsOptional) - { - addError(" is required."); - } - - return TaskHelper.Done; - } - - if (minItems.HasValue && items.Count < minItems.Value) - { - addError($" must have at least {minItems} item(s)."); - } - - if (maxItems.HasValue && items.Count > maxItems.Value) - { - addError($" must have not more than {maxItems} item(s)."); - } - - return TaskHelper.Done; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/IValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/IValidator.cs deleted file mode 100644 index 7c115bb2b..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/IValidator.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Threading.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public interface IValidator - { - Task ValidateAsync(object value, ValidationContext context, Action addError); - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/PatternValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/PatternValidator.cs deleted file mode 100644 index 6dbde5545..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/PatternValidator.cs +++ /dev/null @@ -1,47 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public class PatternValidator : IValidator - { - private readonly Regex regex; - private readonly string errorMessage; - - public PatternValidator(string pattern, string errorMessage = null) - { - this.errorMessage = errorMessage; - - regex = new Regex("^" + pattern + "$"); - } - - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value is string stringValue) - { - if (!string.IsNullOrEmpty(stringValue) && !regex.IsMatch(stringValue)) - { - if (string.IsNullOrWhiteSpace(errorMessage)) - { - addError(" is not valid."); - } - else - { - addError(errorMessage); - } - } - } - - return TaskHelper.Done; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/RangeValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/RangeValidator.cs deleted file mode 100644 index 20a507fc3..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/RangeValidator.cs +++ /dev/null @@ -1,52 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public sealed class RangeValidator : IValidator where T : struct, IComparable - { - private readonly T? min; - private readonly T? max; - - public RangeValidator(T? min, T? max) - { - if (min.HasValue && max.HasValue && min.Value.CompareTo(max.Value) >= 0) - { - throw new ArgumentException("Min value must be greater than max value.", nameof(min)); - } - - this.min = min; - this.max = max; - } - - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value == null) - { - return TaskHelper.Done; - } - - var typedValue = (T)value; - - if (min.HasValue && typedValue.CompareTo(min.Value) < 0) - { - addError($" must be greater or equals than '{min}'."); - } - - if (max.HasValue && typedValue.CompareTo(max.Value) > 0) - { - addError($" must be less or equals than '{max}'."); - } - - return TaskHelper.Done; - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/ReferencesValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/ReferencesValidator.cs deleted file mode 100644 index cfd7b7c27..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/ReferencesValidator.cs +++ /dev/null @@ -1,36 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public sealed class ReferencesValidator : IValidator - { - private readonly Guid schemaId; - - public ReferencesValidator(Guid schemaId) - { - this.schemaId = schemaId; - } - - public async Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value is ICollection contentIds) - { - var invalidIds = await context.GetInvalidContentIdsAsync(contentIds, schemaId); - - foreach (var invalidId in invalidIds) - { - addError($" contains invalid reference '{invalidId}'."); - } - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/RequiredStringValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/RequiredStringValidator.cs deleted file mode 100644 index e77105b2c..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/RequiredStringValidator.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public class RequiredStringValidator : IValidator - { - private readonly bool validateEmptyStrings; - - public RequiredStringValidator(bool validateEmptyStrings = false) - { - this.validateEmptyStrings = validateEmptyStrings; - } - - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (context.IsOptional || (value != null && !(value is string))) - { - return TaskHelper.Done; - } - - var valueAsString = (string)value; - - if (valueAsString == null || (validateEmptyStrings && string.IsNullOrWhiteSpace(valueAsString))) - { - addError(" is required."); - } - - return TaskHelper.Done; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/RequiredValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/RequiredValidator.cs deleted file mode 100644 index 6a41a6d44..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/RequiredValidator.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public class RequiredValidator : IValidator - { - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value == null && !context.IsOptional) - { - addError(" is required."); - } - - return TaskHelper.Done; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Schemas/Validators/StringLengthValidator.cs b/src/Squidex.Domain.Apps.Core/Schemas/Validators/StringLengthValidator.cs deleted file mode 100644 index 8e6add029..000000000 --- a/src/Squidex.Domain.Apps.Core/Schemas/Validators/StringLengthValidator.cs +++ /dev/null @@ -1,48 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Threading.Tasks; -using Squidex.Infrastructure.Tasks; - -namespace Squidex.Domain.Apps.Core.Schemas.Validators -{ - public class StringLengthValidator : IValidator - { - private readonly int? minLength; - private readonly int? maxLength; - - public StringLengthValidator(int? minLength, int? maxLength) - { - if (minLength.HasValue && maxLength.HasValue && minLength.Value >= maxLength.Value) - { - throw new ArgumentException("Min length must be greater than max length.", nameof(minLength)); - } - - this.minLength = minLength; - this.maxLength = maxLength; - } - - public Task ValidateAsync(object value, ValidationContext context, Action addError) - { - if (value is string stringValue && !string.IsNullOrEmpty(stringValue)) - { - if (minLength.HasValue && stringValue.Length < minLength.Value) - { - addError($" must have more than '{minLength}' characters."); - } - - if (maxLength.HasValue && stringValue.Length > maxLength.Value) - { - addError($" must have less than '{maxLength}' characters."); - } - } - - return TaskHelper.Done; - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentDataObject.cs b/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentDataObject.cs deleted file mode 100644 index 934ee5387..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentDataObject.cs +++ /dev/null @@ -1,131 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using Jint; -using Jint.Native; -using Jint.Native.Object; -using Jint.Runtime.Descriptors; -using Squidex.Domain.Apps.Core.Contents; -using Squidex.Infrastructure; - -#pragma warning disable RECS0133 // Parameter name differs in base declaration - -namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper -{ - public sealed class ContentDataObject : ObjectInstance - { - private readonly NamedContentData contentData; - private HashSet fieldsToDelete; - private Dictionary fieldProperties; - private bool isChanged; - - public ContentDataObject(Engine engine, NamedContentData contentData) - : base(engine) - { - Extensible = true; - - this.contentData = contentData; - } - - public void MarkChanged() - { - isChanged = true; - } - - public bool TryUpdate(out NamedContentData result) - { - result = contentData; - - if (isChanged) - { - if (fieldsToDelete != null) - { - foreach (var field in fieldsToDelete) - { - contentData.Remove(field); - } - } - - if (fieldProperties != null) - { - foreach (var kvp in fieldProperties) - { - if (kvp.Value.ContentField.TryUpdate(out var fieldData)) - { - contentData[kvp.Key] = fieldData; - } - } - } - } - - return isChanged; - } - - public override void RemoveOwnProperty(string propertyName) - { - if (fieldsToDelete == null) - { - fieldsToDelete = new HashSet(); - } - - fieldsToDelete.Add(propertyName); - fieldProperties?.Remove(propertyName); - - MarkChanged(); - } - - public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError) - { - EnsurePropertiesInitialized(); - - if (!fieldProperties.ContainsKey(propertyName)) - { - fieldProperties[propertyName] = new ContentDataProperty(this) { Value = desc.Value }; - } - - return true; - } - - public override void Put(string propertyName, JsValue value, bool throwOnError) - { - EnsurePropertiesInitialized(); - - fieldProperties.GetOrAdd(propertyName, x => new ContentDataProperty(this)).Value = value; - } - - public override PropertyDescriptor GetOwnProperty(string propertyName) - { - EnsurePropertiesInitialized(); - - return fieldProperties.GetOrDefault(propertyName) ?? new PropertyDescriptor(new ObjectInstance(Engine) { Extensible = true }, true, false, true); - } - - public override IEnumerable> GetOwnProperties() - { - EnsurePropertiesInitialized(); - - foreach (var property in fieldProperties) - { - yield return new KeyValuePair(property.Key, property.Value); - } - } - - private void EnsurePropertiesInitialized() - { - if (fieldProperties == null) - { - fieldProperties = new Dictionary(contentData.Count); - - foreach (var kvp in contentData) - { - fieldProperties.Add(kvp.Key, new ContentDataProperty(this, new ContentFieldObject(this, kvp.Value, false))); - } - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentDataProperty.cs b/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentDataProperty.cs deleted file mode 100644 index 943d41240..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentDataProperty.cs +++ /dev/null @@ -1,67 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Jint.Native; -using Jint.Runtime; -using Jint.Runtime.Descriptors; -using Squidex.Domain.Apps.Core.Contents; - -namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper -{ - public sealed class ContentDataProperty : PropertyDescriptor - { - private readonly ContentDataObject contentData; - private ContentFieldObject contentField; - private JsValue value; - - public override JsValue Value - { - get - { - return value; - } - set - { - if (!Equals(this.value, value)) - { - if (value == null || !value.IsObject()) - { - throw new JavaScriptException("Can only assign object to content data."); - } - - var obj = value.AsObject(); - - contentField = new ContentFieldObject(contentData, new ContentFieldData(), true); - - foreach (var kvp in obj.GetOwnProperties()) - { - contentField.Put(kvp.Key, kvp.Value.Value, true); - } - - this.value = new JsValue(contentField); - } - } - } - - public ContentFieldObject ContentField - { - get { return contentField; } - } - - public ContentDataProperty(ContentDataObject contentData, ContentFieldObject contentField = null) - : base(null, true, true, true) - { - this.contentData = contentData; - this.contentField = contentField; - - if (contentField != null) - { - value = new JsValue(contentField); - } - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentFieldObject.cs b/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentFieldObject.cs deleted file mode 100644 index f92963096..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentFieldObject.cs +++ /dev/null @@ -1,136 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using Jint.Native.Object; -using Jint.Runtime.Descriptors; -using Squidex.Domain.Apps.Core.Contents; -using Squidex.Infrastructure; - -#pragma warning disable RECS0133 // Parameter name differs in base declaration - -namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper -{ - public sealed class ContentFieldObject : ObjectInstance - { - private readonly ContentDataObject contentData; - private readonly ContentFieldData fieldData; - private HashSet valuesToDelete; - private Dictionary valueProperties; - private bool isChanged; - - public ContentFieldData FieldData - { - get { return fieldData; } - } - - public ContentFieldObject(ContentDataObject contentData, ContentFieldData fieldData, bool isNew) - : base(contentData.Engine) - { - Extensible = true; - - this.contentData = contentData; - this.fieldData = fieldData; - - if (isNew) - { - MarkChanged(); - } - } - - public void MarkChanged() - { - isChanged = true; - - contentData.MarkChanged(); - } - - public bool TryUpdate(out ContentFieldData result) - { - result = fieldData; - - if (isChanged) - { - if (valuesToDelete != null) - { - foreach (var field in valuesToDelete) - { - fieldData.Remove(field); - } - } - - if (valueProperties != null) - { - foreach (var kvp in valueProperties) - { - if (kvp.Value.IsChanged) - { - fieldData[kvp.Key] = kvp.Value.ContentValue; - } - } - } - } - - return isChanged; - } - - public override void RemoveOwnProperty(string propertyName) - { - if (valuesToDelete == null) - { - valuesToDelete = new HashSet(); - } - - valuesToDelete.Add(propertyName); - valueProperties?.Remove(propertyName); - - MarkChanged(); - } - - public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError) - { - EnsurePropertiesInitialized(); - - if (!valueProperties.ContainsKey(propertyName)) - { - valueProperties[propertyName] = new ContentFieldProperty(this) { Value = desc.Value }; - } - - return true; - } - - public override PropertyDescriptor GetOwnProperty(string propertyName) - { - EnsurePropertiesInitialized(); - - return valueProperties?.GetOrDefault(propertyName) ?? PropertyDescriptor.Undefined; - } - - public override IEnumerable> GetOwnProperties() - { - EnsurePropertiesInitialized(); - - foreach (var property in valueProperties) - { - yield return new KeyValuePair(property.Key, property.Value); - } - } - - private void EnsurePropertiesInitialized() - { - if (valueProperties == null) - { - valueProperties = new Dictionary(FieldData.Count); - - foreach (var kvp in FieldData) - { - valueProperties.Add(kvp.Key, new ContentFieldProperty(this, kvp.Value)); - } - } - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentFieldProperty.cs b/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentFieldProperty.cs deleted file mode 100644 index 11ec3918e..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/ContentFieldProperty.cs +++ /dev/null @@ -1,58 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Jint.Native; -using Jint.Runtime.Descriptors; -using Newtonsoft.Json.Linq; - -namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper -{ - public sealed class ContentFieldProperty : PropertyDescriptor - { - private readonly ContentFieldObject contentField; - private JToken contentValue; - private JsValue value; - private bool isChanged; - - public override JsValue Value - { - get - { - return value ?? (value = JsonMapper.Map(contentValue, contentField.Engine)); - } - set - { - if (!Equals(this.value, value)) - { - this.value = value; - - contentValue = null; - contentField.MarkChanged(); - - isChanged = true; - } - } - } - - public JToken ContentValue - { - get { return contentValue ?? (contentValue = JsonMapper.Map(value)); } - } - - public bool IsChanged - { - get { return isChanged; } - } - - public ContentFieldProperty(ContentFieldObject contentField, JToken contentValue = null) - : base(null, true, true, true) - { - this.contentField = contentField; - this.contentValue = contentValue; - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/JsonMapper.cs b/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/JsonMapper.cs deleted file mode 100644 index ea3a19385..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/ContentWrapper/JsonMapper.cs +++ /dev/null @@ -1,145 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Jint; -using Jint.Native; -using Jint.Native.Object; -using Newtonsoft.Json.Linq; - -namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper -{ - public static class JsonMapper - { - public static JsValue Map(JToken value, Engine engine) - { - if (value == null) - { - return JsValue.Null; - } - - switch (value.Type) - { - case JTokenType.Date: - case JTokenType.Guid: - case JTokenType.String: - case JTokenType.Uri: - case JTokenType.TimeSpan: - return new JsValue((string)value); - case JTokenType.Null: - return JsValue.Null; - case JTokenType.Undefined: - return JsValue.Undefined; - case JTokenType.Integer: - return new JsValue((long)value); - case JTokenType.Float: - return new JsValue((double)value); - case JTokenType.Boolean: - return new JsValue((bool)value); - case JTokenType.Object: - return FromObject(value, engine); - case JTokenType.Array: - { - var arr = (JArray)value; - - var target = new JsValue[arr.Count]; - - for (var i = 0; i < arr.Count; i++) - { - target[i] = Map(arr[i], engine); - } - - return engine.Array.Construct(target); - } - } - - throw new ArgumentException("Invalid json type.", nameof(value)); - } - - private static JsValue FromObject(JToken value, Engine engine) - { - var obj = (JObject)value; - - var target = new ObjectInstance(engine); - - foreach (var property in obj) - { - target.FastAddProperty(property.Key, Map(property.Value, engine), false, true, true); - } - - return target; - } - - public static JToken Map(JsValue value) - { - if (value == null || value.IsNull()) - { - return JValue.CreateNull(); - } - - if (value.IsUndefined()) - { - return JValue.CreateUndefined(); - } - - if (value.IsString()) - { - return new JValue(value.AsString()); - } - - if (value.IsBoolean()) - { - return new JValue(value.AsBoolean()); - } - - if (value.IsNumber()) - { - return new JValue(value.AsNumber()); - } - - if (value.IsDate()) - { - return new JValue(value.AsDate().ToDateTime()); - } - - if (value.IsRegExp()) - { - return JValue.CreateString(value.AsRegExp().Value?.ToString()); - } - - if (value.IsArray()) - { - var arr = value.AsArray(); - - var target = new JArray(); - - for (var i = 0; i < arr.GetLength(); i++) - { - target.Add(Map(arr.Get(i.ToString()))); - } - - return target; - } - - if (value.IsObject()) - { - var obj = value.AsObject(); - - var target = new JObject(); - - foreach (var kvp in obj.GetOwnProperties()) - { - target[kvp.Key] = Map(kvp.Value.Value); - } - - return target; - } - - throw new ArgumentException("Invalid json type.", nameof(value)); - } - } -} \ No newline at end of file diff --git a/src/Squidex.Domain.Apps.Core/Scripting/IScriptEngine.cs b/src/Squidex.Domain.Apps.Core/Scripting/IScriptEngine.cs deleted file mode 100644 index e67acdcb6..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/IScriptEngine.cs +++ /dev/null @@ -1,20 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Squidex.Domain.Apps.Core.Contents; - -namespace Squidex.Domain.Apps.Core.Scripting -{ - public interface IScriptEngine - { - void Execute(ScriptContext context, string script); - - NamedContentData ExecuteAndTransform(ScriptContext context, string script); - - NamedContentData Transform(ScriptContext context, string script); - } -} diff --git a/src/Squidex.Domain.Apps.Core/Scripting/JintScriptEngine.cs b/src/Squidex.Domain.Apps.Core/Scripting/JintScriptEngine.cs deleted file mode 100644 index c5ea72ffb..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/JintScriptEngine.cs +++ /dev/null @@ -1,177 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using Jint; -using Jint.Native.Object; -using Jint.Parser; -using Jint.Runtime; -using Squidex.Domain.Apps.Core.Contents; -using Squidex.Domain.Apps.Core.Scripting.ContentWrapper; -using Squidex.Infrastructure; - -namespace Squidex.Domain.Apps.Core.Scripting -{ - public sealed class JintScriptEngine : IScriptEngine - { - public TimeSpan Timeout { get; set; } = TimeSpan.FromMilliseconds(200); - - public void Execute(ScriptContext context, string script) - { - Guard.NotNull(context, nameof(context)); - - if (!string.IsNullOrWhiteSpace(script)) - { - var engine = CreateScriptEngine(context); - - EnableDisallow(engine); - EnableReject(engine); - - Execute(engine, script); - } - } - - public NamedContentData ExecuteAndTransform(ScriptContext context, string script) - { - Guard.NotNull(context, nameof(context)); - - var result = context.Data; - - if (!string.IsNullOrWhiteSpace(script)) - { - var engine = CreateScriptEngine(context); - - EnableDisallow(engine); - EnableReject(engine); - - engine.SetValue("operation", new Action(() => - { - var dataInstance = engine.GetValue("ctx").AsObject().Get("data"); - - if (dataInstance != null && dataInstance.IsObject() && dataInstance.AsObject() is ContentDataObject data) - { - data.TryUpdate(out result); - } - })); - - engine.SetValue("replace", new Action(() => - { - var dataInstance = engine.GetValue("ctx").AsObject().Get("data"); - - if (dataInstance != null && dataInstance.IsObject() && dataInstance.AsObject() is ContentDataObject data) - { - data.TryUpdate(out result); - } - })); - - Execute(engine, script); - } - - return result; - } - - public NamedContentData Transform(ScriptContext context, string script) - { - Guard.NotNull(context, nameof(context)); - - var result = context.Data; - - if (!string.IsNullOrWhiteSpace(script)) - { - try - { - var engine = CreateScriptEngine(context); - - engine.SetValue("replace", new Action(() => - { - var dataInstance = engine.GetValue("ctx").AsObject().Get("data"); - - if (dataInstance != null && dataInstance.IsObject() && dataInstance.AsObject() is ContentDataObject data) - { - data.TryUpdate(out result); - } - })); - - engine.Execute(script); - } - catch (Exception) - { - result = context.Data; - } - } - - return result; - } - - private static void Execute(Engine engine, string script) - { - try - { - engine.Execute(script); - } - catch (ParserException ex) - { - throw new ValidationException($"Failed to execute script with javascript syntaxs error.", new ValidationError(ex.Message)); - } - catch (JavaScriptException ex) - { - throw new ValidationException($"Failed to execute script with javascript error.", new ValidationError(ex.Message)); - } - } - - private Engine CreateScriptEngine(ScriptContext context) - { - var engine = new Engine(options => options.TimeoutInterval(Timeout).Strict()); - - var contextInstance = new ObjectInstance(engine); - - if (context.Data != null) - { - contextInstance.FastAddProperty("data", new ContentDataObject(engine, context.Data), true, true, true); - } - - if (context.OldData != null) - { - contextInstance.FastAddProperty("oldData", new ContentDataObject(engine, context.OldData), true, true, true); - } - - if (context.User != null) - { - contextInstance.FastAddProperty("user", new JintUser(engine, context.User), false, true, false); - } - - if (!string.IsNullOrWhiteSpace(context.Operation)) - { - contextInstance.FastAddProperty("operation", context.Operation, false, true, false); - } - - engine.SetValue("ctx", contextInstance); - - return engine; - } - - private static void EnableDisallow(Engine engine) - { - engine.SetValue("disallow", new Action(message => - { - var exMessage = !string.IsNullOrWhiteSpace(message) ? message : "Not allowed"; - - throw new DomainForbiddenException(exMessage); - })); - } - - private static void EnableReject(Engine engine) - { - engine.SetValue("reject", new Action(message => - { - var errors = !string.IsNullOrWhiteSpace(message) ? new[] { new ValidationError(message) } : null; - - throw new ValidationException($"Script rejected the operation.", errors); - })); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Scripting/JintUser.cs b/src/Squidex.Domain.Apps.Core/Scripting/JintUser.cs deleted file mode 100644 index 07ab6f0de..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/JintUser.cs +++ /dev/null @@ -1,49 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Linq; -using System.Security.Claims; -using Jint; -using Jint.Native; -using Jint.Native.Object; -using Squidex.Infrastructure.Security; - -namespace Squidex.Domain.Apps.Core.Scripting -{ - public sealed class JintUser : ObjectInstance - { - public JintUser(Engine engine, ClaimsPrincipal principal) - : base(engine) - { - var subjectId = principal.OpenIdSubject(); - - var isClient = string.IsNullOrWhiteSpace(subjectId); - - if (!isClient) - { - FastAddProperty("id", subjectId, false, true, false); - FastAddProperty("isClient", false, false, true, false); - } - else - { - FastAddProperty("id", principal.OpenIdClientId(), false, true, false); - FastAddProperty("isClient", true, false, true, false); - } - - FastAddProperty("email", principal.OpenIdEmail(), false, true, false); - - var claimsInstance = new ObjectInstance(engine); - - foreach (var group in principal.Claims.GroupBy(x => x.Type)) - { - claimsInstance.FastAddProperty(group.Key, engine.Array.Construct(group.Select(x => new JsValue(x.Value)).ToArray()), false, true, false); - } - - FastAddProperty("claims", claimsInstance, false, true, false); - } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Scripting/ScriptContext.cs b/src/Squidex.Domain.Apps.Core/Scripting/ScriptContext.cs deleted file mode 100644 index d3d631a40..000000000 --- a/src/Squidex.Domain.Apps.Core/Scripting/ScriptContext.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; -using System.Security.Claims; -using Squidex.Domain.Apps.Core.Contents; - -namespace Squidex.Domain.Apps.Core.Scripting -{ - public sealed class ScriptContext - { - public ClaimsPrincipal User { get; set; } - - public Guid ContentId { get; set; } - - public NamedContentData Data { get; set; } - - public NamedContentData OldData { get; set; } - - public string Operation { get; set; } - } -} diff --git a/src/Squidex.Domain.Apps.Core/Squidex.Domain.Apps.Core.csproj b/src/Squidex.Domain.Apps.Core/Squidex.Domain.Apps.Core.csproj deleted file mode 100644 index b3c89d3b9..000000000 --- a/src/Squidex.Domain.Apps.Core/Squidex.Domain.Apps.Core.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - netstandard2.0 - - - full - True - - - - - - - - - - - - - - - - - ..\..\Squidex.ruleset - - - - - diff --git a/src/Squidex.Domain.Apps.Core/Webhooks/WebhookSchema.cs b/src/Squidex.Domain.Apps.Core/Webhooks/WebhookSchema.cs deleted file mode 100644 index cd1e05d6c..000000000 --- a/src/Squidex.Domain.Apps.Core/Webhooks/WebhookSchema.cs +++ /dev/null @@ -1,24 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschränkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System; - -namespace Squidex.Domain.Apps.Core.Webhooks -{ - public sealed class WebhookSchema - { - public Guid SchemaId { get; set; } - - public bool SendCreate { get; set; } - - public bool SendUpdate { get; set; } - - public bool SendDelete { get; set; } - - public bool SendPublish { get; set; } - } -} diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj b/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj index d96916b08..0e0ab5bc1 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj @@ -16,10 +16,10 @@ - + - + ..\..\Squidex.ruleset diff --git a/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj b/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj index 9dfc0d4a6..9a624c05e 100644 --- a/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj +++ b/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj @@ -15,12 +15,12 @@ - - - + + + - + ..\..\Squidex.ruleset diff --git a/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj b/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj index bd03eadfe..1c2a9a048 100644 --- a/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj +++ b/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj @@ -11,12 +11,12 @@ - - + + - - + + ..\..\Squidex.ruleset diff --git a/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj b/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj index e266f5b80..a37303672 100644 --- a/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj +++ b/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj @@ -14,12 +14,12 @@ - - - + + + - + ..\..\Squidex.ruleset diff --git a/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj b/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj index de19eda7a..a617824d4 100644 --- a/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj +++ b/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj @@ -11,13 +11,13 @@ - - + + - + - + ..\..\Squidex.ruleset diff --git a/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj b/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj index 29032fec1..1c2499dda 100644 --- a/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj +++ b/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj b/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj index 0872cb47e..6c40134c6 100644 --- a/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj +++ b/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj b/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj index 765e70af8..7d6280309 100644 --- a/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj +++ b/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj @@ -12,11 +12,11 @@ - + - - + + ..\..\Squidex.ruleset diff --git a/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj b/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj index 043f04732..b56461f53 100644 --- a/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj +++ b/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj @@ -8,10 +8,10 @@ True - + - + diff --git a/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj b/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj index fee1b24ed..490a6b35a 100644 --- a/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj +++ b/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj @@ -14,7 +14,7 @@ - + ..\..\Squidex.ruleset diff --git a/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj b/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj index 60be0d9a3..f2094120d 100644 --- a/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj +++ b/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj @@ -8,23 +8,23 @@ True - - - - - + + + + + - + - - + + - - + + ..\..\Squidex.ruleset diff --git a/src/Squidex/Areas/Api/Config/Swagger/SwaggerExtensions.cs b/src/Squidex/Areas/Api/Config/Swagger/SwaggerExtensions.cs index abda24f26..1cdea31b5 100644 --- a/src/Squidex/Areas/Api/Config/Swagger/SwaggerExtensions.cs +++ b/src/Squidex/Areas/Api/Config/Swagger/SwaggerExtensions.cs @@ -8,7 +8,9 @@ using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using NSwag.AspNetCore; +using Squidex.Config; namespace Squidex.Areas.Api.Config.Swagger { @@ -16,9 +18,16 @@ namespace Squidex.Areas.Api.Config.Swagger { public static void UseMySwagger(this IApplicationBuilder app) { - var settings = app.ApplicationServices.GetService(); + var urlOptions = app.ApplicationServices.GetService>().Value; - app.UseSwagger(typeof(SwaggerExtensions).GetTypeInfo().Assembly, settings); + app.UseSwagger(typeof(SwaggerExtensions).GetTypeInfo().Assembly, settings => + { + settings.AddAssetODataParams(); + settings.ConfigureNames(); + settings.ConfigurePaths(urlOptions); + settings.ConfigureSchemaSettings(); + settings.ConfigureIdentity(urlOptions); + }); } } } diff --git a/src/Squidex/Areas/Api/Config/Swagger/SwaggerServices.cs b/src/Squidex/Areas/Api/Config/Swagger/SwaggerServices.cs index f04c2e960..8dcb687d8 100644 --- a/src/Squidex/Areas/Api/Config/Swagger/SwaggerServices.cs +++ b/src/Squidex/Areas/Api/Config/Swagger/SwaggerServices.cs @@ -12,6 +12,7 @@ using NJsonSchema; using NJsonSchema.Generation.TypeMappers; using NodaTime; using NSwag.AspNetCore; +using NSwag.SwaggerGeneration; using NSwag.SwaggerGeneration.Processors.Security; using Squidex.Areas.Api.Controllers.Contents.Generator; using Squidex.Config; @@ -24,13 +25,13 @@ namespace Squidex.Areas.Api.Config.Swagger { public static void AddMySwaggerSettings(this IServiceCollection services) { - services.AddSingleton(typeof(SwaggerSettings), s => + services.AddSingleton(typeof(SwaggerSettings), s => { var urlOptions = s.GetService>().Value; - var settings = - new SwaggerSettings { Title = "Squidex API", Version = "1.0", IsAspNetCore = false } + var settings = new SwaggerSettings() .AddAssetODataParams() + .ConfigureNames() .ConfigurePaths(urlOptions) .ConfigureSchemaSettings() .ConfigureIdentity(urlOptions); @@ -41,25 +42,33 @@ namespace Squidex.Areas.Api.Config.Swagger services.AddTransient(); } - private static SwaggerSettings AddAssetODataParams(this SwaggerSettings settings) + public static SwaggerSettings ConfigureNames(this SwaggerSettings settings) where T : SwaggerGeneratorSettings, new() { - settings.OperationProcessors.Add(new ODataQueryParamsProcessor("/apps/{app}/assets", "assets", false)); + settings.GeneratorSettings.Title = "Squidex API"; + settings.GeneratorSettings.Version = "1.0"; return settings; } - private static SwaggerSettings ConfigureIdentity(this SwaggerSettings settings, MyUrlsOptions urlOptions) + public static SwaggerSettings AddAssetODataParams(this SwaggerSettings settings) where T : SwaggerGeneratorSettings, new() { - settings.DocumentProcessors.Add( + settings.GeneratorSettings.OperationProcessors.Add(new ODataQueryParamsProcessor("/apps/{app}/assets", "assets", false)); + + return settings; + } + + public static SwaggerSettings ConfigureIdentity(this SwaggerSettings settings, MyUrlsOptions urlOptions) where T : SwaggerGeneratorSettings, new() + { + settings.GeneratorSettings.DocumentProcessors.Add( new SecurityDefinitionAppender( Constants.SecurityDefinition, SwaggerHelper.CreateOAuthSchema(urlOptions))); - settings.OperationProcessors.Add(new ScopesProcessor()); + settings.GeneratorSettings.OperationProcessors.Add(new ScopesProcessor()); return settings; } - private static SwaggerSettings ConfigurePaths(this SwaggerSettings settings, MyUrlsOptions urlOptions) + public static SwaggerSettings ConfigurePaths(this SwaggerSettings settings, MyUrlsOptions urlOptions) where T : SwaggerGeneratorSettings, new() { settings.SwaggerRoute = $"{Constants.ApiPrefix}/swagger/v1/swagger.json"; @@ -77,12 +86,12 @@ namespace Squidex.Areas.Api.Config.Swagger return settings; } - private static SwaggerSettings ConfigureSchemaSettings(this SwaggerSettings settings) + public static SwaggerSettings ConfigureSchemaSettings(this SwaggerSettings settings) where T : SwaggerGeneratorSettings, new() { - settings.DefaultEnumHandling = EnumHandling.String; - settings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase; + settings.GeneratorSettings.DefaultEnumHandling = EnumHandling.String; + settings.GeneratorSettings.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase; - settings.TypeMappers = new List + settings.GeneratorSettings.TypeMappers = new List { new PrimitiveTypeMapper(typeof(Instant), schema => { @@ -93,10 +102,10 @@ namespace Squidex.Areas.Api.Config.Swagger new PrimitiveTypeMapper(typeof(RefToken), s => s.Type = JsonObjectType.String) }; - settings.DocumentProcessors.Add(new XmlTagProcessor()); + settings.GeneratorSettings.DocumentProcessors.Add(new XmlTagProcessor()); - settings.OperationProcessors.Add(new XmlTagProcessor()); - settings.OperationProcessors.Add(new XmlResponseTypesProcessor()); + settings.GeneratorSettings.OperationProcessors.Add(new XmlTagProcessor()); + settings.GeneratorSettings.OperationProcessors.Add(new XmlResponseTypesProcessor()); return settings; } diff --git a/src/Squidex/Areas/Api/Config/Swagger/XmlTagProcessor.cs b/src/Squidex/Areas/Api/Config/Swagger/XmlTagProcessor.cs index 61e6afa33..6e63a03fb 100644 --- a/src/Squidex/Areas/Api/Config/Swagger/XmlTagProcessor.cs +++ b/src/Squidex/Areas/Api/Config/Swagger/XmlTagProcessor.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Linq; using System.Reflection; using System.Threading.Tasks; using NJsonSchema.Infrastructure; @@ -25,7 +26,7 @@ namespace Squidex.Areas.Api.Config.Swagger if (tagAttribute != null) { - var tag = context.Document.Tags.Find(x => x.Name == tagAttribute.Name); + var tag = context.Document.Tags.FirstOrDefault(x => x.Name == tagAttribute.Name); if (tag != null) { diff --git a/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemaSwaggerGenerator.cs b/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemaSwaggerGenerator.cs index d52320731..4b0538caa 100644 --- a/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemaSwaggerGenerator.cs +++ b/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemaSwaggerGenerator.cs @@ -85,7 +85,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator Name = schemaName, Description = $"API to managed {schemaName} contents." }); - var schemaOperations = new List + var schemaOperations = new List { GenerateSchemaQueryOperation(), GenerateSchemaCreateOperation(), @@ -105,7 +105,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator } } - private SwaggerOperations GenerateSchemaQueryOperation() + private SwaggerPathItem GenerateSchemaQueryOperation() { return AddOperation(SwaggerOperationMethod.Get, null, $"{appPath}/{schemaPath}", operation => { @@ -125,7 +125,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaGetOperation() + private SwaggerPathItem GenerateSchemaGetOperation() { return AddOperation(SwaggerOperationMethod.Get, schemaName, $"{appPath}/{schemaPath}/{{id}}", operation => { @@ -137,7 +137,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaCreateOperation() + private SwaggerPathItem GenerateSchemaCreateOperation() { return AddOperation(SwaggerOperationMethod.Post, null, $"{appPath}/{schemaPath}", operation => { @@ -152,7 +152,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaUpdateOperation() + private SwaggerPathItem GenerateSchemaUpdateOperation() { return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appPath}/{schemaPath}/{{id}}", operation => { @@ -166,7 +166,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaPatchOperation() + private SwaggerPathItem GenerateSchemaPatchOperation() { return AddOperation(SwaggerOperationMethod.Patch, schemaName, $"{appPath}/{schemaPath}/{{id}}", operation => { @@ -180,7 +180,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaPublishOperation() + private SwaggerPathItem GenerateSchemaPublishOperation() { return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appPath}/{schemaPath}/{{id}}/publish", operation => { @@ -192,7 +192,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaUnpublishOperation() + private SwaggerPathItem GenerateSchemaUnpublishOperation() { return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appPath}/{schemaPath}/{{id}}/unpublish", operation => { @@ -204,7 +204,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaArchiveOperation() + private SwaggerPathItem GenerateSchemaArchiveOperation() { return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appPath}/{schemaPath}/{{id}}/archive", operation => { @@ -216,7 +216,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaRestoreOperation() + private SwaggerPathItem GenerateSchemaRestoreOperation() { return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appPath}/{schemaPath}/{{id}}/restore", operation => { @@ -228,7 +228,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations GenerateSchemaDeleteOperation() + private SwaggerPathItem GenerateSchemaDeleteOperation() { return AddOperation(SwaggerOperationMethod.Delete, schemaName, $"{appPath}/{schemaPath}/{{id}}/", operation => { @@ -240,7 +240,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator }); } - private SwaggerOperations AddOperation(SwaggerOperationMethod method, string entityName, string path, Action updater) + private SwaggerPathItem AddOperation(SwaggerOperationMethod method, string entityName, string path, Action updater) { var operations = document.Paths.GetOrAddNew(path); var operation = new SwaggerOperation(); diff --git a/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasSwaggerGenerator.cs b/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasSwaggerGenerator.cs index adf41afad..03d7120bd 100644 --- a/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasSwaggerGenerator.cs +++ b/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasSwaggerGenerator.cs @@ -25,13 +25,13 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator public sealed class SchemasSwaggerGenerator { private readonly HttpContext context; - private readonly SwaggerSettings settings; + private readonly SwaggerSettings settings; private readonly MyUrlsOptions urlOptions; private SwaggerJsonSchemaGenerator schemaGenerator; private JsonSchemaResolver schemaResolver; private SwaggerDocument document; - public SchemasSwaggerGenerator(IHttpContextAccessor context, SwaggerSettings settings, IOptions urlOptions) + public SchemasSwaggerGenerator(IHttpContextAccessor context, SwaggerSettings settings, IOptions urlOptions) { this.context = context.HttpContext; this.settings = settings; @@ -42,8 +42,8 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator { document = SwaggerHelper.CreateApiDocument(context, urlOptions, app.Name); - schemaGenerator = new SwaggerJsonSchemaGenerator(settings); - schemaResolver = new SwaggerSchemaResolver(document, settings); + schemaGenerator = new SwaggerJsonSchemaGenerator(settings.GeneratorSettings); + schemaResolver = new SwaggerSchemaResolver(document, settings.GeneratorSettings); GenerateSchemasOperations(schemas, app); diff --git a/src/Squidex/Pipeline/FileCallbackResultExecutor.cs b/src/Squidex/Pipeline/FileCallbackResultExecutor.cs index d4b5e3909..72d1d2ef8 100644 --- a/src/Squidex/Pipeline/FileCallbackResultExecutor.cs +++ b/src/Squidex/Pipeline/FileCallbackResultExecutor.cs @@ -8,7 +8,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Logging; namespace Squidex.Pipeline @@ -24,7 +24,7 @@ namespace Squidex.Pipeline { try { - SetHeadersAndLog(context, result, null); + SetHeadersAndLog(context, result, null, false); await result.Callback(context.HttpContext.Response.Body); } diff --git a/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs b/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs index 9f92da4da..e8b41562e 100644 --- a/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs +++ b/src/Squidex/Pipeline/Swagger/SwaggerHelper.cs @@ -108,7 +108,7 @@ namespace Squidex.Pipeline.Swagger { var errorType = typeof(ErrorDto); - return await schemaGenerator.GenerateWithReference(errorType, Enumerable.Empty(), resolver); + return await schemaGenerator.GenerateWithReferenceAsync(errorType, Enumerable.Empty(), resolver); } public static void AddQueryParameter(this SwaggerOperation operation, string name, JsonObjectType type, string description = null) diff --git a/src/Squidex/Squidex.csproj b/src/Squidex/Squidex.csproj index 040d73240..cac6394bb 100644 --- a/src/Squidex/Squidex.csproj +++ b/src/Squidex/Squidex.csproj @@ -5,7 +5,7 @@ $(NoWarn);CS1591;1591;1573;1572;NU1605 Squidex true - netcoreapp2.0 + netcoreapp2.1 Latest true @@ -52,42 +52,42 @@ - + - - - - - - - - - - - + + + + + + + + + + + - + - - - + + + - + - + - + diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientJsonTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientJsonTests.cs index d764aa151..66fac6cec 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientJsonTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientJsonTests.cs @@ -36,7 +36,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var appClients = JToken.FromObject(clients, serializer).ToObject(serializer); - appClients.ShouldBeEquivalentTo(clients); + appClients.Should().BeEquivalentTo(clients); } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientsTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientsTests.cs index 04841de9c..1c5b606ef 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientsTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppClientsTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var clients_1 = clients_0.Add("2", "my-secret"); - clients_1["2"].ShouldBeEquivalentTo(new AppClient("2", "my-secret", AppClientPermission.Editor)); + clients_1["2"].Should().BeEquivalentTo(new AppClient("2", "my-secret", AppClientPermission.Editor)); } [Fact] @@ -31,7 +31,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var clients_1 = clients_0.Add("2", new AppClient("my-name", "my-secret", AppClientPermission.Reader)); - clients_1["2"].ShouldBeEquivalentTo(new AppClient("my-name", "my-secret", AppClientPermission.Reader)); + clients_1["2"].Should().BeEquivalentTo(new AppClient("my-name", "my-secret", AppClientPermission.Reader)); } [Fact] @@ -47,7 +47,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var clients_1 = clients_0.Rename("1", "new-name"); - clients_1["1"].ShouldBeEquivalentTo(new AppClient("new-name", "my-secret", AppClientPermission.Editor)); + clients_1["1"].Should().BeEquivalentTo(new AppClient("new-name", "my-secret", AppClientPermission.Editor)); } [Fact] @@ -63,7 +63,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var client_1 = clients_0.Update("1", AppClientPermission.Reader); - client_1["1"].ShouldBeEquivalentTo(new AppClient("1", "my-secret", AppClientPermission.Reader)); + client_1["1"].Should().BeEquivalentTo(new AppClient("1", "my-secret", AppClientPermission.Reader)); } [Fact] diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppContributorsJsonTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppContributorsJsonTests.cs index 41d1d6806..7b674ce74 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppContributorsJsonTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppContributorsJsonTests.cs @@ -28,7 +28,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var serialized = JToken.FromObject(contributors, serializer).ToObject(serializer); - serialized.ShouldBeEquivalentTo(contributors); + serialized.Should().BeEquivalentTo(contributors); } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternJsonTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternJsonTests.cs index 28a7cb4d8..4a3739352 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternJsonTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternJsonTests.cs @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var appPatterns = JToken.FromObject(patterns, serializer).ToObject(serializer); - appPatterns.ShouldBeEquivalentTo(patterns); + appPatterns.Should().BeEquivalentTo(patterns); } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternsTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternsTests.cs index 5fcd7eea7..e035152dc 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternsTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPatternsTests.cs @@ -30,7 +30,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var patterns_2 = patterns_1.Add(id, "NewPattern", "New Pattern", "Message"); - patterns_2[id].ShouldBeEquivalentTo(new AppPattern("NewPattern", "New Pattern", "Message")); + patterns_2[id].Should().BeEquivalentTo(new AppPattern("NewPattern", "New Pattern", "Message")); } [Fact] @@ -46,7 +46,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var patterns_2 = patterns_1.Update(firstId, "UpdatePattern", "Update Pattern", "Message"); - patterns_2[firstId].ShouldBeEquivalentTo(new AppPattern("UpdatePattern", "Update Pattern", "Message")); + patterns_2[firstId].Should().BeEquivalentTo(new AppPattern("UpdatePattern", "Update Pattern", "Message")); } [Fact] diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPlanTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPlanTests.cs index 45f0d3b10..4cf183ab3 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPlanTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/AppPlanTests.cs @@ -25,7 +25,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var serialized = JToken.FromObject(sut, serializer).ToObject(serializer); - serialized.ShouldBeEquivalentTo(sut); + serialized.Should().BeEquivalentTo(sut); } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigJsonTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigJsonTests.cs index 2e7efdd1c..6c560ed06 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigJsonTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigJsonTests.cs @@ -32,7 +32,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var serialized = JToken.FromObject(sut, serializer).ToObject(serializer); - serialized.ShouldBeEquivalentTo(sut); + serialized.Should().BeEquivalentTo(sut); Assert.Same(serialized.FirstOrDefault(x => x.Key == "it"), serialized.Master); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigTests.cs index 622a9507f..868d4dd8c 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Apps/LanguagesConfigTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var config_0 = LanguagesConfig.Build(Language.DE); - config_0.OfType().ToList().ShouldBeEquivalentTo( + config_0.OfType().ToList().Should().BeEquivalentTo( new List { new LanguageConfig(Language.DE) @@ -39,7 +39,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps { var config_0 = LanguagesConfig.Build(Language.DE, Language.EN, Language.IT); - config_0.OfType().ToList().ShouldBeEquivalentTo( + config_0.OfType().ToList().Should().BeEquivalentTo( new List { new LanguageConfig(Language.DE), @@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps }; var config_0 = LanguagesConfig.Build(configs); - config_0.OfType().ToList().ShouldBeEquivalentTo(configs); + config_0.OfType().ToList().Should().BeEquivalentTo(configs); Assert.Equal(configs[0], config_0.Master); Assert.Same(configs[0], config_0.Master); @@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var config_0 = LanguagesConfig.Build(Language.DE); var config_1 = config_0.Set(new LanguageConfig(Language.IT)); - config_1.OfType().ToList().ShouldBeEquivalentTo( + config_1.OfType().ToList().Should().BeEquivalentTo( new List { new LanguageConfig(Language.DE), @@ -141,7 +141,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps Assert.Same(config_1.Master, config_1.OfType().FirstOrDefault(x => x.Language == Language.DE)); - config_1.ToList().ShouldBeEquivalentTo( + config_1.ToList().Should().BeEquivalentTo( new List { new LanguageConfig(Language.DE), @@ -159,7 +159,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps new LanguageConfig(Language.RU, false, Language.DE, Language.IT)); var config_1 = config_0.Remove(Language.IT); - config_1.OfType().ToList().ShouldBeEquivalentTo( + config_1.OfType().ToList().Should().BeEquivalentTo( new List { new LanguageConfig(Language.DE), @@ -190,7 +190,7 @@ namespace Squidex.Domain.Apps.Core.Model.Apps var config_1 = config_0.Set(new LanguageConfig(Language.IT)); var config_2 = config_1.Set(new LanguageConfig(Language.IT, true, Language.DE)); - config_2.OfType().ToList().ShouldBeEquivalentTo( + config_2.OfType().ToList().Should().BeEquivalentTo( new List { new LanguageConfig(Language.DE), diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs index fe0dfac5a..44e26d2e1 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs @@ -131,7 +131,7 @@ namespace Squidex.Domain.Apps.Core.Model.Rules var appClients = JToken.FromObject(rule_1, serializer).ToObject(serializer); - appClients.ShouldBeEquivalentTo(rule_0); + appClients.Should().BeEquivalentTo(rule_0); } [Theory] diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs index 8b9dfcc3b..8dacfd80a 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaTests.cs @@ -284,7 +284,7 @@ namespace Squidex.Domain.Apps.Core.Model.Schemas var schemaSource = TestData.MixedSchema(); var schemaTarget = JToken.FromObject(schemaSource, serializer).ToObject(serializer); - schemaTarget.ShouldBeEquivalentTo(schemaSource); + schemaTarget.Should().BeEquivalentTo(schemaSource); } private static RootField CreateField(int id) diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ArrayFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ArrayFieldTests.cs index 4c6030662..44ee87e03 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ArrayFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ArrayFieldTests.cs @@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -76,7 +76,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync("invalid", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -87,7 +87,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(new JObject(), new JObject()), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have at least 3 item(s)." }); } @@ -98,7 +98,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(new JObject(), new JObject()), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have not more than 1 item(s)." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/AssetsFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/AssetsFieldTests.cs index bea569525..128189c05 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/AssetsFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/AssetsFieldTests.cs @@ -99,7 +99,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -110,7 +110,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -121,7 +121,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync("invalid", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -132,7 +132,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, document.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have at least 3 item(s)." }); } @@ -143,7 +143,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, document.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have not more than 1 item(s)." }); } @@ -156,7 +156,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(assetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[1]: Id '{assetId}' not found." }); } @@ -167,7 +167,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[1]: '4 kB' less than minimum of '5 kB'." }); } @@ -178,7 +178,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[2]: '8 kB' greater than maximum of '5 kB'." }); } @@ -189,7 +189,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[1]: Not an image." }); } @@ -200,7 +200,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[2]: Width '800px' less than minimum of '1000px'." }); } @@ -211,7 +211,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[2]: Width '800px' greater than maximum of '700px'." }); } @@ -222,7 +222,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[2]: Height '600px' less than minimum of '800px'." }); } @@ -233,7 +233,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[2]: Height '600px' greater than maximum of '500px'." }); } @@ -244,7 +244,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "[2]: Aspect ratio not '1:1'." }); } @@ -255,7 +255,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(document.AssetId, image.AssetId), errors, ctx); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"[1]: Invalid file extension.", diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/BooleanFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/BooleanFieldTests.cs index 2c63b643b..537f8d9a7 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/BooleanFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/BooleanFieldTests.cs @@ -53,7 +53,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -64,7 +64,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("Invalid"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ContentValidationTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ContentValidationTests.cs index 299609881..b32fe063d 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ContentValidationTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ContentValidationTests.cs @@ -35,7 +35,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("unknown: Not a known field.", "unknown") @@ -56,7 +56,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field: Must be less or equals than '100'.", "my-field") @@ -77,7 +77,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(es): Not a known invariant value.", "my-field(es)"), @@ -96,7 +96,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(de): Field is required.", "my-field(de)"), @@ -115,7 +115,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field: Field is required.", "my-field") @@ -136,7 +136,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(xx): Not a known language.", "my-field(xx)") @@ -179,7 +179,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidateAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(es): Not a known language.", "my-field(es)"), @@ -197,7 +197,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("unknown: Not a known field.", "unknown") @@ -218,7 +218,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field: Must be less or equals than '100'.", "my-field") @@ -239,7 +239,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(es): Not a known invariant value.", "my-field(es)"), @@ -289,7 +289,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(xx): Not a known language.", "my-field(xx)") @@ -310,7 +310,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field(es): Not a known language.", "my-field(es)"), @@ -336,7 +336,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await data.ValidatePartialAsync(context, schema, languagesConfig.ToResolver(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("my-field[1].my-nested: Field is required.", "my-field[1].my-nested"), diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/DateTimeFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/DateTimeFieldTests.cs index 7950209ea..2c6ff0c72 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/DateTimeFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/DateTimeFieldTests.cs @@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -56,7 +56,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(FutureDays(0)), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"Must be greater or equals than '{FutureDays(10)}'." }); } @@ -67,7 +67,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(FutureDays(20)), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"Must be less or equals than '{FutureDays(10)}'." }); } @@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("Invalid"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(123), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/GeolocationFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/GeolocationFieldTests.cs index 65ad9140b..c19149e6b 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/GeolocationFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/GeolocationFieldTests.cs @@ -61,7 +61,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(geolocation), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -76,7 +76,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(geolocation), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -92,7 +92,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(geolocation), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -103,7 +103,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(JValue.CreateNull()), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/JsonFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/JsonFieldTests.cs index 7e2844cb2..b6cb06f80 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/JsonFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/JsonFieldTests.cs @@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(JValue.CreateNull()), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/NumberFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/NumberFieldTests.cs index d62b93f05..469583d36 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/NumberFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/NumberFieldTests.cs @@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(5), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must be greater or equals than '10'." }); } @@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(20), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must be less or equals than '10'." }); } @@ -77,7 +77,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(20), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not an allowed value." }); } @@ -88,7 +88,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("Invalid"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ReferencesFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ReferencesFieldTests.cs index 7d2781f5c..768b781bc 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ReferencesFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/ReferencesFieldTests.cs @@ -56,7 +56,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -67,7 +67,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync("invalid", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(Guid.NewGuid(), Guid.NewGuid()), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have at least 3 item(s)." }); } @@ -100,7 +100,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(Guid.NewGuid(), Guid.NewGuid()), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have not more than 1 item(s)." }); } @@ -113,7 +113,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(referenceId), errors, ValidationTestExtensions.InvalidReferences(referenceId)); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { $"Contains invalid reference '{referenceId}'." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/StringFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/StringFieldTests.cs index 0f4329e43..87dd5f4f6 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/StringFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/StringFieldTests.cs @@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("123"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have more than '10' characters." }); } @@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("12345678"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have less than '5' characters." }); } @@ -77,7 +77,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("Bar"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not an allowed value." }); } @@ -88,7 +88,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("abc"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not valid." }); } @@ -99,7 +99,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("abc"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Custom Error Message." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/TagsFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/TagsFieldTests.cs index 6b96f8df2..6b763aadc 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/TagsFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/TagsFieldTests.cs @@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(null), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue(), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -76,7 +76,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync("invalid", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not a valid value." }); } @@ -87,7 +87,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("tag-1", "tag-2"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have at least 3 item(s)." }); } @@ -98,7 +98,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent await sut.ValidateAsync(CreateValue("tag-1", "tag-2"), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have not more than 1 item(s)." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AllowedValuesValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AllowedValuesValidatorTests.cs index e9165a47c..69a600609 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AllowedValuesValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/AllowedValuesValidatorTests.cs @@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(50, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not an allowed value." }); } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionItemValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionItemValidatorTests.cs index 800ddc0c7..eee055db6 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionItemValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionItemValidatorTests.cs @@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(new List { 2, 1, 4, 5 }, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "[2]: Must be greater or equals than '2'.", diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionValidatorTests.cs index 4d31d0972..7f3301d0c 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/CollectionValidatorTests.cs @@ -44,7 +44,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(null, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(new List { 1 }, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have at least 2 item(s)." }); } @@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(new List { 1, 2, 3, 4 }, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have not more than 3 item(s)." }); } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/PatternValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/PatternValidatorTests.cs index a15f390e0..2d14038c9 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/PatternValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/PatternValidatorTests.cs @@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync("foo", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Not valid." }); } @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync("foo", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Custom Error Message." }); } @@ -76,7 +76,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync("https://archiverbx.blob.core.windows.net/static/C:/Users/USR/Documents/Projects/PROJ/static/images/full/1234567890.jpg", errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Regex is too slow." }); } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RangeValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RangeValidatorTests.cs index 4d232d10d..e33749ea1 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RangeValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RangeValidatorTests.cs @@ -57,7 +57,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(1500, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must be greater or equals than '2000'." }); } @@ -68,7 +68,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(1500, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must be less or equals than '1000'." }); } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredStringValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredStringValidatorTests.cs index 63b065d59..9a94dfa87 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredStringValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredStringValidatorTests.cs @@ -58,7 +58,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(string.Empty, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } @@ -69,7 +69,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(null, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredValidatorTests.cs index e2a13ce67..852485cec 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/RequiredValidatorTests.cs @@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(null, errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Field is required." }); } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/StringLengthValidatorTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/StringLengthValidatorTests.cs index 5e08b43a6..518549a60 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/StringLengthValidatorTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Operations/ValidateContent/Validators/StringLengthValidatorTests.cs @@ -68,7 +68,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(CreateString(1500), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have more than '2000' characters." }); } @@ -79,7 +79,7 @@ namespace Squidex.Domain.Apps.Core.Operations.ValidateContent.Validators await sut.ValidateAsync(CreateString(1500), errors); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new[] { "Must have less than '1000' characters." }); } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj b/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj index b3946e52a..68fbe2788 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj +++ b/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp2.0 + netcoreapp2.1 Squidex.Domain.Apps.Core @@ -10,18 +10,15 @@ - - - + + + - + - - - ..\..\Squidex.ruleset diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Billing/ConfigAppLimitsProviderTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Billing/ConfigAppLimitsProviderTests.cs index 059164011..899a35c7a 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Billing/ConfigAppLimitsProviderTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Billing/ConfigAppLimitsProviderTests.cs @@ -53,7 +53,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing { var sut = new ConfigAppPlansProvider(Plans); - Plans.OrderBy(x => x.MaxApiCalls).ShouldBeEquivalentTo(sut.GetAvailablePlans()); + Plans.OrderBy(x => x.MaxApiCalls).Should().BeEquivalentTo(sut.GetAvailablePlans()); } [Theory] @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var plan = sut.GetPlanForApp(CreateApp(planId)); - plan.ShouldBeEquivalentTo(InfinitePlan); + plan.Should().BeEquivalentTo(InfinitePlan); } [Fact] @@ -75,7 +75,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var plan = sut.GetPlanForApp(CreateApp("basic")); - plan.ShouldBeEquivalentTo(BasicPlan); + plan.Should().BeEquivalentTo(BasicPlan); } [Fact] @@ -85,7 +85,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var plan = sut.GetPlanForApp(CreateApp("basic_yearly")); - plan.ShouldBeEquivalentTo(BasicPlan); + plan.Should().BeEquivalentTo(BasicPlan); } [Fact] @@ -95,7 +95,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var plan = sut.GetPlanForApp(CreateApp("enterprise")); - plan.ShouldBeEquivalentTo(FreePlan); + plan.Should().BeEquivalentTo(FreePlan); } [Fact] @@ -105,7 +105,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var upgradePlan = sut.GetPlanUpgrade(null); - upgradePlan.ShouldBeEquivalentTo(BasicPlan); + upgradePlan.Should().BeEquivalentTo(BasicPlan); } [Fact] @@ -115,7 +115,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var upgradePlan = sut.GetPlanUpgradeForApp(CreateApp("enterprise")); - upgradePlan.ShouldBeEquivalentTo(BasicPlan); + upgradePlan.Should().BeEquivalentTo(BasicPlan); } [Fact] @@ -135,7 +135,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Billing var upgradePlan = sut.GetPlanUpgradeForApp(CreateApp("free")); - upgradePlan.ShouldBeEquivalentTo(BasicPlan); + upgradePlan.Should().BeEquivalentTo(BasicPlan); } [Fact] diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AlgoliaActionTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AlgoliaActionTests.cs index 8b5c10ba5..6592c2b77 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AlgoliaActionTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AlgoliaActionTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Application ID is required.", "AppId") @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Api Key is required.", "ApiKey") @@ -51,7 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Index name is required.", "IndexName") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs index afa89bae3..b53e0db90 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Connection string is required.", "ConnectionString") @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Queue name is required.", "Queue") @@ -51,7 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Queue name must be valid azure queue name.", "Queue") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/ElasticSearchActionTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/ElasticSearchActionTests.cs index 024aa1a46..c499f6499 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/ElasticSearchActionTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/ElasticSearchActionTests.cs @@ -24,7 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Host is required and must be an absolute URL.", "Host") @@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Host is required and must be an absolute URL.", "Host") @@ -52,7 +52,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Index name is required.", "IndexName") @@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Type name is required.", "IndexType") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/FastlyActionTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/FastlyActionTests.cs index aedc7c775..a38d627fe 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/FastlyActionTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/FastlyActionTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Service ID is required.", "ServiceId") @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Api Key is required.", "ApiKey") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/SlackActionTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/SlackActionTests.cs index 8077cc173..f6b248446 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/SlackActionTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/SlackActionTests.cs @@ -24,7 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Webhook URL is required and must be an absolute URL.", "WebhookUrl") @@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Webhook URL is required and must be an absolute URL.", "WebhookUrl") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/WebhookActionTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/WebhookActionTests.cs index 05b284292..6a523a4f1 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/WebhookActionTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/WebhookActionTests.cs @@ -24,7 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("URL is required and must be an absolute URL.", "Url") @@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions var errors = await RuleActionValidator.ValidateAsync(action); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("URL is required and must be an absolute URL.", "Url") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ArrayFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ArrayFieldPropertiesTests.cs index 74a2ca646..f27c7f922 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ArrayFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ArrayFieldPropertiesTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max items must be greater than min items.", "MinItems", "MaxItems") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/AssetsFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/AssetsFieldPropertiesTests.cs index f031cd5eb..8f6d724d7 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/AssetsFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/AssetsFieldPropertiesTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max items must be greater than min items.", "MinItems", "MaxItems") @@ -37,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max width must be greater than min width.", "MinWidth", "MaxWidth") @@ -51,7 +51,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max height must be greater than min height.", "MinHeight", "MaxHeight") @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max size must be greater than min size.", "MinSize", "MaxSize") @@ -79,7 +79,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Aspect width and height is required.", "AspectWidth", "AspectHeight") @@ -93,7 +93,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Aspect width and height is required.", "AspectWidth", "AspectHeight") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/BooleanFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/BooleanFieldPropertiesTests.cs index d111be098..d35c030f7 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/BooleanFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/BooleanFieldPropertiesTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Editor is not a valid value.", "Editor") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/DateTimeFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/DateTimeFieldPropertiesTests.cs index 6850b50ab..7137b4527 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/DateTimeFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/DateTimeFieldPropertiesTests.cs @@ -40,7 +40,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Default value must be greater than min value.", "DefaultValue") @@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Default value must be less than max value.", "DefaultValue") @@ -68,7 +68,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max value must be greater than min value.", "MinValue", "MaxValue") @@ -82,7 +82,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Editor is not a valid value.", "Editor") @@ -96,7 +96,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Calculated default value is not valid.", "CalculatedDefaultValue") @@ -110,7 +110,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Calculated default value and default value cannot be used together.", "CalculatedDefaultValue", "DefaultValue") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/GeolocationFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/GeolocationFieldPropertiesTests.cs index 78a0d96ba..83320fdcc 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/GeolocationFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/GeolocationFieldPropertiesTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Editor is not a valid value.", "Editor") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/NumberFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/NumberFieldPropertiesTests.cs index 21ce07544..f9d1c303c 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/NumberFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/NumberFieldPropertiesTests.cs @@ -39,7 +39,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Default value must be greater than min value.", "DefaultValue") @@ -53,7 +53,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Default value must be less than max value.", "DefaultValue") @@ -67,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max value must be greater than min value.", "MinValue", "MaxValue") @@ -81,7 +81,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Either allowed values or min and max value can be defined.", "AllowedValues", "MinValue", "MaxValue") @@ -95,7 +95,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Either allowed values or min and max value can be defined.", "AllowedValues", "MinValue", "MaxValue") @@ -109,7 +109,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Radio buttons or dropdown list need allowed values.", "AllowedValues") @@ -123,7 +123,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Editor is not a valid value.", "Editor") @@ -139,7 +139,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Inline editing is only allowed for dropdowns and input fields.", "InlineEditable", "Editor") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ReferencesFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ReferencesFieldPropertiesTests.cs index fb65e9af6..cd0a0fed9 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ReferencesFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ReferencesFieldPropertiesTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max items must be greater than min items.", "MinItems", "MaxItems") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/StringFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/StringFieldPropertiesTests.cs index 62f7ac2e1..ed5382b4e 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/StringFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/StringFieldPropertiesTests.cs @@ -24,7 +24,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max length must be greater than min length.", "MinLength", "MaxLength") @@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Either allowed values or min and max length can be defined.", "AllowedValues", "MinLength", "MaxLength") @@ -52,7 +52,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Either allowed values or min and max length can be defined.", "AllowedValues", "MinLength", "MaxLength") @@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Radio buttons or dropdown list need allowed values.", "AllowedValues") @@ -80,7 +80,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Editor is not a valid value.", "Editor") @@ -94,7 +94,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Pattern is not a valid expression.", "Pattern") @@ -112,7 +112,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Inline editing is only allowed for dropdowns, slugs and input fields.", "InlineEditable", "Editor") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/TagsFieldPropertiesTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/TagsFieldPropertiesTests.cs index e8294b846..73719d63b 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/TagsFieldPropertiesTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/TagsFieldPropertiesTests.cs @@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties var errors = FieldPropertiesValidator.Validate(sut).ToList(); - errors.ShouldBeEquivalentTo( + errors.Should().BeEquivalentTo( new List { new ValidationError("Max items must be greater than min items.", "MinItems", "MaxItems") diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj b/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj index 6325ad89d..4d53d6b79 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp2.0 + netcoreapp2.1 Squidex.Domain.Apps.Entities @@ -19,20 +19,17 @@ - - + + - - + + - + - - - ..\..\Squidex.ruleset diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs b/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs index b89bc6962..66f07000d 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/TestHelpers/AssertHelper.cs @@ -33,7 +33,7 @@ namespace Squidex.Domain.Apps.Entities.TestHelpers { lhs.Should().BeOfType(rhs.GetType()); - ((object)lhs).ShouldBeEquivalentTo(rhs, o => o.IncludingAllDeclaredProperties()); + ((object)lhs).Should().BeEquivalentTo(rhs, o => o.IncludingAllDeclaredProperties()); } public static void ShouldBeSameEventType(this IEvent lhs, IEvent rhs) @@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Entities.TestHelpers public static void ShouldBeEquivalent(this T result, T value) { - result.ShouldBeEquivalentTo(value, o => o.IncludingAllDeclaredProperties()); + result.Should().BeEquivalentTo(value, o => o.IncludingAllDeclaredProperties()); } } } diff --git a/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj b/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj index 69ca7228c..24a59e7e0 100644 --- a/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj +++ b/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp2.0 + netcoreapp2.1 Squidex.Domain.Users @@ -11,18 +11,15 @@ - - - + + + - + - - - ..\..\Squidex.ruleset diff --git a/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs b/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs index 5339d54dd..d6556c694 100644 --- a/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs +++ b/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs @@ -97,7 +97,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.OnActivateAsync(consumerName); await sut.ActivateAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = null }); A.CallTo(() => eventStore.CreateSubscription(A.Ignored, A.Ignored, A.Ignored)) .MustNotHaveHappened(); @@ -109,7 +109,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.OnActivateAsync(consumerName); await sut.ActivateAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); A.CallTo(() => eventStore.CreateSubscription(A.Ignored, A.Ignored, A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -121,7 +121,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.OnActivateAsync(consumerName); await sut.ActivateAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); A.CallTo(() => eventStore.CreateSubscription(A.Ignored, A.Ignored, A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -135,7 +135,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.StopAsync(); await sut.StopAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = null }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -152,7 +152,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.StopAsync(); await sut.ResetAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = null, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = null, Error = null }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustHaveHappened(Repeated.Exactly.Twice); @@ -180,7 +180,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnEventAsync(eventSubscription, @event); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = @event.EventPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = @event.EventPosition, Error = null }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -202,7 +202,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnEventAsync(eventSubscription, @event); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = @event.EventPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = @event.EventPosition, Error = null }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -221,7 +221,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnEventAsync(A.Fake(), @event); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); A.CallTo(() => eventConsumer.On(envelope)) .MustNotHaveHappened(); @@ -237,7 +237,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnErrorAsync(eventSubscription, ex); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -256,7 +256,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnErrorAsync(A.Fake(), ex); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustNotHaveHappened(); @@ -285,7 +285,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.ActivateAsync(); await sut.ResetAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); A.CallTo(() => persistence.WriteSnapshotAsync(A.Ignored)) .MustHaveHappened(Repeated.Exactly.Once); @@ -309,7 +309,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnEventAsync(eventSubscription, @event); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); A.CallTo(() => eventConsumer.On(envelope)) .MustHaveHappened(); @@ -336,7 +336,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await OnEventAsync(eventSubscription, @event); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = ex.ToString() }); A.CallTo(() => eventConsumer.On(envelope)) .MustNotHaveHappened(); @@ -367,7 +367,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains await sut.StartAsync(); await sut.StartAsync(); - state.ShouldBeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); + state.Should().BeEquivalentTo(new EventConsumerState { IsStopped = false, Position = initialPosition, Error = null }); A.CallTo(() => eventConsumer.On(envelope)) .MustHaveHappened(); diff --git a/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerManagerGrainTests.cs b/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerManagerGrainTests.cs index c04256296..f0ca2052d 100644 --- a/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerManagerGrainTests.cs +++ b/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerManagerGrainTests.cs @@ -175,7 +175,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains var infos = await sut.GetConsumersAsync(); - infos.Value.ShouldBeEquivalentTo( + infos.Value.Should().BeEquivalentTo( new List { new EventConsumerInfo { Name = "A", Error = "A-Error", IsStopped = false, Position = "123" }, diff --git a/tests/Squidex.Infrastructure.Tests/MongoDb/BsonConverterTests.cs b/tests/Squidex.Infrastructure.Tests/MongoDb/BsonConverterTests.cs index 4bd070235..543d74468 100644 --- a/tests/Squidex.Infrastructure.Tests/MongoDb/BsonConverterTests.cs +++ b/tests/Squidex.Infrastructure.Tests/MongoDb/BsonConverterTests.cs @@ -122,7 +122,7 @@ namespace Squidex.Infrastructure.MongoDb { var target = JObject.FromObject(source).ToBson().ToJson().ToObject(); - target.ShouldBeEquivalentTo(source); + target.Should().BeEquivalentTo(source); } [Fact] @@ -189,7 +189,7 @@ namespace Squidex.Infrastructure.MongoDb { var target = serializer.Deserialize(reader, buggy.GetType()); - target.ShouldBeEquivalentTo(buggy); + target.Should().BeEquivalentTo(buggy); } } @@ -211,7 +211,7 @@ namespace Squidex.Infrastructure.MongoDb { var target = serializer.Deserialize(reader); - target.ShouldBeEquivalentTo(source); + target.Should().BeEquivalentTo(source); } } } diff --git a/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj b/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj index 0e366e697..cf6ddfe01 100644 --- a/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj +++ b/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp2.0 + netcoreapp2.1 Squidex.Infrastructure @@ -11,21 +11,18 @@ - - + + - - - + + + - + - - - ..\..\Squidex.ruleset diff --git a/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs b/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs index ecaafea85..1e8bba315 100644 --- a/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs +++ b/tests/Squidex.Infrastructure.Tests/UsageTracking/BackgroundUsageTrackerTests.cs @@ -91,7 +91,7 @@ namespace Squidex.Infrastructure.UsageTracking var result = await sut.QueryAsync("key", dateFrom, dateTo); - result.ShouldBeEquivalentTo(new List + result.Should().BeEquivalentTo(new List { new StoredUsage(dateFrom.AddDays(0), 00, 00), new StoredUsage(dateFrom.AddDays(1), 10, 15), diff --git a/tests/Squidex.Tests/Squidex.Tests.csproj b/tests/Squidex.Tests/Squidex.Tests.csproj index 2c6b14f49..03d94abeb 100644 --- a/tests/Squidex.Tests/Squidex.Tests.csproj +++ b/tests/Squidex.Tests/Squidex.Tests.csproj @@ -1,7 +1,7 @@  Exe - netcoreapp2.0 + netcoreapp2.1 Squidex $(NoWarn);NU1605 @@ -10,19 +10,16 @@ - + - - + + - - - ..\..\Squidex.ruleset diff --git a/tools/GenerateLanguages/GenerateLanguages.csproj b/tools/GenerateLanguages/GenerateLanguages.csproj index 7021a1d02..c205ac353 100644 --- a/tools/GenerateLanguages/GenerateLanguages.csproj +++ b/tools/GenerateLanguages/GenerateLanguages.csproj @@ -1,6 +1,6 @@  - netcoreapp2.0 + netcoreapp2.1 Exe diff --git a/tools/Migrate_00/Migrate_00.csproj b/tools/Migrate_00/Migrate_00.csproj index 15541c199..ca0d26aae 100644 --- a/tools/Migrate_00/Migrate_00.csproj +++ b/tools/Migrate_00/Migrate_00.csproj @@ -1,10 +1,10 @@  Exe - netcoreapp2.0 + netcoreapp2.1 - +