Browse Source

Tests fixed.

pull/169/head
Sebastian Stehle 9 years ago
parent
commit
cfab66c074
  1. 4
      src/Squidex.Domain.Apps.Read/State/Orleans/Grains/Implementations/JsonAppEntity.cs
  2. 2
      src/Squidex.Domain.Apps.Write/Contents/ContentCommandMiddleware.cs
  3. 2
      src/Squidex.Domain.Apps.Write/Contents/ContentOperationContext.cs
  4. 21
      tests/Squidex.Domain.Apps.Read.Tests/Contents/ContentQueryServiceTests.cs
  5. 43
      tests/Squidex.Domain.Apps.Read.Tests/Contents/GraphQLTests.cs
  6. 2
      tests/Squidex.Domain.Apps.Read.Tests/Rules/RuleDequeuerTests.cs
  7. 6
      tests/Squidex.Domain.Apps.Read.Tests/Rules/RuleEnqueuerTests.cs
  8. 134
      tests/Squidex.Domain.Apps.Read.Tests/Schemas/CachingSchemaProviderTests.cs
  9. 6
      tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentCommandMiddlewareTests.cs
  10. 29
      tests/Squidex.Domain.Apps.Write.Tests/Rules/Guards/GuardRuleTests.cs
  11. 17
      tests/Squidex.Domain.Apps.Write.Tests/Rules/Guards/Triggers/ContentChangedTriggerTests.cs
  12. 8
      tests/Squidex.Domain.Apps.Write.Tests/Rules/RuleCommandMiddlewareTests.cs
  13. 18
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/GuardSchemaTests.cs
  14. 10
      tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaCommandMiddlewareTests.cs
  15. 62
      tests/Squidex.Infrastructure.Tests/Reflection/SimpleCopierTests.cs

4
src/Squidex.Domain.Apps.Read/State/Orleans/Grains/Implementations/JsonAppEntity.cs

@ -6,13 +6,9 @@
// All rights reserved.
// ==========================================================================
using System;
using Newtonsoft.Json;
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Events;
using Squidex.Domain.Apps.Read.Apps;
using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Read.State.Orleans.Grains.Implementations
{

2
src/Squidex.Domain.Apps.Write/Contents/ContentCommandMiddleware.cs

@ -149,8 +149,8 @@ namespace Squidex.Domain.Apps.Write.Contents
content,
command,
appProvider,
scriptEngine,
assetRepository,
scriptEngine,
message);
return operationContext;

2
src/Squidex.Domain.Apps.Write/Contents/ContentOperationContext.cs

