From c3a6233aaeb0dd842398bcd31f4548919a31e4af Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Thu, 1 Feb 2018 16:10:18 +0100 Subject: [PATCH] Tests improved. --- .../Model/Rules/RuleTests.cs | 31 +++++++-- .../Model/Schemas/SchemaFieldTests.cs | 64 ++++--------------- .../Guards/Actions/AzureQueueActionTests.cs | 56 ++++++++++++++++ 3 files changed, 94 insertions(+), 57 deletions(-) create mode 100644 tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Actions/AzureQueueActionTests.cs 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 1eee35983..fe0dfac5a 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Rules/RuleTests.cs @@ -6,6 +6,8 @@ // ========================================================================== using System; +using System.Collections.Generic; +using System.Linq; using FluentAssertions; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -21,6 +23,21 @@ namespace Squidex.Domain.Apps.Core.Model.Rules public class RuleTests { private readonly JsonSerializer serializer = TestData.DefaultSerializer(); + + public static readonly List Actions = + typeof(Rule).Assembly.GetTypes() + .Where(x => x.BaseType == typeof(RuleAction)) + .Select(Activator.CreateInstance) + .Select(x => new object[] { x }) + .ToList(); + + public static readonly List 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()); public sealed class OtherTrigger : RuleTrigger @@ -117,16 +134,18 @@ namespace Squidex.Domain.Apps.Core.Model.Rules appClients.ShouldBeEquivalentTo(rule_0); } - [Fact] - public void Should_freeze_webhook_action() + [Theory] + [MemberData(nameof(Actions))] + public void Should_freeze_actions(RuleAction action) { - TestData.TestFreeze(new WebhookAction()); + TestData.TestFreeze(action); } - [Fact] - public void Should_freeze_contentchanged_trigger() + [Theory] + [MemberData(nameof(Triggers))] + public void Should_freeze_triggers(RuleTrigger trigger) { - TestData.TestFreeze(new ContentChangedTrigger()); + TestData.TestFreeze(trigger); } } } diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaFieldTests.cs b/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaFieldTests.cs index 4f267a407..4360b5673 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Core.Tests/Model/Schemas/SchemaFieldTests.cs @@ -6,6 +6,8 @@ // ========================================================================== using System; +using System.Collections.Generic; +using System.Linq; using Squidex.Domain.Apps.Core.Schemas; using Xunit; @@ -15,6 +17,13 @@ namespace Squidex.Domain.Apps.Core.Model.Schemas { public class SchemaFieldTests { + public static readonly List 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); [Fact] @@ -97,58 +106,11 @@ namespace Squidex.Domain.Apps.Core.Model.Schemas Assert.Throws(() => field_0.Update(new StringFieldProperties())); } - [Fact] - public void Should_freeze_asset_field_properties() - { - 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() + [Theory] + [MemberData(nameof(FieldProperties))] + public void Should_freeze_field_properties(FieldProperties action) { - TestData.TestFreeze(new TagsFieldProperties()); + TestData.TestFreeze(action); } } } 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 new file mode 100644 index 000000000..1569a7ada --- /dev/null +++ b/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); + } + } +}