Browse Source

Build fixes.

pull/141/head
Sebastian Stehle 8 years ago
parent
commit
cf798ebc89
  1. 1
      src/Squidex.Domain.Apps.Core/Schemas/Schema.cs
  2. 1
      src/Squidex.Domain.Apps.Read.MongoDb/Contents/Visitors/PropertyVisitor.cs
  3. 1
      src/Squidex.Domain.Apps.Read/Contents/Edm/EdmModelBuilder.cs
  4. 2
      src/Squidex.Domain.Apps.Read/Contents/GraphQL/GraphQLModel.cs
  5. 6
      src/Squidex.Domain.Apps.Write/Schemas/Guards/SchemaFieldGuard.cs
  6. 1
      src/Squidex/Controllers/ContentApi/Generator/SchemaSwaggerGenerator.cs
  7. 79
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/BooleanFieldPropertiesTests.cs
  8. 46
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/DateTimePropertiesTests.cs
  9. 50
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/FieldPropertiesTests.cs
  10. 5
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/FieldRegistryTests.cs
  11. 79
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/GeolocationFieldPropertiesTests.cs
  12. 79
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/ReferencesFieldPropertiesTests.cs
  13. 1
      tests/Squidex.Domain.Apps.Core.Tests/Schemas/SchemaTests.cs
  14. 34
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/AssetsFieldPropertiesTests.cs
  15. 34
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/BooleanFieldPropertiesTests.cs
  16. 86
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/DateTimeFieldPropertiesTests.cs
  17. 34
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/GeolocationFieldPropertiesTests.cs
  18. 65
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/NumberFieldPropertiesTests.cs
  19. 34
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/ReferencesFieldPropertiesTests.cs
  20. 61
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/StringFieldPropertiesTests.cs

1
src/Squidex.Domain.Apps.Core/Schemas/Schema.cs

@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using NJsonSchema;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Core.Schemas

1
src/Squidex.Domain.Apps.Read.MongoDb/Contents/Visitors/PropertyVisitor.cs

@ -12,6 +12,7 @@ using System.Linq;
using Microsoft.OData.UriParser;
using MongoDB.Driver;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Core.Schemas.Edm;
namespace Squidex.Domain.Apps.Read.MongoDb.Contents.Visitors
{

1
src/Squidex.Domain.Apps.Read/Contents/Edm/EdmModelBuilder.cs

@ -11,6 +11,7 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.OData.Edm;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Core.Schemas.Edm;
using Squidex.Domain.Apps.Read.Apps;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Utils;

2
src/Squidex.Domain.Apps.Read/Contents/GraphQL/GraphQLModel.cs

@ -219,7 +219,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL
{
var schema = schemas.GetOrDefault(schemaId);
return schema != null ? schemaTypes.Add(schemaId, k => new ContentGraphType(schema, this)) : null;
return schema != null ? schemaTypes.GetOrAdd(schemaId, k => new ContentGraphType(schema, this)) : null;
}
}
}

6
src/Squidex.Domain.Apps.Write/Schemas/Guards/SchemaFieldGuard.cs