@ -42,8 +42,8 @@ namespace Squidex.Domain.Apps.Write.Contents
ContentDomainObject content,
ContentCommand command,
IAppProvider appProvider,
IScriptEngine scriptEngine,
IAssetRepository assetRepository,
IScriptEngine scriptEngine,
Func<string> message)
{
var (appEntity, schemaEntity) = await appProvider.GetAppWithSchemaAsync(command.AppId.Name, command.SchemaId.Id);

21
tests/Squidex.Domain.Apps.Read.Tests/Contents/ContentQueryServiceTests.cs

@ -18,7 +18,6 @@ using Squidex.Domain.Apps.Read.Apps;
using Squidex.Domain.Apps.Read.Contents.Edm;
using Squidex.Domain.Apps.Read.Contents.Repositories;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Security;
using Xunit;
@ -29,13 +28,14 @@ namespace Squidex.Domain.Apps.Read.Contents
{
private readonly IContentRepository contentRepository = A.Fake<IContentRepository>();
private readonly IScriptEngine scriptEngine = A.Fake<IScriptEngine>();
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly ISchemaEntity schema = A.Fake<ISchemaEntity>();
private readonly IContentEntity content = A.Fake<IContentEntity>();
private readonly IAppEntity app = A.Fake<IAppEntity>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly Guid appId = Guid.NewGuid();
private readonly Guid schemaId = Guid.NewGuid();
private readonly Guid contentId = Guid.NewGuid();
private readonly string appName = "my-app";
private readonly NamedContentData data = new NamedContentData();
private readonly NamedContentData transformedData = new NamedContentData();
private readonly ClaimsPrincipal user;
@ -48,18 +48,19 @@ namespace Squidex.Domain.Apps.Read.Contents
user = new ClaimsPrincipal(identity);
A.CallTo(() => app.Id).Returns(appId);
A.CallTo(() => app.Name).Returns(appName);
A.CallTo(() => content.Id).Returns(contentId);
A.CallTo(() => content.Data).Returns(data);
A.CallTo(() => content.Status).Returns(Status.Published);
sut = new ContentQueryService(contentRepository, schemas, scriptEngine, modelBuilder);
sut = new ContentQueryService(contentRepository, appProvider, scriptEngine, modelBuilder);
}
[Fact]
public async Task Should_return_schema_from_id_if_string_is_guid()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(schemaId, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, schemaId, false))
.Returns(schema);
var result = await sut.FindSchemaAsync(app, schemaId.ToString());
@ -70,7 +71,7 @@ namespace Squidex.Domain.Apps.Read.Contents
[Fact]
public async Task Should_return_schema_from_name_if_string_not_guid()
{
A.CallTo(() => schemas.FindSchemaByNameAsync(appId, "my-schema"))
A.CallTo(() => appProvider.GetSchemaAsync(appName, "my-schema", false))
.Returns(schema);
var result = await sut.FindSchemaAsync(app, "my-schema");
@ -81,7 +82,7 @@ namespace Squidex.Domain.Apps.Read.Contents
[Fact]
public async Task Should_throw_if_schema_not_found()
{
A.CallTo(() => schemas.FindSchemaByNameAsync(appId, "my-schema"))
A.CallTo(() => appProvider.GetSchemaAsync(appName, "my-schema", false))
.Returns((ISchemaEntity)null);
await Assert.ThrowsAsync<DomainObjectNotFoundException>(() => sut.FindSchemaAsync(app, "my-schema"));
@ -90,7 +91,7 @@ namespace Squidex.Domain.Apps.Read.Contents
[Fact]
public async Task Should_return_content_from_repository_and_transform()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(schemaId, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.FindContentAsync(app, schema, contentId))
.Returns(content);
@ -111,7 +112,7 @@ namespace Squidex.Domain.Apps.Read.Contents
[Fact]
public async Task Should_throw_if_content_to_find_does_not_exist()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(schemaId, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.FindContentAsync(app, schema, contentId))
.Returns((IContentEntity)null);
@ -189,7 +190,7 @@ namespace Squidex.Domain.Apps.Read.Contents
private void SetupFakeWithIdQuery(Status[] status, HashSet<Guid> ids)
{
A.CallTo(() => schemas.FindSchemaByIdAsync(schemaId, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.QueryAsync(app, schema, A<Status[]>.That.IsSameSequenceAs(status), ids))
.Returns(new List<IContentEntity> { content });
@ -199,7 +200,7 @@ namespace Squidex.Domain.Apps.Read.Contents
private void SetupFakeWithOdataQuery(Status[] status)
{
A.CallTo(() => schemas.FindSchemaByIdAsync(schemaId, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.QueryAsync(app, schema, A<Status[]>.That.IsSameSequenceAs(status), A<ODataUriParser>.Ignored))
.Returns(new List<IContentEntity> { content });

43
tests/Squidex.Domain.Apps.Read.Tests/Contents/GraphQLTests.cs

@ -26,7 +26,6 @@ using Squidex.Domain.Apps.Read.Assets.Repositories;
using Squidex.Domain.Apps.Read.Contents.GraphQL;
using Squidex.Domain.Apps.Read.Contents.TestData;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Repositories;
using Squidex.Infrastructure;
using Xunit;
@ -38,12 +37,13 @@ namespace Squidex.Domain.Apps.Read.Contents
{
private static readonly Guid schemaId = Guid.NewGuid();
private static readonly Guid appId = Guid.NewGuid();
private static readonly string appName = "my-app";
private readonly Schema schemaDef = new Schema("my-schema");
private readonly IContentQueryService contentQuery = A.Fake<IContentQueryService>();
private readonly ISchemaRepository schemaRepository = A.Fake<ISchemaRepository>();
private readonly IAssetRepository assetRepository = A.Fake<IAssetRepository>();
private readonly ISchemaEntity schema = A.Fake<ISchemaEntity>();
private readonly IMemoryCache cache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly IAppEntity app = A.Dummy<IAppEntity>();
private readonly ClaimsPrincipal user = new ClaimsPrincipal();
private readonly IGraphQLService sut;
@ -78,6 +78,7 @@ namespace Squidex.Domain.Apps.Read.Contents
new GeolocationFieldProperties()));
A.CallTo(() => app.Id).Returns(appId);
A.CallTo(() => app.Name).Returns(appName);
A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.DE));
A.CallTo(() => schema.Id).Returns(schemaId);
@ -88,9 +89,9 @@ namespace Squidex.Domain.Apps.Read.Contents
var allSchemas = new List<ISchemaEntity> { schema };
A.CallTo(() => schemaRepository.QueryAllAsync(appId)).Returns(allSchemas);
A.CallTo(() => appProvider.GetSchemasAsync(appName)).Returns(allSchemas);
sut = new CachingGraphQLService(cache, assetRepository, contentQuery, new FakeUrlGenerator(), schemaRepository);
sut = new CachingGraphQLService(cache, appProvider, assetRepository, contentQuery, new FakeUrlGenerator());
}
[Theory]
@ -240,7 +241,7 @@ namespace Squidex.Domain.Apps.Read.Contents
}
[Fact]
public async Task Should_return_multiple_contens_when_querying_contents()
public async Task Should_return_multiple_contents_when_querying_contents()
{
const string query = @"
query {
@ -254,7 +255,7 @@ namespace Squidex.Domain.Apps.Read.Contents
url
data {
myString {
iv
de
}
myNumber {
iv
@ -303,7 +304,7 @@ namespace Squidex.Domain.Apps.Read.Contents
{
myString = new
{
iv = "value"
de = "value"
},
myNumber = new
{
@ -359,7 +360,7 @@ namespace Squidex.Domain.Apps.Read.Contents
url
data {{
myString {{
iv
de
}}
myNumber {{
iv
@ -402,7 +403,7 @@ namespace Squidex.Domain.Apps.Read.Contents
{
myString = new
{
iv = "value"
de = "value"
},
myNumber = new
{
@ -560,7 +561,7 @@ namespace Squidex.Domain.Apps.Read.Contents
}
[Fact]
public async Task Should_not_return_value_when_field_not_part_of_content()
public async Task Should_not_return_data_when_field_not_part_of_content()
{
var contentId = Guid.NewGuid();
var content = CreateContent(contentId, Guid.Empty, Guid.Empty, new NamedContentData());
@ -576,7 +577,7 @@ namespace Squidex.Domain.Apps.Read.Contents
lastModifiedBy
url
data {{
myString {{
myInvalid {{
iv
}}
}}
@ -590,23 +591,7 @@ namespace Squidex.Domain.Apps.Read.Contents
var expected = new
{
data = new
{
findMySchemaContent = new
{
id = content.Id,
version = 1,
created = content.Created.ToDateTimeUtc(),
createdBy = "subject:user1",
lastModified = content.LastModified.ToDateTimeUtc(),
lastModifiedBy = "subject:user2",
url = $"contents/my-schema/{content.Id}",
data = new
{
myString = (object)null
}
}
}
data = (object)null
};
AssertJson(expected, new { data = result.Data });
@ -621,7 +606,7 @@ namespace Squidex.Domain.Apps.Read.Contents
.AddField("my-json",
new ContentFieldData().AddValue("iv", JToken.FromObject(new { value = 1 })))
.AddField("my-string",
new ContentFieldData().AddValue("iv", "value"))
new ContentFieldData().AddValue("de", "value"))
.AddField("my-assets",
new ContentFieldData().AddValue("iv", JToken.FromObject(new[] { assetId })))
.AddField("my-number",

2
tests/Squidex.Domain.Apps.Read.Tests/Rules/RuleDequeuerTests.cs

@ -25,7 +25,7 @@ namespace Squidex.Domain.Apps.Read.Rules
{
private readonly IClock clock = A.Fake<IClock>();
private readonly ISemanticLog log = A.Fake<ISemanticLog>();
private readonly IRuleRepository ruleRepository = A.Fake<IRuleRepository>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly IRuleEventRepository ruleEventRepository = A.Fake<IRuleEventRepository>();
private readonly RuleService ruleService = A.Fake<RuleService>();
private readonly Instant now = SystemClock.Instance.GetCurrentInstant();

6
tests/Squidex.Domain.Apps.Read.Tests/Rules/RuleEnqueuerTests.cs

@ -25,7 +25,7 @@ namespace Squidex.Domain.Apps.Read.Rules
{
public class RuleEnqueuerTests
{
private readonly IRuleRepository ruleRepository = A.Fake<IRuleRepository>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly IRuleEventRepository ruleEventRepository = A.Fake<IRuleEventRepository>();
private readonly RuleService ruleService = A.Fake<RuleService>();
private readonly Instant now = SystemClock.Instance.GetCurrentInstant();
@ -36,7 +36,7 @@ namespace Squidex.Domain.Apps.Read.Rules
{
sut = new RuleEnqueuer(
ruleEventRepository,
ruleRepository,
appProvider,
ruleService);
}
@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Read.Rules
A.CallTo(() => ruleEntity2.Rule).Returns(rule2);
A.CallTo(() => ruleEntity3.Rule).Returns(rule3);
A.CallTo(() => ruleRepository.QueryCachedByAppAsync(appId.Id))
A.CallTo(() => appProvider.GetRulesAsync(appId.Name))
.Returns(new List<IRuleEntity> { ruleEntity1, ruleEntity2, ruleEntity3 });
A.CallTo(() => ruleService.CreateJob(rule1, @event))

134
tests/Squidex.Domain.Apps.Read.Tests/Schemas/CachingSchemaProviderTests.cs

@ -1,134 +0,0 @@
// ==========================================================================
// CachingSchemaProviderTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Threading.Tasks;
using FakeItEasy;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using Squidex.Domain.Apps.Events.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Repositories;
using Squidex.Domain.Apps.Read.Schemas.Services.Implementations;
using Squidex.Infrastructure;
using Squidex.Infrastructure.CQRS.Events;
using Xunit;
namespace Squidex.Domain.Apps.Read.Schemas
{
public class CachingSchemaProviderTests
{
private readonly IMemoryCache cache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
private readonly ISchemaRepository repository = A.Fake<ISchemaRepository>();
private readonly CachingSchemaProvider sut;
private readonly ISchemaEntity schemaV1 = A.Dummy<ISchemaEntity>();
private readonly ISchemaEntity schemaV2 = A.Dummy<ISchemaEntity>();
private readonly NamedId<Guid> schemaId = new NamedId<Guid>(Guid.NewGuid(), "my-schema");
private readonly NamedId<Guid> appId = new NamedId<Guid>(Guid.NewGuid(), "my-app");
public CachingSchemaProviderTests()
{
A.CallTo(() => schemaV1.Id).Returns(schemaId.Id);
A.CallTo(() => schemaV1.Name).Returns(schemaId.Name);
A.CallTo(() => schemaV1.AppId).Returns(appId.Id);
A.CallTo(() => schemaV2.Id).Returns(schemaId.Id);
A.CallTo(() => schemaV2.Name).Returns(schemaId.Name);
A.CallTo(() => schemaV2.AppId).Returns(appId.Id);
sut = new CachingSchemaProvider(cache, repository);
}
[Fact]
public void Should_return_empty_for_events_filter()
{
Assert.Equal(string.Empty, sut.EventsFilter);
}
[Fact]
public void Should_return_empty_for_name()
{
Assert.Equal(typeof(CachingSchemaProvider).Name, sut.Name);
}
[Fact]
public void Should_do_nothing_when_clearing()
{
Assert.NotNull(sut.ClearAsync());
}
[Fact]
public async Task Should_also_retrieve_schema_by_name_if_retrieved_by_id_before()
{
A.CallTo(() => repository.FindSchemaAsync(schemaId.Id))
.Returns(schemaV1);
await ProvideSchemaById(schemaV1);
await ProvideSchemaByName(schemaV1);
A.CallTo(() => repository.FindSchemaAsync(schemaId.Id)).MustHaveHappened();
A.CallTo(() => repository.FindSchemaAsync(appId.Id, schemaId.Name)).MustNotHaveHappened();
}
[Fact]
public async Task Should_also_retrieve_schema_by_id_if_retrieved_by_name_before()
{
A.CallTo(() => repository.FindSchemaAsync(appId.Id, schemaId.Name))
.Returns(schemaV1);
await ProvideSchemaByName(schemaV1);
await ProvideSchemaById(schemaV1);
A.CallTo(() => repository.FindSchemaAsync(schemaId.Id)).MustNotHaveHappened();
A.CallTo(() => repository.FindSchemaAsync(appId.Id, schemaId.Name)).MustHaveHappened();
}
[Fact]
public async Task Should_clear_cache_for_id_after_update_event()
{
A.CallTo(() => repository.FindSchemaAsync(schemaId.Id))
.Returns(schemaV2);
A.CallTo(() => repository.FindSchemaAsync(schemaId.Id))
.Returns(schemaV1).Once();
await ProvideSchemaById(schemaV1);
sut.On(Envelope.Create(new FieldAdded { AppId = appId, SchemaId = schemaId })).Wait();
await ProvideSchemaById(schemaV2);
A.CallTo(() => repository.FindSchemaAsync(schemaId.Id)).MustHaveHappened(Repeated.Exactly.Times(2));
}
[Fact]
public async Task Should_clear_cache_for_name_after_update_event()
{
A.CallTo(() => repository.FindSchemaAsync(appId.Id, schemaId.Name))
.Returns(schemaV2);
A.CallTo(() => repository.FindSchemaAsync(appId.Id, schemaId.Name))
.Returns(schemaV1).Once();
await ProvideSchemaByName(schemaV1);
sut.On(Envelope.Create(new SchemaUpdated { AppId = appId, SchemaId = schemaId })).Wait();
await ProvideSchemaByName(schemaV2);
A.CallTo(() => repository.FindSchemaAsync(appId.Id, schemaId.Name)).MustHaveHappened(Repeated.Exactly.Times(2));
}
private async Task ProvideSchemaById(ISchemaEntity schema)
{
Assert.Equal(schema, await sut.FindSchemaByIdAsync(schemaId.Id));
}
private async Task ProvideSchemaByName(ISchemaEntity schema)
{
Assert.Equal(schema, await sut.FindSchemaByNameAsync(appId.Id, schemaId.Name));
}
}
}

6
tests/Squidex.Domain.Apps.Write.Tests/Contents/ContentCommandMiddlewareTests.cs

@ -20,7 +20,6 @@ using Squidex.Domain.Apps.Read.Apps;
using Squidex.Domain.Apps.Read.Assets.Repositories;
using Squidex.Domain.Apps.Read.Contents.Repositories;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Squidex.Domain.Apps.Write.Contents.Commands;
using Squidex.Domain.Apps.Write.TestHelpers;
using Squidex.Infrastructure;
@ -33,7 +32,6 @@ namespace Squidex.Domain.Apps.Write.Contents
{
private readonly ContentCommandMiddleware sut;
private readonly ContentDomainObject content;
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly ISchemaEntity schema = A.Fake<ISchemaEntity>();
private readonly IScriptEngine scriptEngine = A.Fake<IScriptEngine>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
@ -70,7 +68,7 @@ namespace Squidex.Domain.Apps.Write.Contents
content = new ContentDomainObject(contentId, -1);
sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy<IAssetRepository>(), schemas, scriptEngine, A.Dummy<IContentRepository>());
sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy<IAssetRepository>(), scriptEngine, A.Dummy<IContentRepository>());
A.CallTo(() => app.LanguagesConfig).Returns(languagesConfig);
@ -82,7 +80,7 @@ namespace Squidex.Domain.Apps.Write.Contents
A.CallTo(() => schema.ScriptUpdate).Returns("<update-script>");
A.CallTo(() => schema.ScriptDelete).Returns("<delete-script>");
A.CallTo(() => schemas.FindSchemaByIdAsync(SchemaId, false)).Returns(schema);
A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppName, SchemaId)).Returns((app, schema));
}
[Fact]

29
tests/Squidex.Domain.Apps.Write.Tests/Rules/Guards/GuardRuleTests.cs

@ -13,8 +13,8 @@ using FakeItEasy;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Core.Rules.Actions;
using Squidex.Domain.Apps.Core.Rules.Triggers;
using Squidex.Domain.Apps.Read;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Squidex.Domain.Apps.Write.Rules.Commands;
using Squidex.Infrastructure;
using Xunit;
@ -25,11 +25,12 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards
{
private readonly Uri validUrl = new Uri("https://squidex.io");
private readonly Rule rule = new Rule(new ContentChangedTrigger(), new WebhookAction());
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly NamedId<Guid> appId = new NamedId<Guid>(Guid.NewGuid(), "my-app");
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
public GuardRuleTests()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(A<Guid>.Ignored, false))
A.CallTo(() => appProvider.GetSchemaAsync(appId.Name, A<Guid>.Ignored, false))
.Returns(A.Fake<ISchemaEntity>());
}
@ -42,10 +43,11 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards
Action = new WebhookAction
{
Url = validUrl
}
},
AppId = appId
};
await Assert.ThrowsAsync<ValidationException>(() => GuardRule.CanCreate(command, schemas));
await Assert.ThrowsAsync<ValidationException>(() => GuardRule.CanCreate(command, appProvider));
}
[Fact]
@ -57,10 +59,11 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards
{
Schemas = new List<ContentChangedTriggerSchema>()
},
Action = null
Action = null,
AppId = appId
};
await Assert.ThrowsAsync<ValidationException>(() => GuardRule.CanCreate(command, schemas));
await Assert.ThrowsAsync<ValidationException>(() => GuardRule.CanCreate(command, appProvider));
}
[Fact]
@ -75,10 +78,11 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards
Action = new WebhookAction
{
Url = validUrl
}
},
AppId = appId
};
await GuardRule.CanCreate(command, schemas);
await GuardRule.CanCreate(command, appProvider);
}
[Fact]
@ -86,7 +90,7 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards
{
var command = new UpdateRule();
await Assert.ThrowsAsync<ValidationException>(() => GuardRule.CanUpdate(command, schemas));
await Assert.ThrowsAsync<ValidationException>(() => GuardRule.CanUpdate(command, appProvider));
}
[Fact]
@ -101,10 +105,11 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards
Action = new WebhookAction
{
Url = validUrl
}
},
AppId = appId
};
await GuardRule.CanUpdate(command, schemas);
await GuardRule.CanUpdate(command, appProvider);
}
[Fact]

17
tests/Squidex.Domain.Apps.Write.Tests/Rules/Guards/Triggers/ContentChangedTriggerTests.cs

@ -11,20 +11,21 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using FakeItEasy;
using Squidex.Domain.Apps.Core.Rules.Triggers;
using Squidex.Domain.Apps.Read;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Xunit;
namespace Squidex.Domain.Apps.Write.Rules.Guards.Triggers
{
public class ContentChangedTriggerTests
{
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly string appName = "my-app";
[Fact]
public async Task Should_add_error_if_schemas_ids_are_not_valid()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(A<Guid>.Ignored, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, A<Guid>.Ignored, false))
.Returns(Task.FromResult<ISchemaEntity>(null));
var trigger = new ContentChangedTrigger
@ -35,7 +36,7 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards.Triggers
}
};
var errors = await RuleTriggerValidator.ValidateAsync(trigger, schemas);
var errors = await RuleTriggerValidator.ValidateAsync(appName, trigger, appProvider);
Assert.NotEmpty(errors);
}
@ -45,7 +46,7 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards.Triggers
{
var trigger = new ContentChangedTrigger();
var errors = await RuleTriggerValidator.ValidateAsync(trigger, schemas);
var errors = await RuleTriggerValidator.ValidateAsync(appName, trigger, appProvider);
Assert.Empty(errors);
}
@ -58,7 +59,7 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards.Triggers
Schemas = new List<ContentChangedTriggerSchema>()
};
var errors = await RuleTriggerValidator.ValidateAsync(trigger, schemas);
var errors = await RuleTriggerValidator.ValidateAsync(appName, trigger, appProvider);
Assert.Empty(errors);
}
@ -66,7 +67,7 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards.Triggers
[Fact]
public async Task Should_not_add_error_if_schemas_ids_are_valid()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(A<Guid>.Ignored, false))
A.CallTo(() => appProvider.GetSchemaAsync(appName, A<Guid>.Ignored, false))
.Returns(A.Fake<ISchemaEntity>());
var trigger = new ContentChangedTrigger
@ -77,7 +78,7 @@ namespace Squidex.Domain.Apps.Write.Rules.Guards.Triggers
}
};
var errors = await RuleTriggerValidator.ValidateAsync(trigger, schemas);
var errors = await RuleTriggerValidator.ValidateAsync(appName, trigger, appProvider);
Assert.Empty(errors);
}

