Browse Source

Tests improved.

pull/240/head
Sebastian Stehle 8 years ago
parent
commit
c3a6233aae
  1. 31
      tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs
  2. 64
      tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaFieldTests.cs
  3. 56
      tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs

31
tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs

@ -6,6 +6,8 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions; using FluentAssertions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@ -21,6 +23,21 @@ namespace Squidex.Domain.Apps.Core.Model.Rules
public class RuleTests public class RuleTests
{ {
private readonly JsonSerializer serializer = TestData.DefaultSerializer(); private readonly JsonSerializer serializer = TestData.DefaultSerializer();
public static readonly List<object[]> Actions =
typeof(Rule).Assembly.GetTypes()
.Where(x => x.BaseType == typeof(RuleAction))
.Select(Activator.CreateInstance)
.Select(x => new object[] { x })
.ToList();
public static readonly List<object[]> Triggers =
typeof(Rule).Assembly.GetTypes()
.Where(x => x.BaseType == typeof(RuleTrigger))
.Select(Activator.CreateInstance)
.Select(x => new object[] { x })
.ToList();
private readonly Rule rule_0 = new Rule(new ContentChangedTrigger(), new WebhookAction()); private readonly Rule rule_0 = new Rule(new ContentChangedTrigger(), new WebhookAction());
public sealed class OtherTrigger : RuleTrigger public sealed class OtherTrigger : RuleTrigger
@ -117,16 +134,18 @@ namespace Squidex.Domain.Apps.Core.Model.Rules
appClients.ShouldBeEquivalentTo(rule_0); appClients.ShouldBeEquivalentTo(rule_0);
} }
[Fact] [Theory]
public void Should_freeze_webhook_action() [MemberData(nameof(Actions))]
public void Should_freeze_actions(RuleAction action)
{ {
TestData.TestFreeze(new WebhookAction()); TestData.TestFreeze(action);
} }
[Fact] [Theory]
public void Should_freeze_contentchanged_trigger() [MemberData(nameof(Triggers))]
public void Should_freeze_triggers(RuleTrigger trigger)
{ {
TestData.TestFreeze(new ContentChangedTrigger()); TestData.TestFreeze(trigger);
} }
} }
} }

64
tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaFieldTests.cs

@ -6,6 +6,8 @@
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Core.Schemas;
using Xunit; using Xunit;
@ -15,6 +17,13 @@ namespace Squidex.Domain.Apps.Core.Model.Schemas
{ {
public class SchemaFieldTests public class SchemaFieldTests
{ {
public static readonly List<object[]> FieldProperties =
typeof(Schema).Assembly.GetTypes()
.Where(x => x.BaseType == typeof(FieldProperties))
.Select(Activator.CreateInstance)
.Select(x => new object[] { x })
.ToList();
private readonly NumberField field_0 = new NumberField(1, "my-field", Partitioning.Invariant); private readonly NumberField field_0 = new NumberField(1, "my-field", Partitioning.Invariant);
[Fact] [Fact]
@ -97,58 +106,11 @@ namespace Squidex.Domain.Apps.Core.Model.Schemas
Assert.Throws<ArgumentException>(() => field_0.Update(new StringFieldProperties())); Assert.Throws<ArgumentException>(() => field_0.Update(new StringFieldProperties()));
} }
[Fact] [Theory]
public void Should_freeze_asset_field_properties() [MemberData(nameof(FieldProperties))]
{ public void Should_freeze_field_properties(FieldProperties action)
TestData.TestFreeze(new AssetsFieldProperties());
}
[Fact]
public void Should_freeze_boolean_field_properties()
{
TestData.TestFreeze(new BooleanFieldProperties());
}
[Fact]
public void Should_freeze_datetime_field_properties()
{
TestData.TestFreeze(new DateTimeFieldProperties());
}
[Fact]
public void Should_freeze_geolocation_field_properties()
{
TestData.TestFreeze(new GeolocationFieldProperties());
}
[Fact]
public void Should_freeze_json_field_properties()
{
TestData.TestFreeze(new JsonFieldProperties());
}
[Fact]
public void Should_freeze_number_field_properties()
{
TestData.TestFreeze(new NumberFieldProperties());
}
[Fact]
public void Should_freeze_references_field_properties()
{
TestData.TestFreeze(new ReferencesFieldProperties());
}
[Fact]
public void Should_freeze_string_field_properties()
{
TestData.TestFreeze(new StringFieldProperties());
}
[Fact]
public void Should_freeze_tags_field_properties()
{ {
TestData.TestFreeze(new TagsFieldProperties()); TestData.TestFreeze(action);
} }
} }
} }

56
tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs

@ -0,0 +1,56 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Threading.Tasks;
using Squidex.Domain.Apps.Core.Rules.Actions;
using Xunit;
namespace Squidex.Domain.Apps.Entities.Rules.Guards.Actions
{
public sealed class AzureQueueActionTests
{
[Fact]
public async Task Should_add_error_if_connection_string_is_null()
{
var action = new AzureQueueAction { ConnectionString = null, Queue = "squidex" };
var errors = await RuleActionValidator.ValidateAsync(action);
Assert.NotEmpty(errors);
}
[Fact]
public async Task Should_add_error_if_queue_is_null()
{
var action = new AzureQueueAction { ConnectionString = "connection", Queue = null };
var errors = await RuleActionValidator.ValidateAsync(action);
Assert.NotEmpty(errors);
}
[Fact]
public async Task Should_add_error_if_queue_is_invalid()
{
var action = new AzureQueueAction { ConnectionString = "connection", Queue = "Squidex" };
var errors = await RuleActionValidator.ValidateAsync(action);
Assert.NotEmpty(errors);
}
[Fact]
public async Task Should_not_add_error_if_values_are_valid()
{
var action = new AzureQueueAction { ConnectionString = "connection", Queue = "squidex" };
var errors = await RuleActionValidator.ValidateAsync(action);
Assert.Empty(errors);
}
}
}
Loading…
Cancel
Save