@ -94,7 +94,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
return field;
}
private static IEnumerable<ValidationError> ValidateProperties(FieldProperties properties)
public static IEnumerable<ValidationError> ValidateProperties(FieldProperties properties)
{
switch (properties)
{
@ -148,7 +148,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
{
if (!d.Editor.IsEnumValue())
{
yield return new ValidationError("Editor is not a valid value",
yield return new ValidationError("Editor is not a valid value",
nameof(d.Editor));
}
@ -194,7 +194,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
{
if (!n.Editor.IsEnumValue())
{
yield return new ValidationError("Editor is not a valid value",
yield return new ValidationError("Editor is not a valid value",
nameof(n.Editor));
}

1
src/Squidex/Controllers/ContentApi/Generator/SchemaSwaggerGenerator.cs

@ -14,6 +14,7 @@ using NSwag;
using Squidex.Config;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Core.Schemas.JsonSchema;
using Squidex.Domain.Apps.Read.Contents.JsonSchema;
using Squidex.Infrastructure;
using Squidex.Pipeline.Swagger;

79
tests/Squidex.Domain.Apps.Core.Tests/Schemas/BooleanFieldPropertiesTests.cs

@ -1,79 +0,0 @@
// ==========================================================================
// BooleanFieldPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
{
public class BooleanFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_add_error_if_editor_is_not_valid()
{
var sut = new BooleanFieldProperties { Editor = (BooleanFieldEditor)123 };
sut.Validate(errors);
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Editor is not a valid value", "Editor")
});
}
[Fact]
public void Should_set_or_freeze_sut()
{
var sut = new BooleanFieldProperties();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
var result = property.GetValue(sut);
Assert.Equal(value, result);
}
sut.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
Assert.Throws<InvalidOperationException>(() =>
{
try
{
property.SetValue(sut, value);
}
catch (Exception ex)
{
throw ex.InnerException;
}
});
}
}
}
}

46
tests/Squidex.Domain.Apps.Core.Tests/Schemas/DateTimePropertiesTests.cs

@ -0,0 +1,46 @@
// ==========================================================================
// DateTimePropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using NodaTime;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
{
public class DateTimePropertiesTests
{
[Fact]
public void Should_provide_today_default_value()
{
var sut = new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Today };
Assert.Equal(DateTime.UtcNow.Date.ToString("o"), sut.GetDefaultValue().ToString());
}
[Fact]
public void Should_provide_now_default_value()
{
var sut = new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Now };
Assert.Equal(DateTime.UtcNow.ToString("o").Substring(0, 16), sut.GetDefaultValue().ToString().Substring(0, 16));
}
[Fact]
public void Should_provide_specific_default_value()
{
var sut = new DateTimeFieldProperties { DefaultValue = FutureDays(15) };
Assert.Equal(FutureDays(15).ToString(), sut.GetDefaultValue());
}
private static Instant FutureDays(int days)
{
return Instant.FromDateTimeUtc(DateTime.UtcNow.Date.AddDays(days));
}
}
}

50
tests/Squidex.Domain.Apps.Core.Tests/Schemas/AssetsFieldPropertiesTests.cs → tests/Squidex.Domain.Apps.Core.Tests/Schemas/FieldPropertiesTests.cs

@ -1,5 +1,5 @@
// ==========================================================================
// AssetsFieldPropertiesTests.cs
// FieldPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
@ -10,52 +10,56 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
{
public class AssetsFieldPropertiesTests
public class FieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_add_error_if_min_greater_than_max()
public static IEnumerable<FieldProperties> Properties
{
var sut = new AssetsFieldProperties { MinItems = 10, MaxItems = 5 };
sut.Validate(errors);
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Max items must be greater than min items", "MinItems", "MaxItems")
});
get
{
yield return new AssetsFieldProperties();
yield return new BooleanFieldProperties();
yield return new DateTimeFieldProperties();
yield return new GeolocationFieldProperties();
yield return new JsonFieldProperties();
yield return new NumberFieldProperties();
yield return new ReferencesFieldProperties();
yield return new StringFieldProperties();
}
}
[Fact]
public void Should_set_or_freeze_sut()
public static IEnumerable<object[]> PropertiesData
{
var sut = new AssetsFieldProperties();
get { return Properties.Select(x => new object[] { x }); }
}
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
[Theory]
[MemberData(nameof(PropertiesData))]
public void Should_set_or_freeze_sut(FieldProperties properties)
{
foreach (var property in properties.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
property.SetValue(properties, value);
var result = property.GetValue(sut);
var result = property.GetValue(properties);
Assert.Equal(value, result);
}
sut.Freeze();
properties.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
foreach (var property in properties.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
@ -66,7 +70,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
try
{
property.SetValue(sut, value);
property.SetValue(properties, value);
}
catch (Exception ex)
{

5
tests/Squidex.Domain.Apps.Core.Tests/Schemas/FieldRegistryTests.cs

@ -24,11 +24,6 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
return null;
}
protected override IEnumerable<ValidationError> ValidateCore()
{
yield break;
}
}
[Fact]

79
tests/Squidex.Domain.Apps.Core.Tests/Schemas/GeolocationFieldPropertiesTests.cs

@ -1,79 +0,0 @@
// ==========================================================================
// GeolocationPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
{
public class GeolocationFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_add_error_if_editor_is_not_valid()
{
var sut = new GeolocationFieldProperties { Editor = (GeolocationFieldEditor)123 };
sut.Validate(errors);
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Editor is not a valid value", "Editor")
});
}
[Fact]
public void Should_set_or_freeze_sut()
{
var sut = new GeolocationFieldProperties();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
var result = property.GetValue(sut);
Assert.Equal(value, result);
}
sut.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
Assert.Throws<InvalidOperationException>(() =>
{
try
{
property.SetValue(sut, value);
}
catch (Exception ex)
{
throw ex.InnerException;
}
});
}
}
}
}