8
tests/Squidex.Domain.Apps.Write.Tests/Rules/RuleCommandMiddlewareTests.cs

@ -12,8 +12,8 @@ using FakeItEasy;
using Squidex.Domain.Apps.Core.Rules;
using Squidex.Domain.Apps.Core.Rules.Actions;
using Squidex.Domain.Apps.Core.Rules.Triggers;
using Squidex.Domain.Apps.Read;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Squidex.Domain.Apps.Write.Rules.Commands;
using Squidex.Domain.Apps.Write.TestHelpers;
using Squidex.Infrastructure.CQRS.Commands;
@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Write.Rules
{
public class RuleCommandMiddlewareTests : HandlerTestBase<RuleDomainObject>
{
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly RuleCommandMiddleware sut;
private readonly RuleDomainObject rule;
private readonly RuleTrigger ruleTrigger = new ContentChangedTrigger();
@ -32,12 +32,12 @@ namespace Squidex.Domain.Apps.Write.Rules
public RuleCommandMiddlewareTests()
{
A.CallTo(() => schemas.FindSchemaByIdAsync(A<Guid>.Ignored, false))
A.CallTo(() => appProvider.GetSchemaAsync(A<string>.Ignored, A<Guid>.Ignored, false))
.Returns(A.Fake<ISchemaEntity>());
rule = new RuleDomainObject(ruleId, -1);
sut = new RuleCommandMiddleware(Handler, schemas);
sut = new RuleCommandMiddleware(Handler, appProvider);
}
[Fact]

18
tests/Squidex.Domain.Apps.Write.Tests/Schemas/Guards/GuardSchemaTests.cs

@ -12,8 +12,8 @@ using System.Threading.Tasks;
using FakeItEasy;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Read;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Squidex.Domain.Apps.Write.Schemas.Commands;
using Squidex.Infrastructure;
using Xunit;
@ -22,7 +22,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
{
public class GuardSchemaTests
{
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly Schema schema = new Schema("my-schema");
private readonly NamedId<Guid> appId = new NamedId<Guid>(Guid.NewGuid(), "my-app");
@ -31,7 +31,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
schema.AddField(new StringField(1, "field1", Partitioning.Invariant));
schema.AddField(new StringField(2, "field2", Partitioning.Invariant));
A.CallTo(() => schemas.FindSchemaByNameAsync(A<Guid>.Ignored, "new-schema"))
A.CallTo(() => appProvider.GetSchemaAsync(A<string>.Ignored, "new-schema", false))
.Returns(Task.FromResult<ISchemaEntity>(null));
}
@ -40,18 +40,18 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
{
var command = new CreateSchema { AppId = appId, Name = "INVALID NAME" };
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, schemas));
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, appProvider));
}
[Fact]
public Task CanCreate_should_throw_exception_if_name_already_in_use()
{
A.CallTo(() => schemas.FindSchemaByNameAsync(A<Guid>.Ignored, "new-schema"))
A.CallTo(() => appProvider.GetSchemaAsync(A<string>.Ignored, "new-schema", false))
.Returns(Task.FromResult(A.Fake<ISchemaEntity>()));
var command = new CreateSchema { AppId = appId, Name = "new-schema" };
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, schemas));
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, appProvider));
}
[Fact]
@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
Name = "new-schema"
};
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, schemas));
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, appProvider));
}
[Fact]
@ -105,7 +105,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
Name = "new-schema"
};
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, schemas));
return Assert.ThrowsAsync<ValidationException>(() => GuardSchema.CanCreate(command, appProvider));
}
[Fact]
@ -113,7 +113,7 @@ namespace Squidex.Domain.Apps.Write.Schemas.Guards
{
var command = new CreateSchema { AppId = appId, Name = "new-schema" };
return GuardSchema.CanCreate(command, schemas);
return GuardSchema.CanCreate(command, appProvider);
}
[Fact]