79
tests/Squidex.Domain.Apps.Core.Tests/Schemas/ReferencesFieldPropertiesTests.cs

@ -1,79 +0,0 @@
// ==========================================================================
// ReferencesFieldPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
{
public class ReferencesFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_add_error_if_min_greater_than_max()
{
var sut = new ReferencesFieldProperties { MinItems = 10, MaxItems = 5 };
sut.Validate(errors);
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Max items must be greater than min items", "MinItems", "MaxItems")
});
}
[Fact]
public void Should_set_or_freeze_sut()
{
var sut = new ReferencesFieldProperties();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
var result = property.GetValue(sut);
Assert.Equal(value, result);
}
sut.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
Assert.Throws<InvalidOperationException>(() =>
{
try
{
property.SetValue(sut, value);
}
catch (Exception ex)
{
throw ex.InnerException;
}
});
}
}
}
}

1
tests/Squidex.Domain.Apps.Core.Tests/Schemas/SchemaTests.cs

@ -13,6 +13,7 @@ using System.Linq;
using Newtonsoft.Json.Linq;
using NJsonSchema;
using Squidex.Domain.Apps.Core.Schemas.Edm;
using Squidex.Domain.Apps.Core.Schemas.JsonSchema;
using Squidex.Infrastructure;
using Xunit;

34
tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/AssetsFieldPropertiesTests.cs

@ -0,0 +1,34 @@
// ==========================================================================
// AssetsFieldPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Write.Schemas.Guards.FieldPro
{
public class AssetsFieldPropertiesTests
{
[Fact]
public void Should_add_error_if_min_greater_than_max()
{
var sut = new AssetsFieldProperties { MinItems = 10, MaxItems = 5 };
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Max items must be greater than min items", "MinItems", "MaxItems")
});
}
}
}

34
tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/BooleanFieldPropertiesTests.cs

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

86
tests/Squidex.Domain.Apps.Core.Tests/Schemas/DateTimeFieldPropertiesTests.cs → tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/DateTimeFieldPropertiesTests.cs

@ -9,18 +9,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using NodaTime;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
namespace Squidex.Domain.Apps.Write.Schemas.Guards.FieldProperties
{
public class DateTimeFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_not_add_error_if_sut_is_valid()
{
@ -31,7 +29,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
DefaultValue = FutureDays(15)
};
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
Assert.Empty(errors);
}
@ -41,7 +39,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new DateTimeFieldProperties { MinValue = FutureDays(10), DefaultValue = FutureDays(5) };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -55,7 +53,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new DateTimeFieldProperties { MaxValue = FutureDays(10), DefaultValue = FutureDays(15) };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -69,7 +67,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new DateTimeFieldProperties { MinValue = FutureDays(10), MaxValue = FutureDays(5) };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -83,7 +81,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new DateTimeFieldProperties { Editor = (DateTimeFieldEditor)123 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -97,7 +95,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new DateTimeFieldProperties { CalculatedDefaultValue = (DateTimeCalculatedDefaultValue)123 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -111,7 +109,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Now, DefaultValue = FutureDays(10) };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -120,72 +118,6 @@ namespace Squidex.Domain.Apps.Core.Schemas
});
}
[Fact]
public void Should_provide_today_default_value()
{
var sut = new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Today };
Assert.Equal(DateTime.UtcNow.Date.ToString("o"), sut.GetDefaultValue().ToString());
}
[Fact]
public void Should_provide_now_default_value()
{
var sut = new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Now };
Assert.Equal(DateTime.UtcNow.ToString("o").Substring(0, 16), sut.GetDefaultValue().ToString().Substring(0, 16));
}
[Fact]
public void Should_provide_specific_default_value()
{
var sut = new DateTimeFieldProperties { DefaultValue = FutureDays(15) };
Assert.Equal(FutureDays(15).ToString(), sut.GetDefaultValue());
}
[Fact]
public void Should_set_or_freeze_sut()
{
var sut = new DateTimeFieldProperties();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
var result = property.GetValue(sut);
Assert.Equal(value, result);
}
sut.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
Assert.Throws<InvalidOperationException>(() =>
{
try
{
property.SetValue(sut, value);
}
catch (Exception ex)
{
throw ex.InnerException;
}
});
}
}
private static Instant FutureDays(int days)
{
return Instant.FromDateTimeUtc(DateTime.UtcNow.Date.AddDays(days));

34
tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/GeolocationFieldPropertiesTests.cs

@ -0,0 +1,34 @@
// ==========================================================================
// GeolocationPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Write.Schemas.Guards.FieldProperties
{
public class GeolocationFieldPropertiesTests
{
[Fact]
public void Should_add_error_if_editor_is_not_valid()
{
var sut = new GeolocationFieldProperties { Editor = (GeolocationFieldEditor)123 };
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Editor is not a valid value", "Editor")
});
}
}
}

65
tests/Squidex.Domain.Apps.Core.Tests/Schemas/NumberFieldPropertiesTests.cs → tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/NumberFieldPropertiesTests.cs

@ -6,21 +6,18 @@
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
namespace Squidex.Domain.Apps.Write.Schemas.Guards.FieldProperties
{
public class NumberFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_not_add_error_if_sut_is_valid()
{
@ -31,7 +28,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
DefaultValue = 5
};
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
Assert.Empty(errors);
}
@ -41,7 +38,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { MinValue = 10, DefaultValue = 5 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -55,7 +52,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { MaxValue = 0, DefaultValue = 5 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -69,7 +66,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { MinValue = 10, MaxValue = 5 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -83,7 +80,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { MaxValue = 10, AllowedValues = ImmutableList.Create<double>(4) };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -97,7 +94,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { MinValue = 10, AllowedValues = ImmutableList.Create<double>(4) };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -111,7 +108,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { Editor = NumberFieldEditor.Radio };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -125,7 +122,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new NumberFieldProperties { Editor = (NumberFieldEditor)123 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -133,47 +130,5 @@ namespace Squidex.Domain.Apps.Core.Schemas
new ValidationError("Editor is not a valid value", "Editor")
});
}
[Fact]
public void Should_set_or_freeze_sut()
{
var sut = new NumberFieldProperties();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
var result = property.GetValue(sut);
Assert.Equal(value, result);
}
sut.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
Assert.Throws<InvalidOperationException>(() =>
{
try
{
property.SetValue(sut, value);
}
catch (Exception ex)
{
throw ex.InnerException;
}
});
}
}
}
}

34
tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/ReferencesFieldPropertiesTests.cs

@ -0,0 +1,34 @@
// ==========================================================================
// ReferencesFieldPropertiesTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Write.Schemas.Guards.FieldProperties
{
public class ReferencesFieldPropertiesTests
{
[Fact]
public void Should_add_error_if_min_greater_than_max()
{
var sut = new ReferencesFieldProperties { MinItems = 10, MaxItems = 5 };
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Max items must be greater than min items", "MinItems", "MaxItems")
});
}
}
}

61
tests/Squidex.Domain.Apps.Core.Tests/Schemas/StringFieldPropertiesTests.cs → tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/FieldProperties/StringFieldPropertiesTests.cs

@ -6,27 +6,24 @@
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Core.Schemas
namespace Squidex.Domain.Apps.Write.Schemas.Guards.FieldProperties
{
public class StringFieldPropertiesTests
{
private readonly List<ValidationError> errors = new List<ValidationError>();
[Fact]
public void Should_add_error_if_min_greater_than_max()
{
var sut = new StringFieldProperties { MinLength = 10, MaxLength = 5 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -40,7 +37,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new StringFieldProperties { MinLength = 10, AllowedValues = ImmutableList.Create("4") };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -54,7 +51,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new StringFieldProperties { MaxLength = 10, AllowedValues = ImmutableList.Create("4") };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -68,7 +65,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new StringFieldProperties { Editor = StringFieldEditor.Radio };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -82,7 +79,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new StringFieldProperties { Editor = (StringFieldEditor)123 };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -96,7 +93,7 @@ namespace Squidex.Domain.Apps.Core.Schemas
{
var sut = new StringFieldProperties { Pattern = "[0-9{1}" };
sut.Validate(errors);
var errors = SchemaFieldGuard.ValidateProperties(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
@ -104,47 +101,5 @@ namespace Squidex.Domain.Apps.Core.Schemas
new ValidationError("Pattern is not a valid expression", "Pattern")
});
}
[Fact]
public void Should_set_or_freeze_sut()
{
var sut = new StringFieldProperties();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
property.SetValue(sut, value);
var result = property.GetValue(sut);
Assert.Equal(value, result);
}
sut.Freeze();
foreach (var property in sut.GetType().GetRuntimeProperties().Where(x => x.Name != "IsFrozen"))
{
var value =
property.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(property.PropertyType) :
null;
Assert.Throws<InvalidOperationException>(() =>
{
try
{
property.SetValue(sut, value);
}
catch (Exception ex)
{
throw ex.InnerException;
}
});
}
}
}
}
Loading…
Cancel
Save