10
tests/Squidex.Domain.Apps.Write.Tests/Schemas/SchemaCommandMiddlewareTests.cs

@ -11,8 +11,8 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using FakeItEasy;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Read;
using Squidex.Domain.Apps.Read.Schemas;
using Squidex.Domain.Apps.Read.Schemas.Services;
using Squidex.Domain.Apps.Write.Schemas.Commands;
using Squidex.Domain.Apps.Write.TestHelpers;
using Squidex.Infrastructure;
@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Write.Schemas
{
public class SchemaCommandMiddlewareTests : HandlerTestBase<SchemaDomainObject>
{
private readonly ISchemaProvider schemas = A.Fake<ISchemaProvider>();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly SchemaCommandMiddleware sut;
private readonly SchemaDomainObject schema;
private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry());
@ -33,9 +33,9 @@ namespace Squidex.Domain.Apps.Write.Schemas
{
schema = new SchemaDomainObject(SchemaId, -1, registry);
sut = new SchemaCommandMiddleware(Handler, schemas);
sut = new SchemaCommandMiddleware(Handler, appProvider);
A.CallTo(() => schemas.FindSchemaByNameAsync(AppId, SchemaName))
A.CallTo(() => appProvider.GetSchemaAsync(AppName, SchemaName, false))
.Returns((ISchemaEntity)null);
}
@ -51,7 +51,7 @@ namespace Squidex.Domain.Apps.Write.Schemas
Assert.Equal(SchemaId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);
A.CallTo(() => schemas.FindSchemaByNameAsync(AppId, SchemaName)).MustHaveHappened();
A.CallTo(() => appProvider.GetSchemaAsync(AppName, SchemaName, false)).MustHaveHappened();
}
[Fact]

62
tests/Squidex.Infrastructure.Tests/Reflection/SimpleCopierTests.cs

@ -0,0 +1,62 @@
// ==========================================================================
// SimpleCopierTests.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using Xunit;
namespace Squidex.Infrastructure.Reflection
{
public class SimpleCopierTests
{
public class Cloneable : ICloneable
{
public int Value { get; }
public Cloneable(int value)
{
Value = value;
}
public object Clone()
{
return new Cloneable(Value);
}
}
public class MyClass1Base
{
public int Value1 { get; set; }
}
public class MyClass1 : MyClass1Base
{
public int Value2 { get; set; }
public Cloneable Cloneable { get; set; }
}
[Fact]
public void Should_copy_class()
{
var value = new MyClass1
{
Value1 = 1,
Value2 = 2,
Cloneable = new Cloneable(4)
};
var copy = value.Copy();
Assert.Equal(value.Value1, copy.Value1);
Assert.Equal(value.Value2, copy.Value2);
Assert.Equal(value.Cloneable.Value, copy.Cloneable.Value);
Assert.NotSame(value.Cloneable, copy.Cloneable);
}
}
}
Loading…
Cancel
Save