mirror of https://github.com/Squidex/squidex.git
14 changed files with 2827 additions and 2995 deletions
@ -1,291 +1,291 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Squidex.Domain.Apps.Entities.Apps.Commands; |
|||
using Squidex.Domain.Apps.Entities.Apps.Services; |
|||
using Squidex.Domain.Apps.Entities.Apps.Services.Implementations; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.States; |
|||
using Squidex.Shared.Users; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Apps |
|||
{ |
|||
public class AppCommandMiddlewareTests : HandlerTestBase<AppDomainObject> |
|||
{ |
|||
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|||
private readonly IAppPlansProvider appPlansProvider = A.Fake<IAppPlansProvider>(); |
|||
private readonly IAppPlanBillingManager appPlansBillingManager = A.Fake<IAppPlanBillingManager>(); |
|||
private readonly IUserResolver userResolver = A.Fake<IUserResolver>(); |
|||
private readonly Language language = Language.DE; |
|||
private readonly string contributorId = Guid.NewGuid().ToString(); |
|||
private readonly string clientName = "client"; |
|||
private readonly Guid patternId = Guid.NewGuid(); |
|||
private readonly AppDomainObject app = new AppDomainObject(new InitialPatterns()); |
|||
private readonly AppCommandMiddleware sut; |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return AppId; } |
|||
} |
|||
|
|||
public AppCommandMiddlewareTests() |
|||
{ |
|||
A.CallTo(() => appProvider.GetAppAsync(AppName)) |
|||
.Returns((IAppEntity)null); |
|||
|
|||
A.CallTo(() => userResolver.FindByIdAsync(contributorId)) |
|||
.Returns(A.Fake<IUser>()); |
|||
|
|||
sut = new AppCommandMiddleware(Handler, appProvider, appPlansProvider, appPlansBillingManager, userResolver); |
|||
|
|||
app.ActivateAsync(Id, A.Fake<IStore<Guid>>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new CreateApp { Name = AppName, AppId = AppId }); |
|||
|
|||
await TestCreate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Equal(AppId, context.Result<EntityCreatedResult<Guid>>().IdOrValue); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AssignContributor_should_update_domain_object_if_user_found() |
|||
{ |
|||
A.CallTo(() => appPlansProvider.GetPlan(null)) |
|||
.Returns(new ConfigAppLimitsPlan { MaxContributors = -1 }); |
|||
|
|||
CreateApp(); |
|||
|
|||
var context = CreateContextForCommand(new AssignContributor { ContributorId = contributorId }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RemoveContributor_should_update_domain_object() |
|||
{ |
|||
CreateApp() |
|||
.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId })); |
|||
|
|||
var context = CreateContextForCommand(new RemoveContributor { ContributorId = contributorId }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AttachClient_should_update_domain_object() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
var context = CreateContextForCommand(new AttachClient { Id = clientName }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RenameClient_should_update_domain_object() |
|||
{ |
|||
CreateApp() |
|||
.AttachClient(CreateCommand(new AttachClient { Id = clientName })); |
|||
|
|||
var context = CreateContextForCommand(new UpdateClient { Id = clientName, Name = "New Name" }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RevokeClient_should_update_domain_object() |
|||
{ |
|||
CreateApp() |
|||
.AttachClient(CreateCommand(new AttachClient { Id = clientName })); |
|||
|
|||
var context = CreateContextForCommand(new RevokeClient { Id = clientName }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ChangePlan_should_update_domain_object() |
|||
{ |
|||
A.CallTo(() => appPlansProvider.IsConfiguredPlan("my-plan")) |
|||
.Returns(true); |
|||
|
|||
CreateApp(); |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.Threading.Tasks;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Entities.Apps.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.Apps.Services;
|
|||
//using Squidex.Domain.Apps.Entities.Apps.Services.Implementations;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.Commands;
|
|||
//using Squidex.Infrastructure.States;
|
|||
//using Squidex.Shared.Users;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Apps
|
|||
//{
|
|||
// public class AppCommandMiddlewareTests : HandlerTestBase<AppDomainObject>
|
|||
// {
|
|||
// private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
|
|||
// private readonly IAppPlansProvider appPlansProvider = A.Fake<IAppPlansProvider>();
|
|||
// private readonly IAppPlanBillingManager appPlansBillingManager = A.Fake<IAppPlanBillingManager>();
|
|||
// private readonly IUserResolver userResolver = A.Fake<IUserResolver>();
|
|||
// private readonly Language language = Language.DE;
|
|||
// private readonly string contributorId = Guid.NewGuid().ToString();
|
|||
// private readonly string clientName = "client";
|
|||
// private readonly Guid patternId = Guid.NewGuid();
|
|||
// private readonly AppDomainObject app = new AppDomainObject(new InitialPatterns());
|
|||
// private readonly AppCommandMiddleware sut;
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return AppId; }
|
|||
// }
|
|||
|
|||
// public AppCommandMiddlewareTests()
|
|||
// {
|
|||
// A.CallTo(() => appProvider.GetAppAsync(AppName))
|
|||
// .Returns((IAppEntity)null);
|
|||
|
|||
// A.CallTo(() => userResolver.FindByIdAsync(contributorId))
|
|||
// .Returns(A.Fake<IUser>());
|
|||
|
|||
// sut = new AppCommandMiddleware(Handler, appProvider, appPlansProvider, appPlansBillingManager, userResolver);
|
|||
|
|||
// app.ActivateAsync(Id, A.Fake<IStore<Guid>>());
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_create_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new CreateApp { Name = AppName, AppId = AppId });
|
|||
|
|||
// await TestCreate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(AppId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task AssignContributor_should_update_domain_object_if_user_found()
|
|||
// {
|
|||
// A.CallTo(() => appPlansProvider.GetPlan(null))
|
|||
// .Returns(new ConfigAppLimitsPlan { MaxContributors = -1 });
|
|||
|
|||
// CreateApp();
|
|||
|
|||
// var context = CreateContextForCommand(new AssignContributor { ContributorId = contributorId });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task RemoveContributor_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId }));
|
|||
|
|||
// var context = CreateContextForCommand(new RemoveContributor { ContributorId = contributorId });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task AttachClient_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// var context = CreateContextForCommand(new AttachClient { Id = clientName });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task RenameClient_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AttachClient(CreateCommand(new AttachClient { Id = clientName }));
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateClient { Id = clientName, Name = "New Name" });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task RevokeClient_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AttachClient(CreateCommand(new AttachClient { Id = clientName }));
|
|||
|
|||
// var context = CreateContextForCommand(new RevokeClient { Id = clientName });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ChangePlan_should_update_domain_object()
|
|||
// {
|
|||
// A.CallTo(() => appPlansProvider.IsConfiguredPlan("my-plan"))
|
|||
// .Returns(true);
|
|||
|
|||
// CreateApp();
|
|||
|
|||
var context = CreateContextForCommand(new ChangePlan { PlanId = "my-plan" }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, "my-plan")) |
|||
.MustHaveHappened(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ChangePlan_should_not_make_update_for_redirect_result() |
|||
{ |
|||
A.CallTo(() => appPlansProvider.IsConfiguredPlan("my-plan")) |
|||
.Returns(true); |
|||
|
|||
A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, "my-plan")) |
|||
.Returns(CreateRedirectResult()); |
|||
|
|||
CreateApp(); |
|||
|
|||
var context = CreateContextForCommand(new ChangePlan { PlanId = "my-plan" }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Null(app.Snapshot.Plan); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ChangePlan_should_not_call_billing_manager_for_callback() |
|||
{ |
|||
A.CallTo(() => appPlansProvider.IsConfiguredPlan("my-plan")) |
|||
.Returns(true); |
|||
|
|||
CreateApp(); |
|||
|
|||
var context = CreateContextForCommand(new ChangePlan { PlanId = "my-plan", FromCallback = true }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, "my-plan")) |
|||
.MustNotHaveHappened(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AddLanguage_should_update_domain_object() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
var context = CreateContextForCommand(new AddLanguage { Language = language }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RemoveLanguage_should_update_domain_object() |
|||
{ |
|||
CreateApp() |
|||
.AddLanguage(CreateCommand(new AddLanguage { Language = language })); |
|||
|
|||
var context = CreateContextForCommand(new RemoveLanguage { Language = language }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateLanguage_should_update_domain_object() |
|||
{ |
|||
CreateApp() |
|||
.AddLanguage(CreateCommand(new AddLanguage { Language = language })); |
|||
|
|||
var context = CreateContextForCommand(new UpdateLanguage { Language = language }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AddPattern_should_update_domain_object() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
var context = CreateContextForCommand(new AddPattern { Name = "Any", Pattern = ".*" }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdatePattern_should_update_domain() |
|||
{ |
|||
CreateApp() |
|||
.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = "." })); |
|||
|
|||
var context = CreateContextForCommand(new UpdatePattern { PatternId = patternId, Name = "Number", Pattern = "[0-9]" }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeletePattern_should_update_domain_object() |
|||
{ |
|||
CreateApp() |
|||
.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = "." })); |
|||
|
|||
var context = CreateContextForCommand(new DeletePattern { PatternId = patternId }); |
|||
|
|||
await TestUpdate(app, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
private AppDomainObject CreateApp() |
|||
{ |
|||
app.Create(CreateCommand(new CreateApp { AppId = AppId, Name = AppName })); |
|||
|
|||
return app; |
|||
} |
|||
|
|||
private static Task<IChangePlanResult> CreateRedirectResult() |
|||
{ |
|||
return Task.FromResult<IChangePlanResult>(new RedirectToCheckoutResult(new Uri("http://squidex.io"))); |
|||
} |
|||
} |
|||
} |
|||
// var context = CreateContextForCommand(new ChangePlan { PlanId = "my-plan" });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, "my-plan"))
|
|||
// .MustHaveHappened();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ChangePlan_should_not_make_update_for_redirect_result()
|
|||
// {
|
|||
// A.CallTo(() => appPlansProvider.IsConfiguredPlan("my-plan"))
|
|||
// .Returns(true);
|
|||
|
|||
// A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, "my-plan"))
|
|||
// .Returns(CreateRedirectResult());
|
|||
|
|||
// CreateApp();
|
|||
|
|||
// var context = CreateContextForCommand(new ChangePlan { PlanId = "my-plan" });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Null(app.Snapshot.Plan);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ChangePlan_should_not_call_billing_manager_for_callback()
|
|||
// {
|
|||
// A.CallTo(() => appPlansProvider.IsConfiguredPlan("my-plan"))
|
|||
// .Returns(true);
|
|||
|
|||
// CreateApp();
|
|||
|
|||
// var context = CreateContextForCommand(new ChangePlan { PlanId = "my-plan", FromCallback = true });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, "my-plan"))
|
|||
// .MustNotHaveHappened();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task AddLanguage_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// var context = CreateContextForCommand(new AddLanguage { Language = language });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task RemoveLanguage_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AddLanguage(CreateCommand(new AddLanguage { Language = language }));
|
|||
|
|||
// var context = CreateContextForCommand(new RemoveLanguage { Language = language });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UpdateLanguage_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AddLanguage(CreateCommand(new AddLanguage { Language = language }));
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateLanguage { Language = language });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task AddPattern_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// var context = CreateContextForCommand(new AddPattern { Name = "Any", Pattern = ".*" });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UpdatePattern_should_update_domain()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = "." }));
|
|||
|
|||
// var context = CreateContextForCommand(new UpdatePattern { PatternId = patternId, Name = "Number", Pattern = "[0-9]" });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DeletePattern_should_update_domain_object()
|
|||
// {
|
|||
// CreateApp()
|
|||
// .AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = "." }));
|
|||
|
|||
// var context = CreateContextForCommand(new DeletePattern { PatternId = patternId });
|
|||
|
|||
// await TestUpdate(app, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// private AppDomainObject CreateApp()
|
|||
// {
|
|||
// app.Create(CreateCommand(new CreateApp { AppId = AppId, Name = AppName }));
|
|||
|
|||
// return app;
|
|||
// }
|
|||
|
|||
// private static Task<IChangePlanResult> CreateRedirectResult()
|
|||
// {
|
|||
// return Task.FromResult<IChangePlanResult>(new RedirectToCheckoutResult(new Uri("http://squidex.io")));
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
@ -1,399 +1,399 @@ |
|||
// ==========================================================================
|
|||
// 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 FakeItEasy; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Squidex.Domain.Apps.Entities.Apps.Commands; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Apps; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Apps |
|||
{ |
|||
public class AppDomainObjectTests : HandlerTestBase<AppDomainObject> |
|||
{ |
|||
private readonly string contributorId = Guid.NewGuid().ToString(); |
|||
private readonly string clientId = "client"; |
|||
private readonly string clientNewName = "My Client"; |
|||
private readonly string planId = "premium"; |
|||
private readonly Guid patternId = Guid.NewGuid(); |
|||
private readonly AppDomainObject sut = new AppDomainObject(new InitialPatterns()); |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return AppId; } |
|||
} |
|||
|
|||
public AppDomainObjectTests() |
|||
{ |
|||
sut.ActivateAsync(Id, A.Fake<IStore<Guid>>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_throw_exception_if_created() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Create(CreateCommand(new CreateApp { Name = AppName })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_specify_name_and_owner() |
|||
{ |
|||
var id1 = Guid.NewGuid(); |
|||
var id2 = Guid.NewGuid(); |
|||
|
|||
var initialPatterns = new InitialPatterns |
|||
{ |
|||
{ id1, new AppPattern("Number", "[0-9]") }, |
|||
{ id2, new AppPattern("Numbers", "[0-9]*") } |
|||
}; |
|||
|
|||
var app = new AppDomainObject(initialPatterns); |
|||
|
|||
app.Create(CreateCommand(new CreateApp { Name = AppName, Actor = User, AppId = AppId })); |
|||
|
|||
Assert.Equal(AppName, app.Snapshot.Name); |
|||
|
|||
app.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppCreated { Name = AppName }), |
|||
CreateEvent(new AppContributorAssigned { ContributorId = User.Identifier, Permission = AppContributorPermission.Owner }), |
|||
CreateEvent(new AppLanguageAdded { Language = Language.EN }), |
|||
CreateEvent(new AppPatternAdded { PatternId = id1, Name = "Number", Pattern = "[0-9]" }), |
|||
CreateEvent(new AppPatternAdded { PatternId = id2, Name = "Numbers", Pattern = "[0-9]*" }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ChangePlan_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.ChangePlan(CreateCommand(new ChangePlan { PlanId = planId })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ChangePlan_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
sut.ChangePlan(CreateCommand(new ChangePlan { PlanId = planId })); |
|||
|
|||
Assert.Equal(planId, sut.Snapshot.Plan.PlanId); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPlanChanged { PlanId = planId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AssignContributor_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AssignContributor_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = AppContributorPermission.Editor })); |
|||
|
|||
Assert.Equal(AppContributorPermission.Editor, sut.Snapshot.Contributors[contributorId]); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppContributorAssigned { ContributorId = contributorId, Permission = AppContributorPermission.Editor }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RemoveContributor_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.RemoveContributor(CreateCommand(new RemoveContributor { ContributorId = contributorId })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RemoveContributor_should_create_events_and_remove_contributor() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = AppContributorPermission.Editor })); |
|||
sut.RemoveContributor(CreateCommand(new RemoveContributor { ContributorId = contributorId })); |
|||
|
|||
Assert.False(sut.Snapshot.Contributors.ContainsKey(contributorId)); |
|||
|
|||
sut.GetUncomittedEvents().Skip(1) |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppContributorRemoved { ContributorId = contributorId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AttachClient_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.AttachClient(CreateCommand(new AttachClient { Id = clientId })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AttachClient_should_create_events() |
|||
{ |
|||
var command = new AttachClient { Id = clientId }; |
|||
|
|||
CreateApp(); |
|||
|
|||
sut.AttachClient(CreateCommand(command)); |
|||
|
|||
Assert.True(sut.Snapshot.Clients.ContainsKey(clientId)); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppClientAttached { Id = clientId, Secret = command.Secret }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RevokeClient_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.RevokeClient(CreateCommand(new RevokeClient { Id = "not-found" })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RevokeClient_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
CreateClient(); |
|||
|
|||
sut.RevokeClient(CreateCommand(new RevokeClient { Id = clientId })); |
|||
|
|||
Assert.False(sut.Snapshot.Clients.ContainsKey(clientId)); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppClientRevoked { Id = clientId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UpdateClient_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.UpdateClient(CreateCommand(new UpdateClient { Id = "not-found", Name = clientNewName })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UpdateClient_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
CreateClient(); |
|||
|
|||
sut.UpdateClient(CreateCommand(new UpdateClient { Id = clientId, Name = clientNewName, Permission = AppClientPermission.Developer })); |
|||
|
|||
Assert.Equal(clientNewName, sut.Snapshot.Clients[clientId].Name); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppClientRenamed { Id = clientId, Name = clientNewName }), |
|||
CreateEvent(new AppClientUpdated { Id = clientId, Permission = AppClientPermission.Developer }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddLanguage_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.AddLanguage(CreateCommand(new AddLanguage { Language = Language.DE })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddLanguage_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
sut.AddLanguage(CreateCommand(new AddLanguage { Language = Language.DE })); |
|||
|
|||
Assert.True(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppLanguageAdded { Language = Language.DE }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RemoveLanguage_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.RemoveLanguage(CreateCommand(new RemoveLanguage { Language = Language.EN })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void RemoveLanguage_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
CreateLanguage(Language.DE); |
|||
|
|||
sut.RemoveLanguage(CreateCommand(new RemoveLanguage { Language = Language.DE })); |
|||
|
|||
Assert.False(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppLanguageRemoved { Language = Language.DE }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UpdateLanguage_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.UpdateLanguage(CreateCommand(new UpdateLanguage { Language = Language.EN })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UpdateLanguage_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
CreateLanguage(Language.DE); |
|||
|
|||
sut.UpdateLanguage(CreateCommand(new UpdateLanguage { Language = Language.DE, Fallback = new List<Language> { Language.EN } })); |
|||
|
|||
Assert.True(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppLanguageUpdated { Language = Language.DE, Fallback = new List<Language> { Language.EN } }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddPattern_should_throw_exception_if_app_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = ".*" }))); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddPattern_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
|
|||
sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })); |
|||
|
|||
Assert.Single(sut.Snapshot.Patterns); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPatternAdded { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DeletePattern_should_throw_exception_if_app_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.DeletePattern(CreateCommand(new DeletePattern |
|||
{ |
|||
PatternId = Guid.NewGuid() |
|||
})); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DeletePattern_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
CreatePattern(); |
|||
|
|||
sut.DeletePattern(CreateCommand(new DeletePattern { PatternId = patternId })); |
|||
|
|||
Assert.Empty(sut.Snapshot.Patterns); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPatternDeleted { PatternId = patternId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UpdatePattern_should_throw_exception_if_app_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => sut.UpdatePattern(CreateCommand(new UpdatePattern { PatternId = patternId, Name = "Any", Pattern = ".*" }))); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UpdatePattern_should_create_events() |
|||
{ |
|||
CreateApp(); |
|||
CreatePattern(); |
|||
|
|||
sut.UpdatePattern(CreateCommand(new UpdatePattern { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })); |
|||
|
|||
Assert.Single(sut.Snapshot.Patterns); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPatternUpdated { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }) |
|||
); |
|||
} |
|||
|
|||
private void CreatePattern() |
|||
{ |
|||
sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Name", Pattern = ".*" })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void CreateApp() |
|||
{ |
|||
sut.Create(CreateCommand(new CreateApp { Name = AppName })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void CreateClient() |
|||
{ |
|||
sut.AttachClient(CreateCommand(new AttachClient { Id = clientId })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void CreateLanguage(Language language) |
|||
{ |
|||
sut.AddLanguage(CreateCommand(new AddLanguage { Language = language })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
} |
|||
} |
|||
//// ==========================================================================
|
|||
//// 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 FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Core.Apps;
|
|||
//using Squidex.Domain.Apps.Entities.Apps.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Domain.Apps.Events.Apps;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.States;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Apps
|
|||
//{
|
|||
// public class AppDomainObjectTests : HandlerTestBase<AppDomainObject>
|
|||
// {
|
|||
// private readonly string contributorId = Guid.NewGuid().ToString();
|
|||
// private readonly string clientId = "client";
|
|||
// private readonly string clientNewName = "My Client";
|
|||
// private readonly string planId = "premium";
|
|||
// private readonly Guid patternId = Guid.NewGuid();
|
|||
// private readonly AppDomainObject sut = new AppDomainObject(new InitialPatterns());
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return AppId; }
|
|||
// }
|
|||
|
|||
// public AppDomainObjectTests()
|
|||
// {
|
|||
// sut.ActivateAsync(Id, A.Fake<IStore<Guid>>());
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_throw_exception_if_created()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Create(CreateCommand(new CreateApp { Name = AppName }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_specify_name_and_owner()
|
|||
// {
|
|||
// var id1 = Guid.NewGuid();
|
|||
// var id2 = Guid.NewGuid();
|
|||
|
|||
// var initialPatterns = new InitialPatterns
|
|||
// {
|
|||
// { id1, new AppPattern("Number", "[0-9]") },
|
|||
// { id2, new AppPattern("Numbers", "[0-9]*") }
|
|||
// };
|
|||
|
|||
// var app = new AppDomainObject(initialPatterns);
|
|||
|
|||
// app.Create(CreateCommand(new CreateApp { Name = AppName, Actor = User, AppId = AppId }));
|
|||
|
|||
// Assert.Equal(AppName, app.Snapshot.Name);
|
|||
|
|||
// app.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppCreated { Name = AppName }),
|
|||
// CreateEvent(new AppContributorAssigned { ContributorId = User.Identifier, Permission = AppContributorPermission.Owner }),
|
|||
// CreateEvent(new AppLanguageAdded { Language = Language.EN }),
|
|||
// CreateEvent(new AppPatternAdded { PatternId = id1, Name = "Number", Pattern = "[0-9]" }),
|
|||
// CreateEvent(new AppPatternAdded { PatternId = id2, Name = "Numbers", Pattern = "[0-9]*" })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ChangePlan_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ChangePlan(CreateCommand(new ChangePlan { PlanId = planId }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ChangePlan_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// sut.ChangePlan(CreateCommand(new ChangePlan { PlanId = planId }));
|
|||
|
|||
// Assert.Equal(planId, sut.Snapshot.Plan.PlanId);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppPlanChanged { PlanId = planId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AssignContributor_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AssignContributor_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = AppContributorPermission.Editor }));
|
|||
|
|||
// Assert.Equal(AppContributorPermission.Editor, sut.Snapshot.Contributors[contributorId]);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppContributorAssigned { ContributorId = contributorId, Permission = AppContributorPermission.Editor })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void RemoveContributor_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.RemoveContributor(CreateCommand(new RemoveContributor { ContributorId = contributorId }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void RemoveContributor_should_create_events_and_remove_contributor()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// sut.AssignContributor(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = AppContributorPermission.Editor }));
|
|||
// sut.RemoveContributor(CreateCommand(new RemoveContributor { ContributorId = contributorId }));
|
|||
|
|||
// Assert.False(sut.Snapshot.Contributors.ContainsKey(contributorId));
|
|||
|
|||
// sut.GetUncomittedEvents().Skip(1)
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppContributorRemoved { ContributorId = contributorId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AttachClient_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.AttachClient(CreateCommand(new AttachClient { Id = clientId }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AttachClient_should_create_events()
|
|||
// {
|
|||
// var command = new AttachClient { Id = clientId };
|
|||
|
|||
// CreateApp();
|
|||
|
|||
// sut.AttachClient(CreateCommand(command));
|
|||
|
|||
// Assert.True(sut.Snapshot.Clients.ContainsKey(clientId));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppClientAttached { Id = clientId, Secret = command.Secret })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void RevokeClient_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.RevokeClient(CreateCommand(new RevokeClient { Id = "not-found" }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void RevokeClient_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
// CreateClient();
|
|||
|
|||
// sut.RevokeClient(CreateCommand(new RevokeClient { Id = clientId }));
|
|||
|
|||
// Assert.False(sut.Snapshot.Clients.ContainsKey(clientId));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppClientRevoked { Id = clientId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateClient_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.UpdateClient(CreateCommand(new UpdateClient { Id = "not-found", Name = clientNewName }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateClient_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
// CreateClient();
|
|||
|
|||
// sut.UpdateClient(CreateCommand(new UpdateClient { Id = clientId, Name = clientNewName, Permission = AppClientPermission.Developer }));
|
|||
|
|||
// Assert.Equal(clientNewName, sut.Snapshot.Clients[clientId].Name);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppClientRenamed { Id = clientId, Name = clientNewName }),
|
|||
// CreateEvent(new AppClientUpdated { Id = clientId, Permission = AppClientPermission.Developer })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AddLanguage_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.AddLanguage(CreateCommand(new AddLanguage { Language = Language.DE }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AddLanguage_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// sut.AddLanguage(CreateCommand(new AddLanguage { Language = Language.DE }));
|
|||
|
|||
// Assert.True(sut.Snapshot.LanguagesConfig.Contains(Language.DE));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppLanguageAdded { Language = Language.DE })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void RemoveLanguage_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.RemoveLanguage(CreateCommand(new RemoveLanguage { Language = Language.EN }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void RemoveLanguage_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
// CreateLanguage(Language.DE);
|
|||
|
|||
// sut.RemoveLanguage(CreateCommand(new RemoveLanguage { Language = Language.DE }));
|
|||
|
|||
// Assert.False(sut.Snapshot.LanguagesConfig.Contains(Language.DE));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppLanguageRemoved { Language = Language.DE })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateLanguage_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.UpdateLanguage(CreateCommand(new UpdateLanguage { Language = Language.EN }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateLanguage_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
// CreateLanguage(Language.DE);
|
|||
|
|||
// sut.UpdateLanguage(CreateCommand(new UpdateLanguage { Language = Language.DE, Fallback = new List<Language> { Language.EN } }));
|
|||
|
|||
// Assert.True(sut.Snapshot.LanguagesConfig.Contains(Language.DE));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppLanguageUpdated { Language = Language.DE, Fallback = new List<Language> { Language.EN } })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AddPattern_should_throw_exception_if_app_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() => sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = ".*" })));
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AddPattern_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
|
|||
// sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }));
|
|||
|
|||
// Assert.Single(sut.Snapshot.Patterns);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppPatternAdded { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DeletePattern_should_throw_exception_if_app_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.DeletePattern(CreateCommand(new DeletePattern
|
|||
// {
|
|||
// PatternId = Guid.NewGuid()
|
|||
// }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DeletePattern_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
// CreatePattern();
|
|||
|
|||
// sut.DeletePattern(CreateCommand(new DeletePattern { PatternId = patternId }));
|
|||
|
|||
// Assert.Empty(sut.Snapshot.Patterns);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppPatternDeleted { PatternId = patternId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdatePattern_should_throw_exception_if_app_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() => sut.UpdatePattern(CreateCommand(new UpdatePattern { PatternId = patternId, Name = "Any", Pattern = ".*" })));
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdatePattern_should_create_events()
|
|||
// {
|
|||
// CreateApp();
|
|||
// CreatePattern();
|
|||
|
|||
// sut.UpdatePattern(CreateCommand(new UpdatePattern { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }));
|
|||
|
|||
// Assert.Single(sut.Snapshot.Patterns);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new AppPatternUpdated { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })
|
|||
// );
|
|||
// }
|
|||
|
|||
// private void CreatePattern()
|
|||
// {
|
|||
// sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Name", Pattern = ".*" }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void CreateApp()
|
|||
// {
|
|||
// sut.Create(CreateCommand(new CreateApp { Name = AppName }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void CreateClient()
|
|||
// {
|
|||
// sut.AttachClient(CreateCommand(new AttachClient { Id = clientId }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void CreateLanguage(Language language)
|
|||
// {
|
|||
// sut.AddLanguage(CreateCommand(new AddLanguage { Language = language }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
@ -1,145 +1,145 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure.Assets; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.Tasks; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Assets |
|||
{ |
|||
public class AssetCommandMiddlewareTests : HandlerTestBase<AssetDomainObject> |
|||
{ |
|||
private readonly IAssetThumbnailGenerator assetThumbnailGenerator = A.Fake<IAssetThumbnailGenerator>(); |
|||
private readonly IAssetStore assetStore = A.Fake<IAssetStore>(); |
|||
private readonly Guid assetId = Guid.NewGuid(); |
|||
private readonly Stream stream = new MemoryStream(); |
|||
private readonly ImageInfo image = new ImageInfo(2048, 2048); |
|||
private readonly AssetDomainObject asset = new AssetDomainObject(); |
|||
private readonly AssetFile file; |
|||
private readonly AssetCommandMiddleware sut; |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return assetId; } |
|||
} |
|||
|
|||
public AssetCommandMiddlewareTests() |
|||
{ |
|||
file = new AssetFile("my-image.png", "image/png", 1024, () => stream); |
|||
|
|||
sut = new AssetCommandMiddleware(Handler, assetStore, assetThumbnailGenerator); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new CreateAsset { AssetId = assetId, File = file }); |
|||
|
|||
SetupStore(0, context.ContextId); |
|||
SetupImageInfo(); |
|||
|
|||
await TestCreate(asset, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Equal(assetId, context.Result<EntityCreatedResult<Guid>>().IdOrValue); |
|||
|
|||
AssertAssetHasBeenUploaded(0, context.ContextId); |
|||
AssertAssetImageChecked(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_update_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new UpdateAsset { AssetId = assetId, File = file }); |
|||
|
|||
SetupStore(1, context.ContextId); |
|||
SetupImageInfo(); |
|||
|
|||
CreateAsset(); |
|||
|
|||
await TestUpdate(asset, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
AssertAssetHasBeenUploaded(1, context.ContextId); |
|||
AssertAssetImageChecked(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Rename_should_update_domain_object() |
|||
{ |
|||
CreateAsset(); |
|||
|
|||
var context = CreateContextForCommand(new RenameAsset { AssetId = assetId, FileName = "my-new-image.png" }); |
|||
|
|||
await TestUpdate(asset, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Delete_should_update_domain_object() |
|||
{ |
|||
CreateAsset(); |
|||
|
|||
var command = CreateContextForCommand(new DeleteAsset { AssetId = assetId }); |
|||
|
|||
await TestUpdate(asset, async _ => |
|||
{ |
|||
await sut.HandleAsync(command); |
|||
}); |
|||
} |
|||
|
|||
private void CreateAsset() |
|||
{ |
|||
asset.Create(CreateCommand(new CreateAsset { File = file })); |
|||
} |
|||
|
|||
private void SetupImageInfo() |
|||
{ |
|||
A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream)) |
|||
.Returns(image); |
|||
} |
|||
|
|||
private void SetupStore(long version, Guid commitId) |
|||
{ |
|||
A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream)) |
|||
.Returns(TaskHelper.Done); |
|||
A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null)) |
|||
.Returns(TaskHelper.Done); |
|||
A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString())) |
|||
.Returns(TaskHelper.Done); |
|||
} |
|||
|
|||
private void AssertAssetImageChecked() |
|||
{ |
|||
A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream)) |
|||
.MustHaveHappened(); |
|||
} |
|||
|
|||
private void AssertAssetHasBeenUploaded(long version, Guid commitId) |
|||
{ |
|||
A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream)) |
|||
.MustHaveHappened(); |
|||
A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null)) |
|||
.MustHaveHappened(); |
|||
A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString())) |
|||
.MustHaveHappened(); |
|||
} |
|||
} |
|||
} |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.IO;
|
|||
//using System.Threading.Tasks;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Entities.Assets.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Infrastructure.Assets;
|
|||
//using Squidex.Infrastructure.Commands;
|
|||
//using Squidex.Infrastructure.Tasks;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Assets
|
|||
//{
|
|||
// public class AssetCommandMiddlewareTests : HandlerTestBase<AssetDomainObject>
|
|||
// {
|
|||
// private readonly IAssetThumbnailGenerator assetThumbnailGenerator = A.Fake<IAssetThumbnailGenerator>();
|
|||
// private readonly IAssetStore assetStore = A.Fake<IAssetStore>();
|
|||
// private readonly Guid assetId = Guid.NewGuid();
|
|||
// private readonly Stream stream = new MemoryStream();
|
|||
// private readonly ImageInfo image = new ImageInfo(2048, 2048);
|
|||
// private readonly AssetDomainObject asset = new AssetDomainObject();
|
|||
// private readonly AssetFile file;
|
|||
// private readonly AssetCommandMiddleware sut;
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return assetId; }
|
|||
// }
|
|||
|
|||
// public AssetCommandMiddlewareTests()
|
|||
// {
|
|||
// file = new AssetFile("my-image.png", "image/png", 1024, () => stream);
|
|||
|
|||
// sut = new AssetCommandMiddleware(Handler, assetStore, assetThumbnailGenerator);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_create_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new CreateAsset { AssetId = assetId, File = file });
|
|||
|
|||
// SetupStore(0, context.ContextId);
|
|||
// SetupImageInfo();
|
|||
|
|||
// await TestCreate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(assetId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);
|
|||
|
|||
// AssertAssetHasBeenUploaded(0, context.ContextId);
|
|||
// AssertAssetImageChecked();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Update_should_update_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new UpdateAsset { AssetId = assetId, File = file });
|
|||
|
|||
// SetupStore(1, context.ContextId);
|
|||
// SetupImageInfo();
|
|||
|
|||
// CreateAsset();
|
|||
|
|||
// await TestUpdate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// AssertAssetHasBeenUploaded(1, context.ContextId);
|
|||
// AssertAssetImageChecked();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Rename_should_update_domain_object()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// var context = CreateContextForCommand(new RenameAsset { AssetId = assetId, FileName = "my-new-image.png" });
|
|||
|
|||
// await TestUpdate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Delete_should_update_domain_object()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// var command = CreateContextForCommand(new DeleteAsset { AssetId = assetId });
|
|||
|
|||
// await TestUpdate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(command);
|
|||
// });
|
|||
// }
|
|||
|
|||
// private void CreateAsset()
|
|||
// {
|
|||
// asset.Create(CreateCommand(new CreateAsset { File = file }));
|
|||
// }
|
|||
|
|||
// private void SetupImageInfo()
|
|||
// {
|
|||
// A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream))
|
|||
// .Returns(image);
|
|||
// }
|
|||
|
|||
// private void SetupStore(long version, Guid commitId)
|
|||
// {
|
|||
// A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream))
|
|||
// .Returns(TaskHelper.Done);
|
|||
// A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null))
|
|||
// .Returns(TaskHelper.Done);
|
|||
// A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString()))
|
|||
// .Returns(TaskHelper.Done);
|
|||
// }
|
|||
|
|||
// private void AssertAssetImageChecked()
|
|||
// {
|
|||
// A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream))
|
|||
// .MustHaveHappened();
|
|||
// }
|
|||
|
|||
// private void AssertAssetHasBeenUploaded(long version, Guid commitId)
|
|||
// {
|
|||
// A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream))
|
|||
// .MustHaveHappened();
|
|||
// A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null))
|
|||
// .MustHaveHappened();
|
|||
// A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString()))
|
|||
// .MustHaveHappened();
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
@ -1,220 +1,220 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using FakeItEasy; |
|||
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Assets; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Assets; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Assets |
|||
{ |
|||
public class AssetDomainObjectTests : HandlerTestBase<AssetDomainObject> |
|||
{ |
|||
private readonly ImageInfo image = new ImageInfo(2048, 2048); |
|||
private readonly Guid assetId = Guid.NewGuid(); |
|||
private readonly AssetFile file = new AssetFile("my-image.png", "image/png", 1024, () => new MemoryStream()); |
|||
private readonly AssetDomainObject sut = new AssetDomainObject(); |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return assetId; } |
|||
} |
|||
|
|||
public AssetDomainObjectTests() |
|||
{ |
|||
sut.ActivateAsync(Id, A.Fake<IStore<Guid>>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_throw_exception_if_created() |
|||
{ |
|||
CreateAsset(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Create(CreateAssetCommand(new CreateAsset { File = file })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_create_events() |
|||
{ |
|||
sut.Create(CreateAssetCommand(new CreateAsset { File = file, ImageInfo = image })); |
|||
|
|||
Assert.Equal(0, sut.Snapshot.FileVersion); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetCreated |
|||
{ |
|||
IsImage = true, |
|||
FileName = file.FileName, |
|||
FileSize = file.FileSize, |
|||
FileVersion = 0, |
|||
MimeType = file.MimeType, |
|||
PixelWidth = image.PixelWidth, |
|||
PixelHeight = image.PixelHeight |
|||
}) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateAssetCommand(new UpdateAsset { File = file })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_throw_exception_if_asset_is_deleted() |
|||
{ |
|||
CreateAsset(); |
|||
DeleteAsset(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateAssetCommand(new UpdateAsset())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_create_events() |
|||
{ |
|||
CreateAsset(); |
|||
|
|||
sut.Update(CreateAssetCommand(new UpdateAsset { File = file, ImageInfo = image })); |
|||
|
|||
Assert.Equal(1, sut.Snapshot.FileVersion); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetUpdated |
|||
{ |
|||
IsImage = true, |
|||
FileSize = file.FileSize, |
|||
FileVersion = 1, |
|||
MimeType = file.MimeType, |
|||
PixelWidth = image.PixelWidth, |
|||
PixelHeight = image.PixelHeight |
|||
}) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Rename_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Rename(CreateAssetCommand(new RenameAsset { FileName = "new-file.png" })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Rename_should_throw_exception_if_asset_is_deleted() |
|||
{ |
|||
CreateAsset(); |
|||
DeleteAsset(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateAssetCommand(new UpdateAsset())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Rename_should_create_events() |
|||
{ |
|||
CreateAsset(); |
|||
|
|||
sut.Rename(CreateAssetCommand(new RenameAsset { FileName = "my-new-image.png" })); |
|||
|
|||
Assert.Equal("my-new-image.png", sut.Snapshot.FileName); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetRenamed { FileName = "my-new-image.png" }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Delete(CreateAssetCommand(new DeleteAsset())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_throw_exception_if_already_deleted() |
|||
{ |
|||
CreateAsset(); |
|||
DeleteAsset(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Delete(CreateAssetCommand(new DeleteAsset())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_create_events_with_total_file_size() |
|||
{ |
|||
CreateAsset(); |
|||
UpdateAsset(); |
|||
|
|||
sut.Delete(CreateAssetCommand(new DeleteAsset())); |
|||
|
|||
Assert.True(sut.Snapshot.IsDeleted); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetDeleted { DeletedSize = 2048 }) |
|||
); |
|||
} |
|||
|
|||
private void CreateAsset() |
|||
{ |
|||
sut.Create(CreateAssetCommand(new CreateAsset { File = file })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void UpdateAsset() |
|||
{ |
|||
sut.Update(CreateAssetCommand(new UpdateAsset { File = file })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void DeleteAsset() |
|||
{ |
|||
sut.Delete(CreateAssetCommand(new DeleteAsset())); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
protected T CreateAssetEvent<T>(T @event) where T : AssetEvent |
|||
{ |
|||
@event.AssetId = assetId; |
|||
|
|||
return CreateEvent(@event); |
|||
} |
|||
|
|||
protected T CreateAssetCommand<T>(T command) where T : AssetCommand |
|||
{ |
|||
command.AssetId = assetId; |
|||
|
|||
return CreateCommand(command); |
|||
} |
|||
} |
|||
} |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.IO;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Entities.Assets.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Domain.Apps.Events.Assets;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.Assets;
|
|||
//using Squidex.Infrastructure.States;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Assets
|
|||
//{
|
|||
// public class AssetDomainObjectTests : HandlerTestBase<AssetDomainObject>
|
|||
// {
|
|||
// private readonly ImageInfo image = new ImageInfo(2048, 2048);
|
|||
// private readonly Guid assetId = Guid.NewGuid();
|
|||
// private readonly AssetFile file = new AssetFile("my-image.png", "image/png", 1024, () => new MemoryStream());
|
|||
// private readonly AssetDomainObject sut = new AssetDomainObject();
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return assetId; }
|
|||
// }
|
|||
|
|||
// public AssetDomainObjectTests()
|
|||
// {
|
|||
// sut.ActivateAsync(Id, A.Fake<IStore<Guid>>());
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_throw_exception_if_created()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Create(CreateAssetCommand(new CreateAsset { File = file }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_create_events()
|
|||
// {
|
|||
// sut.Create(CreateAssetCommand(new CreateAsset { File = file, ImageInfo = image }));
|
|||
|
|||
// Assert.Equal(0, sut.Snapshot.FileVersion);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetCreated
|
|||
// {
|
|||
// IsImage = true,
|
|||
// FileName = file.FileName,
|
|||
// FileSize = file.FileSize,
|
|||
// FileVersion = 0,
|
|||
// MimeType = file.MimeType,
|
|||
// PixelWidth = image.PixelWidth,
|
|||
// PixelHeight = image.PixelHeight
|
|||
// })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset { File = file }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_asset_is_deleted()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// DeleteAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_create_events()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset { File = file, ImageInfo = image }));
|
|||
|
|||
// Assert.Equal(1, sut.Snapshot.FileVersion);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetUpdated
|
|||
// {
|
|||
// IsImage = true,
|
|||
// FileSize = file.FileSize,
|
|||
// FileVersion = 1,
|
|||
// MimeType = file.MimeType,
|
|||
// PixelWidth = image.PixelWidth,
|
|||
// PixelHeight = image.PixelHeight
|
|||
// })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Rename_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Rename(CreateAssetCommand(new RenameAsset { FileName = "new-file.png" }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Rename_should_throw_exception_if_asset_is_deleted()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// DeleteAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Rename_should_create_events()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// sut.Rename(CreateAssetCommand(new RenameAsset { FileName = "my-new-image.png" }));
|
|||
|
|||
// Assert.Equal("my-new-image.png", sut.Snapshot.FileName);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetRenamed { FileName = "my-new-image.png" })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_already_deleted()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// DeleteAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_create_events_with_total_file_size()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// UpdateAsset();
|
|||
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
|
|||
// Assert.True(sut.Snapshot.IsDeleted);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetDeleted { DeletedSize = 2048 })
|
|||
// );
|
|||
// }
|
|||
|
|||
// private void CreateAsset()
|
|||
// {
|
|||
// sut.Create(CreateAssetCommand(new CreateAsset { File = file }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void UpdateAsset()
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset { File = file }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void DeleteAsset()
|
|||
// {
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// protected T CreateAssetEvent<T>(T @event) where T : AssetEvent
|
|||
// {
|
|||
// @event.AssetId = assetId;
|
|||
|
|||
// return CreateEvent(@event);
|
|||
// }
|
|||
|
|||
// protected T CreateAssetCommand<T>(T command) where T : AssetCommand
|
|||
// {
|
|||
// command.AssetId = assetId;
|
|||
|
|||
// return CreateCommand(command);
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
@ -1,264 +1,264 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using NodaTime; |
|||
using Squidex.Domain.Apps.Core; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Domain.Apps.Core.Scripting; |
|||
using Squidex.Domain.Apps.Entities.Apps; |
|||
using Squidex.Domain.Apps.Entities.Assets.Repositories; |
|||
using Squidex.Domain.Apps.Entities.Contents.Commands; |
|||
using Squidex.Domain.Apps.Entities.Contents.Repositories; |
|||
using Squidex.Domain.Apps.Entities.Schemas; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents |
|||
{ |
|||
public class ContentCommandMiddlewareTests : HandlerTestBase<ContentDomainObject> |
|||
{ |
|||
private readonly ISchemaEntity schema = A.Fake<ISchemaEntity>(); |
|||
private readonly IScriptEngine scriptEngine = A.Fake<IScriptEngine>(); |
|||
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|||
private readonly IAppEntity app = A.Fake<IAppEntity>(); |
|||
private readonly ClaimsPrincipal user = new ClaimsPrincipal(); |
|||
private readonly LanguagesConfig languagesConfig = LanguagesConfig.Build(Language.DE); |
|||
private readonly Guid contentId = Guid.NewGuid(); |
|||
private readonly ContentDomainObject content = new ContentDomainObject(); |
|||
private readonly ContentCommandMiddleware sut; |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return contentId; } |
|||
} |
|||
|
|||
private readonly NamedContentData invalidData = |
|||
new NamedContentData() |
|||
.AddField("my-field1", new ContentFieldData() |
|||
.AddValue(null)) |
|||
.AddField("my-field2", new ContentFieldData() |
|||
.AddValue(1)); |
|||
private readonly NamedContentData data = |
|||
new NamedContentData() |
|||
.AddField("my-field1", new ContentFieldData() |
|||
.AddValue(1)) |
|||
.AddField("my-field2", new ContentFieldData() |
|||
.AddValue(1)); |
|||
private readonly NamedContentData patch = |
|||
new NamedContentData() |
|||
.AddField("my-field1", new ContentFieldData() |
|||
.AddValue(1)); |
|||
|
|||
public ContentCommandMiddlewareTests() |
|||
{ |
|||
var schemaDef = |
|||
new Schema("my-schema") |
|||
.AddField(new NumberField(1, "my-field1", Partitioning.Invariant, |
|||
new NumberFieldProperties { IsRequired = true })) |
|||
.AddField(new NumberField(2, "my-field2", Partitioning.Invariant, |
|||
new NumberFieldProperties { IsRequired = false })); |
|||
|
|||
sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy<IAssetRepository>(), scriptEngine, A.Dummy<IContentRepository>()); |
|||
|
|||
A.CallTo(() => app.LanguagesConfig).Returns(languagesConfig); |
|||
|
|||
A.CallTo(() => appProvider.GetAppAsync(AppName)).Returns(app); |
|||
|
|||
A.CallTo(() => schema.SchemaDef).Returns(schemaDef); |
|||
A.CallTo(() => schema.ScriptCreate).Returns("<create-script>"); |
|||
A.CallTo(() => schema.ScriptChange).Returns("<change-script>"); |
|||
A.CallTo(() => schema.ScriptUpdate).Returns("<update-script>"); |
|||
A.CallTo(() => schema.ScriptDelete).Returns("<delete-script>"); |
|||
|
|||
A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId)).Returns((app, schema)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_throw_exception_if_data_is_not_valid() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(invalidData); |
|||
|
|||
var context = CreateContextForCommand(new CreateContent { ContentId = contentId, Data = invalidData, User = user }); |
|||
|
|||
await TestCreate(content, async _ => |
|||
{ |
|||
await Assert.ThrowsAsync<ValidationException>(() => sut.HandleAsync(context)); |
|||
}, false); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_content() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(data); |
|||
|
|||
var context = CreateContextForCommand(new CreateContent { ContentId = contentId, Data = data, User = user }); |
|||
|
|||
await TestCreate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Equal(data, context.Result<EntityCreatedResult<NamedContentData>>().IdOrValue); |
|||
|
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<create-script>")).MustHaveHappened(); |
|||
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustNotHaveHappened(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_also_invoke_publish_script_when_publishing() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(data); |
|||
|
|||
var context = CreateContextForCommand(new CreateContent { ContentId = contentId, Data = data, User = user, Publish = true }); |
|||
|
|||
await TestCreate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Equal(data, context.Result<EntityCreatedResult<NamedContentData>>().IdOrValue); |
|||
|
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<create-script>")).MustHaveHappened(); |
|||
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustHaveHappened(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_throw_exception_if_data_is_not_valid() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(invalidData); |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.Security.Claims;
|
|||
//using System.Threading.Tasks;
|
|||
//using FakeItEasy;
|
|||
//using NodaTime;
|
|||
//using Squidex.Domain.Apps.Core;
|
|||
//using Squidex.Domain.Apps.Core.Apps;
|
|||
//using Squidex.Domain.Apps.Core.Contents;
|
|||
//using Squidex.Domain.Apps.Core.Schemas;
|
|||
//using Squidex.Domain.Apps.Core.Scripting;
|
|||
//using Squidex.Domain.Apps.Entities.Apps;
|
|||
//using Squidex.Domain.Apps.Entities.Assets.Repositories;
|
|||
//using Squidex.Domain.Apps.Entities.Contents.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.Contents.Repositories;
|
|||
//using Squidex.Domain.Apps.Entities.Schemas;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.Commands;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Contents
|
|||
//{
|
|||
// public class ContentCommandMiddlewareTests : HandlerTestBase<ContentDomainObject>
|
|||
// {
|
|||
// private readonly ISchemaEntity schema = A.Fake<ISchemaEntity>();
|
|||
// private readonly IScriptEngine scriptEngine = A.Fake<IScriptEngine>();
|
|||
// private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
|
|||
// private readonly IAppEntity app = A.Fake<IAppEntity>();
|
|||
// private readonly ClaimsPrincipal user = new ClaimsPrincipal();
|
|||
// private readonly LanguagesConfig languagesConfig = LanguagesConfig.Build(Language.DE);
|
|||
// private readonly Guid contentId = Guid.NewGuid();
|
|||
// private readonly ContentDomainObject content = new ContentDomainObject();
|
|||
// private readonly ContentCommandMiddleware sut;
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return contentId; }
|
|||
// }
|
|||
|
|||
// private readonly NamedContentData invalidData =
|
|||
// new NamedContentData()
|
|||
// .AddField("my-field1", new ContentFieldData()
|
|||
// .AddValue(null))
|
|||
// .AddField("my-field2", new ContentFieldData()
|
|||
// .AddValue(1));
|
|||
// private readonly NamedContentData data =
|
|||
// new NamedContentData()
|
|||
// .AddField("my-field1", new ContentFieldData()
|
|||
// .AddValue(1))
|
|||
// .AddField("my-field2", new ContentFieldData()
|
|||
// .AddValue(1));
|
|||
// private readonly NamedContentData patch =
|
|||
// new NamedContentData()
|
|||
// .AddField("my-field1", new ContentFieldData()
|
|||
// .AddValue(1));
|
|||
|
|||
// public ContentCommandMiddlewareTests()
|
|||
// {
|
|||
// var schemaDef =
|
|||
// new Schema("my-schema")
|
|||
// .AddField(new NumberField(1, "my-field1", Partitioning.Invariant,
|
|||
// new NumberFieldProperties { IsRequired = true }))
|
|||
// .AddField(new NumberField(2, "my-field2", Partitioning.Invariant,
|
|||
// new NumberFieldProperties { IsRequired = false }));
|
|||
|
|||
// sut = new ContentCommandMiddleware(Handler, appProvider, A.Dummy<IAssetRepository>(), scriptEngine, A.Dummy<IContentRepository>());
|
|||
|
|||
// A.CallTo(() => app.LanguagesConfig).Returns(languagesConfig);
|
|||
|
|||
// A.CallTo(() => appProvider.GetAppAsync(AppName)).Returns(app);
|
|||
|
|||
// A.CallTo(() => schema.SchemaDef).Returns(schemaDef);
|
|||
// A.CallTo(() => schema.ScriptCreate).Returns("<create-script>");
|
|||
// A.CallTo(() => schema.ScriptChange).Returns("<change-script>");
|
|||
// A.CallTo(() => schema.ScriptUpdate).Returns("<update-script>");
|
|||
// A.CallTo(() => schema.ScriptDelete).Returns("<delete-script>");
|
|||
|
|||
// A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId)).Returns((app, schema));
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_throw_exception_if_data_is_not_valid()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(invalidData);
|
|||
|
|||
// var context = CreateContextForCommand(new CreateContent { ContentId = contentId, Data = invalidData, User = user });
|
|||
|
|||
// await TestCreate(content, async _ =>
|
|||
// {
|
|||
// await Assert.ThrowsAsync<ValidationException>(() => sut.HandleAsync(context));
|
|||
// }, false);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_create_content()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(data);
|
|||
|
|||
// var context = CreateContextForCommand(new CreateContent { ContentId = contentId, Data = data, User = user });
|
|||
|
|||
// await TestCreate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(data, context.Result<EntityCreatedResult<NamedContentData>>().IdOrValue);
|
|||
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<create-script>")).MustHaveHappened();
|
|||
// A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustNotHaveHappened();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_also_invoke_publish_script_when_publishing()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(data);
|
|||
|
|||
// var context = CreateContextForCommand(new CreateContent { ContentId = contentId, Data = data, User = user, Publish = true });
|
|||
|
|||
// await TestCreate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(data, context.Result<EntityCreatedResult<NamedContentData>>().IdOrValue);
|
|||
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<create-script>")).MustHaveHappened();
|
|||
// A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustHaveHappened();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Update_should_throw_exception_if_data_is_not_valid()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(invalidData);
|
|||
|
|||
CreateContent(); |
|||
|
|||
var context = CreateContextForCommand(new UpdateContent { ContentId = contentId, Data = invalidData, User = user }); |
|||
// CreateContent();
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateContent { ContentId = contentId, Data = invalidData, User = user });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await Assert.ThrowsAsync<ValidationException>(() => sut.HandleAsync(context)); |
|||
}, false); |
|||
} |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await Assert.ThrowsAsync<ValidationException>(() => sut.HandleAsync(context));
|
|||
// }, false);
|
|||
// }
|
|||
|
|||
[Fact] |
|||
public async Task Update_should_update_domain_object() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(data); |
|||
// [Fact]
|
|||
// public async Task Update_should_update_domain_object()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(data);
|
|||
|
|||
CreateContent(); |
|||
// CreateContent();
|
|||
|
|||
var context = CreateContextForCommand(new UpdateContent { ContentId = contentId, Data = data, User = user }); |
|||
// var context = CreateContextForCommand(new UpdateContent { ContentId = contentId, Data = data, User = user });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
Assert.Equal(data, context.Result<ContentDataChangedResult>().Data); |
|||
// Assert.Equal(data, context.Result<ContentDataChangedResult>().Data);
|
|||
|
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<update-script>")).MustHaveHappened(); |
|||
} |
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<update-script>")).MustHaveHappened();
|
|||
// }
|
|||
|
|||
[Fact] |
|||
public async Task Patch_should_throw_exception_if_data_is_not_valid() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(invalidData); |
|||
// [Fact]
|
|||
// public async Task Patch_should_throw_exception_if_data_is_not_valid()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(invalidData);
|
|||
|
|||
CreateContent(); |
|||
// CreateContent();
|
|||
|
|||
var context = CreateContextForCommand(new PatchContent { ContentId = contentId, Data = invalidData, User = user }); |
|||
// var context = CreateContextForCommand(new PatchContent { ContentId = contentId, Data = invalidData, User = user });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await Assert.ThrowsAsync<ValidationException>(() => sut.HandleAsync(context)); |
|||
}, false); |
|||
} |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await Assert.ThrowsAsync<ValidationException>(() => sut.HandleAsync(context));
|
|||
// }, false);
|
|||
// }
|
|||
|
|||
[Fact] |
|||
public async Task Patch_should_update_domain_object() |
|||
{ |
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|||
.Returns(data); |
|||
// [Fact]
|
|||
// public async Task Patch_should_update_domain_object()
|
|||
// {
|
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored))
|
|||
// .Returns(data);
|
|||
|
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)).Returns(patch); |
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)).Returns(patch);
|
|||
|
|||
CreateContent(); |
|||
// CreateContent();
|
|||
|
|||
var context = CreateContextForCommand(new PatchContent { ContentId = contentId, Data = patch, User = user }); |
|||
// var context = CreateContextForCommand(new PatchContent { ContentId = contentId, Data = patch, User = user });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
Assert.NotNull(context.Result<ContentDataChangedResult>().Data); |
|||
// Assert.NotNull(context.Result<ContentDataChangedResult>().Data);
|
|||
|
|||
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<update-script>")).MustHaveHappened(); |
|||
} |
|||
// A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<update-script>")).MustHaveHappened();
|
|||
// }
|
|||
|
|||
[Fact] |
|||
public async Task ChangeStatus_should_publish_domain_object() |
|||
{ |
|||
CreateContent(); |
|||
// [Fact]
|
|||
// public async Task ChangeStatus_should_publish_domain_object()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
var context = CreateContextForCommand(new ChangeContentStatus { ContentId = contentId, User = user, Status = Status.Published }); |
|||
// var context = CreateContextForCommand(new ChangeContentStatus { ContentId = contentId, User = user, Status = Status.Published });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustHaveHappened(); |
|||
} |
|||
// A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustHaveHappened();
|
|||
// }
|
|||
|
|||
[Fact] |
|||
public async Task ChangeStatus_should_not_invoke_scripts_when_scheduled() |
|||
{ |
|||
CreateContent(); |
|||
// [Fact]
|
|||
// public async Task ChangeStatus_should_not_invoke_scripts_when_scheduled()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
var context = CreateContextForCommand(new ChangeContentStatus { ContentId = contentId, User = user, Status = Status.Published, DueTime = Instant.MaxValue }); |
|||
// var context = CreateContextForCommand(new ChangeContentStatus { ContentId = contentId, User = user, Status = Status.Published, DueTime = Instant.MaxValue });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustNotHaveHappened(); |
|||
} |
|||
// A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")).MustNotHaveHappened();
|
|||
// }
|
|||
|
|||
[Fact] |
|||
public async Task Delete_should_update_domain_object() |
|||
{ |
|||
CreateContent(); |
|||
// [Fact]
|
|||
// public async Task Delete_should_update_domain_object()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
var command = CreateContextForCommand(new DeleteContent { ContentId = contentId, User = user }); |
|||
// var command = CreateContextForCommand(new DeleteContent { ContentId = contentId, User = user });
|
|||
|
|||
await TestUpdate(content, async _ => |
|||
{ |
|||
await sut.HandleAsync(command); |
|||
}); |
|||
// await TestUpdate(content, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(command);
|
|||
// });
|
|||
|
|||
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<delete-script>")).MustHaveHappened(); |
|||
} |
|||
// A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<delete-script>")).MustHaveHappened();
|
|||
// }
|
|||
|
|||
private void CreateContent() |
|||
{ |
|||
content.Create(CreateCommand(new CreateContent { Data = data })); |
|||
} |
|||
} |
|||
} |
|||
// private void CreateContent()
|
|||
// {
|
|||
// content.Create(CreateCommand(new CreateContent { Data = data }));
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
@ -1,304 +1,304 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using FakeItEasy; |
|||
using FluentAssertions; |
|||
using NodaTime; |
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Squidex.Domain.Apps.Entities.Contents.Commands; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Contents; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents |
|||
{ |
|||
public class ContentDomainObjectTests : HandlerTestBase<ContentDomainObject> |
|||
{ |
|||
private readonly NamedContentData data = |
|||
new NamedContentData() |
|||
.AddField("field1", |
|||
new ContentFieldData() |
|||
.AddValue("iv", 1)); |
|||
private readonly NamedContentData otherData = |
|||
new NamedContentData() |
|||
.AddField("field2", |
|||
new ContentFieldData() |
|||
.AddValue("iv", 2)); |
|||
private readonly NamedContentData patched; |
|||
private readonly Guid contentId = Guid.NewGuid(); |
|||
private readonly ContentDomainObject sut = new ContentDomainObject(); |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return contentId; } |
|||
} |
|||
|
|||
public ContentDomainObjectTests() |
|||
{ |
|||
patched = otherData.MergeInto(data); |
|||
|
|||
sut.ActivateAsync(Id, A.Fake<IStore<Guid>>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_throw_exception_if_created() |
|||
{ |
|||
sut.Create(CreateCommand(new CreateContent { Data = data })); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Create(CreateContentCommand(new CreateContent { Data = data })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_create_events() |
|||
{ |
|||
sut.Create(CreateContentCommand(new CreateContent { Data = data })); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentCreated { Data = data }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_also_publish_if_set_to_true() |
|||
{ |
|||
sut.Create(CreateContentCommand(new CreateContent { Data = data, Publish = true })); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentCreated { Data = data }), |
|||
CreateContentEvent(new ContentStatusChanged { Status = Status.Published }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateContentCommand(new UpdateContent { Data = data })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_throw_exception_if_content_is_deleted() |
|||
{ |
|||
CreateContent(); |
|||
DeleteContent(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateContentCommand(new UpdateContent())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_create_events() |
|||
{ |
|||
CreateContent(); |
|||
|
|||
sut.Update(CreateContentCommand(new UpdateContent { Data = otherData })); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentUpdated { Data = otherData }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_not_create_event_for_same_data() |
|||
{ |
|||
CreateContent(); |
|||
UpdateContent(); |
|||
|
|||
sut.Update(CreateContentCommand(new UpdateContent { Data = data })); |
|||
|
|||
sut.GetUncomittedEvents().Should().BeEmpty(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Patch_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Patch(CreateContentCommand(new PatchContent { Data = data })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Patch_should_throw_exception_if_content_is_deleted() |
|||
{ |
|||
CreateContent(); |
|||
DeleteContent(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Patch(CreateContentCommand(new PatchContent())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Patch_should_create_events() |
|||
{ |
|||
CreateContent(); |
|||
UpdateContent(); |
|||
|
|||
sut.Patch(CreateContentCommand(new PatchContent { Data = otherData })); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentUpdated { Data = patched }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Patch_should_not_create_event_for_same_data() |
|||
{ |
|||
CreateContent(); |
|||
UpdateContent(); |
|||
|
|||
sut.Patch(CreateContentCommand(new PatchContent { Data = data })); |
|||
|
|||
sut.GetUncomittedEvents().Should().BeEmpty(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ChangeStatus_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ChangeStatus_should_throw_exception_if_content_is_deleted() |
|||
{ |
|||
CreateContent(); |
|||
DeleteContent(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ChangeStatus_should_refresh_properties_and_create_events() |
|||
{ |
|||
CreateContent(); |
|||
|
|||
sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus { Status = Status.Published })); |
|||
|
|||
Assert.Equal(Status.Published, sut.Snapshot.Status); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentStatusChanged { Status = Status.Published }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ChangeStatus_should_refresh_properties_and_create_scheduled_events_when_command_has_due_time() |
|||
{ |
|||
CreateContent(); |
|||
|
|||
var dueTime = Instant.MaxValue; |
|||
|
|||
sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus { Status = Status.Published, DueTime = dueTime })); |
|||
|
|||
Assert.Equal(Status.Draft, sut.Snapshot.Status); |
|||
Assert.Equal(Status.Published, sut.Snapshot.ScheduledTo); |
|||
Assert.Equal(dueTime, sut.Snapshot.ScheduledAt); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentStatusScheduled { Status = Status.Published, DueTime = dueTime }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Delete(CreateContentCommand(new DeleteContent())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_throw_exception_if_already_deleted() |
|||
{ |
|||
CreateContent(); |
|||
DeleteContent(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Delete(CreateContentCommand(new DeleteContent())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_update_properties_and_create_events() |
|||
{ |
|||
CreateContent(); |
|||
|
|||
sut.Delete(CreateContentCommand(new DeleteContent())); |
|||
|
|||
Assert.True(sut.Snapshot.IsDeleted); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateContentEvent(new ContentDeleted()) |
|||
); |
|||
} |
|||
|
|||
private void CreateContent() |
|||
{ |
|||
sut.Create(CreateContentCommand(new CreateContent { Data = data })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void UpdateContent() |
|||
{ |
|||
sut.Update(CreateContentCommand(new UpdateContent { Data = data })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void ChangeStatus(Status status) |
|||
{ |
|||
sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus { Status = status })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void DeleteContent() |
|||
{ |
|||
sut.Delete(CreateContentCommand(new DeleteContent())); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
protected T CreateContentEvent<T>(T @event) where T : ContentEvent |
|||
{ |
|||
@event.ContentId = contentId; |
|||
|
|||
return CreateEvent(@event); |
|||
} |
|||
|
|||
protected T CreateContentCommand<T>(T command) where T : ContentCommand |
|||
{ |
|||
command.ContentId = contentId; |
|||
|
|||
return CreateCommand(command); |
|||
} |
|||
} |
|||
} |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using FakeItEasy;
|
|||
//using FluentAssertions;
|
|||
//using NodaTime;
|
|||
//using Squidex.Domain.Apps.Core.Contents;
|
|||
//using Squidex.Domain.Apps.Entities.Contents.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Domain.Apps.Events.Contents;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.States;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Contents
|
|||
//{
|
|||
// public class ContentDomainObjectTests : HandlerTestBase<ContentDomainObject>
|
|||
// {
|
|||
// private readonly NamedContentData data =
|
|||
// new NamedContentData()
|
|||
// .AddField("field1",
|
|||
// new ContentFieldData()
|
|||
// .AddValue("iv", 1));
|
|||
// private readonly NamedContentData otherData =
|
|||
// new NamedContentData()
|
|||
// .AddField("field2",
|
|||
// new ContentFieldData()
|
|||
// .AddValue("iv", 2));
|
|||
// private readonly NamedContentData patched;
|
|||
// private readonly Guid contentId = Guid.NewGuid();
|
|||
// private readonly ContentDomainObject sut = new ContentDomainObject();
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return contentId; }
|
|||
// }
|
|||
|
|||
// public ContentDomainObjectTests()
|
|||
// {
|
|||
// patched = otherData.MergeInto(data);
|
|||
|
|||
// sut.ActivateAsync(Id, A.Fake<IStore<Guid>>());
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_throw_exception_if_created()
|
|||
// {
|
|||
// sut.Create(CreateCommand(new CreateContent { Data = data }));
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Create(CreateContentCommand(new CreateContent { Data = data }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_create_events()
|
|||
// {
|
|||
// sut.Create(CreateContentCommand(new CreateContent { Data = data }));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentCreated { Data = data })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_also_publish_if_set_to_true()
|
|||
// {
|
|||
// sut.Create(CreateContentCommand(new CreateContent { Data = data, Publish = true }));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentCreated { Data = data }),
|
|||
// CreateContentEvent(new ContentStatusChanged { Status = Status.Published })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateContentCommand(new UpdateContent { Data = data }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_content_is_deleted()
|
|||
// {
|
|||
// CreateContent();
|
|||
// DeleteContent();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateContentCommand(new UpdateContent()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_create_events()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
// sut.Update(CreateContentCommand(new UpdateContent { Data = otherData }));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentUpdated { Data = otherData })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_not_create_event_for_same_data()
|
|||
// {
|
|||
// CreateContent();
|
|||
// UpdateContent();
|
|||
|
|||
// sut.Update(CreateContentCommand(new UpdateContent { Data = data }));
|
|||
|
|||
// sut.GetUncomittedEvents().Should().BeEmpty();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Patch_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Patch(CreateContentCommand(new PatchContent { Data = data }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Patch_should_throw_exception_if_content_is_deleted()
|
|||
// {
|
|||
// CreateContent();
|
|||
// DeleteContent();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Patch(CreateContentCommand(new PatchContent()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Patch_should_create_events()
|
|||
// {
|
|||
// CreateContent();
|
|||
// UpdateContent();
|
|||
|
|||
// sut.Patch(CreateContentCommand(new PatchContent { Data = otherData }));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentUpdated { Data = patched })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Patch_should_not_create_event_for_same_data()
|
|||
// {
|
|||
// CreateContent();
|
|||
// UpdateContent();
|
|||
|
|||
// sut.Patch(CreateContentCommand(new PatchContent { Data = data }));
|
|||
|
|||
// sut.GetUncomittedEvents().Should().BeEmpty();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ChangeStatus_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ChangeStatus_should_throw_exception_if_content_is_deleted()
|
|||
// {
|
|||
// CreateContent();
|
|||
// DeleteContent();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ChangeStatus_should_refresh_properties_and_create_events()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
// sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus { Status = Status.Published }));
|
|||
|
|||
// Assert.Equal(Status.Published, sut.Snapshot.Status);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentStatusChanged { Status = Status.Published })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ChangeStatus_should_refresh_properties_and_create_scheduled_events_when_command_has_due_time()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
// var dueTime = Instant.MaxValue;
|
|||
|
|||
// sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus { Status = Status.Published, DueTime = dueTime }));
|
|||
|
|||
// Assert.Equal(Status.Draft, sut.Snapshot.Status);
|
|||
// Assert.Equal(Status.Published, sut.Snapshot.ScheduledTo);
|
|||
// Assert.Equal(dueTime, sut.Snapshot.ScheduledAt);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentStatusScheduled { Status = Status.Published, DueTime = dueTime })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateContentCommand(new DeleteContent()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_already_deleted()
|
|||
// {
|
|||
// CreateContent();
|
|||
// DeleteContent();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateContentCommand(new DeleteContent()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_update_properties_and_create_events()
|
|||
// {
|
|||
// CreateContent();
|
|||
|
|||
// sut.Delete(CreateContentCommand(new DeleteContent()));
|
|||
|
|||
// Assert.True(sut.Snapshot.IsDeleted);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateContentEvent(new ContentDeleted())
|
|||
// );
|
|||
// }
|
|||
|
|||
// private void CreateContent()
|
|||
// {
|
|||
// sut.Create(CreateContentCommand(new CreateContent { Data = data }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void UpdateContent()
|
|||
// {
|
|||
// sut.Update(CreateContentCommand(new UpdateContent { Data = data }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void ChangeStatus(Status status)
|
|||
// {
|
|||
// sut.ChangeStatus(CreateContentCommand(new ChangeContentStatus { Status = status }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void DeleteContent()
|
|||
// {
|
|||
// sut.Delete(CreateContentCommand(new DeleteContent()));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// protected T CreateContentEvent<T>(T @event) where T : ContentEvent
|
|||
// {
|
|||
// @event.ContentId = contentId;
|
|||
|
|||
// return CreateEvent(@event);
|
|||
// }
|
|||
|
|||
// protected T CreateContentCommand<T>(T command) where T : ContentCommand
|
|||
// {
|
|||
// command.ContentId = contentId;
|
|||
|
|||
// return CreateCommand(command);
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
|
|||
@ -1,118 +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 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.Entities.Rules.Commands; |
|||
using Squidex.Domain.Apps.Entities.Schemas; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Rules |
|||
{ |
|||
public class RuleCommandMiddlewareTests : HandlerTestBase<RuleDomainObject> |
|||
{ |
|||
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|||
private readonly RuleDomainObject rule = new RuleDomainObject(); |
|||
private readonly RuleTrigger ruleTrigger = new ContentChangedTrigger(); |
|||
private readonly RuleAction ruleAction = new WebhookAction { Url = new Uri("https://squidex.io") }; |
|||
private readonly Guid ruleId = Guid.NewGuid(); |
|||
private readonly RuleCommandMiddleware sut; |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return ruleId; } |
|||
} |
|||
|
|||
public RuleCommandMiddlewareTests() |
|||
{ |
|||
A.CallTo(() => appProvider.GetSchemaAsync(A<Guid>.Ignored, A<Guid>.Ignored, false)) |
|||
.Returns(A.Fake<ISchemaEntity>()); |
|||
|
|||
sut = new RuleCommandMiddleware(Handler, appProvider); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new CreateRule { Trigger = ruleTrigger, Action = ruleAction }); |
|||
|
|||
await TestCreate(rule, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_update_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new UpdateRule { Trigger = ruleTrigger, Action = ruleAction }); |
|||
|
|||
CreateRule(); |
|||
|
|||
await TestUpdate(rule, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Enable_should_update_domain_object() |
|||
{ |
|||
CreateRule(); |
|||
DisableRule(); |
|||
|
|||
var command = CreateContextForCommand(new EnableRule { RuleId = ruleId }); |
|||
|
|||
await TestUpdate(rule, async _ => |
|||
{ |
|||
await sut.HandleAsync(command); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Disable_should_update_domain_object() |
|||
{ |
|||
CreateRule(); |
|||
|
|||
var command = CreateContextForCommand(new DisableRule { RuleId = ruleId }); |
|||
|
|||
await TestUpdate(rule, async _ => |
|||
{ |
|||
await sut.HandleAsync(command); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Delete_should_update_domain_object() |
|||
{ |
|||
CreateRule(); |
|||
|
|||
var command = CreateContextForCommand(new DeleteRule { RuleId = ruleId }); |
|||
|
|||
await TestUpdate(rule, async _ => |
|||
{ |
|||
await sut.HandleAsync(command); |
|||
}); |
|||
} |
|||
|
|||
private void DisableRule() |
|||
{ |
|||
rule.Disable(CreateCommand(new DisableRule())); |
|||
} |
|||
|
|||
private void CreateRule() |
|||
{ |
|||
rule.Create(CreateCommand(new CreateRule { Trigger = ruleTrigger, Action = ruleAction })); |
|||
} |
|||
} |
|||
} |
|||
@ -1,256 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Immutable; |
|||
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.Entities.Rules.Commands; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Rules; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Rules |
|||
{ |
|||
public class RuleDomainObjectTests : HandlerTestBase<RuleDomainObject> |
|||
{ |
|||
private readonly Guid ruleId = Guid.NewGuid(); |
|||
private readonly RuleTrigger ruleTrigger = new ContentChangedTrigger(); |
|||
private readonly RuleAction ruleAction = new WebhookAction { Url = new Uri("https://squidex.io") }; |
|||
private readonly RuleDomainObject sut = new RuleDomainObject(); |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return ruleId; } |
|||
} |
|||
|
|||
public RuleDomainObjectTests() |
|||
{ |
|||
sut.ActivateAsync(Id, A.Fake<IStore<Guid>>()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_throw_exception_if_created() |
|||
{ |
|||
sut.Create(CreateRuleCommand(new CreateRule { Trigger = ruleTrigger, Action = ruleAction })); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Create(CreateRuleCommand(new CreateRule { Trigger = ruleTrigger, Action = ruleAction })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Create_should_create_events() |
|||
{ |
|||
var command = new CreateRule { Trigger = ruleTrigger, Action = ruleAction }; |
|||
|
|||
sut.Create(CreateRuleCommand(command)); |
|||
|
|||
Assert.Equal(AppId, sut.Snapshot.AppId.Id); |
|||
|
|||
Assert.Same(ruleTrigger, sut.Snapshot.RuleDef.Trigger); |
|||
Assert.Same(ruleAction, sut.Snapshot.RuleDef.Action); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleCreated { Trigger = ruleTrigger, Action = ruleAction }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateRuleCommand(new UpdateRule { Trigger = ruleTrigger, Action = ruleAction })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_throw_exception_if_rule_is_deleted() |
|||
{ |
|||
CreateRule(); |
|||
DeleteRule(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Update(CreateRuleCommand(new UpdateRule { Trigger = ruleTrigger, Action = ruleAction })); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_should_create_events() |
|||
{ |
|||
var newTrigger = new ContentChangedTrigger |
|||
{ |
|||
Schemas = ImmutableList<ContentChangedTriggerSchema>.Empty |
|||
}; |
|||
|
|||
var newAction = new WebhookAction |
|||
{ |
|||
Url = new Uri("https://squidex.io/v2") |
|||
}; |
|||
|
|||
CreateRule(); |
|||
|
|||
var command = new UpdateRule { Trigger = newTrigger, Action = newAction }; |
|||
|
|||
sut.Update(CreateRuleCommand(command)); |
|||
|
|||
Assert.Same(newTrigger, sut.Snapshot.RuleDef.Trigger); |
|||
Assert.Same(newAction, sut.Snapshot.RuleDef.Action); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleUpdated { Trigger = newTrigger, Action = newAction }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Enable_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Enable(CreateRuleCommand(new EnableRule())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Enable_should_throw_exception_if_rule_is_deleted() |
|||
{ |
|||
CreateRule(); |
|||
DeleteRule(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Enable(CreateRuleCommand(new EnableRule())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Enable_should_create_events() |
|||
{ |
|||
CreateRule(); |
|||
|
|||
var command = new EnableRule(); |
|||
|
|||
sut.Enable(CreateRuleCommand(command)); |
|||
|
|||
Assert.True(sut.Snapshot.RuleDef.IsEnabled); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleEnabled()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Disable_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Disable(CreateRuleCommand(new DisableRule())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Disable_should_throw_exception_if_rule_is_deleted() |
|||
{ |
|||
CreateRule(); |
|||
DeleteRule(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Disable(CreateRuleCommand(new DisableRule())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Disable_should_create_events() |
|||
{ |
|||
CreateRule(); |
|||
|
|||
var command = new DisableRule(); |
|||
|
|||
sut.Disable(CreateRuleCommand(command)); |
|||
|
|||
Assert.False(sut.Snapshot.RuleDef.IsEnabled); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleDisabled()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_throw_exception_if_not_created() |
|||
{ |
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Delete(CreateRuleCommand(new DeleteRule())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_throw_exception_if_already_deleted() |
|||
{ |
|||
CreateRule(); |
|||
DeleteRule(); |
|||
|
|||
Assert.Throws<DomainException>(() => |
|||
{ |
|||
sut.Delete(CreateRuleCommand(new DeleteRule())); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Delete_should_update_create_events() |
|||
{ |
|||
CreateRule(); |
|||
|
|||
sut.Delete(CreateRuleCommand(new DeleteRule())); |
|||
|
|||
Assert.True(sut.Snapshot.IsDeleted); |
|||
|
|||
sut.GetUncomittedEvents() |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleDeleted()) |
|||
); |
|||
} |
|||
|
|||
private void CreateRule() |
|||
{ |
|||
sut.Create(CreateRuleCommand(new CreateRule { Trigger = ruleTrigger, Action = ruleAction })); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
private void DeleteRule() |
|||
{ |
|||
sut.Delete(CreateRuleCommand(new DeleteRule())); |
|||
sut.ClearUncommittedEvents(); |
|||
} |
|||
|
|||
protected T CreateRuleEvent<T>(T @event) where T : RuleEvent |
|||
{ |
|||
@event.RuleId = ruleId; |
|||
|
|||
return CreateEvent(@event); |
|||
} |
|||
|
|||
protected T CreateRuleCommand<T>(T command) where T : RuleCommand |
|||
{ |
|||
command.RuleId = ruleId; |
|||
|
|||
return CreateCommand(command); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,227 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Immutable; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Orleans.Core; |
|||
using Orleans.Runtime; |
|||
using Squidex.Domain.Apps.Core.Rules.Actions; |
|||
using Squidex.Domain.Apps.Core.Rules.Triggers; |
|||
using Squidex.Domain.Apps.Entities.Rules.Commands; |
|||
using Squidex.Domain.Apps.Entities.Rules.State; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Rules; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Rules |
|||
{ |
|||
public class RuleDomainObjectTests : HandlerTestBase<RuleGrain, RuleState> |
|||
{ |
|||
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|||
private readonly Guid ruleId = Guid.NewGuid(); |
|||
private readonly RuleGrain sut; |
|||
|
|||
public sealed class MyRuleGrain : RuleGrain |
|||
{ |
|||
public MyRuleGrain(IStore<Guid> store, IAppProvider appProvider, IGrainIdentity identity, IGrainRuntime runtime) |
|||
: base(store, appProvider, identity, runtime) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return ruleId; } |
|||
} |
|||
|
|||
public RuleDomainObjectTests() |
|||
{ |
|||
sut = new MyRuleGrain(Store, appProvider, Identity, Runtime); |
|||
sut.OnActivateAsync().Wait(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Command_should_throw_exception_if_rule_is_deleted() |
|||
{ |
|||
await CreateAsync(); |
|||
await DeleteAsync(); |
|||
|
|||
await Assert.ThrowsAsync<DomainException>(() => |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateRuleCommand(MakeUpdateCommand()))); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_events() |
|||
{ |
|||
var command = MakeCreateCommand(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateRuleCommand(command))); |
|||
|
|||
Assert.True(result.Value is EntityCreatedResult<Guid>); |
|||
|
|||
Assert.Equal(AppId, sut.Snapshot.AppId.Id); |
|||
|
|||
Assert.Same(command.Trigger, sut.Snapshot.RuleDef.Trigger); |
|||
Assert.Same(command.Action, sut.Snapshot.RuleDef.Action); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleCreated { Trigger = command.Trigger, Action = command.Action }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_handle_command() |
|||
{ |
|||
await sut.ExecuteAsync(J(CreateRuleCommand(MakeCreateCommand()))); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateRuleCommand(MakeUpdateCommand()))); |
|||
|
|||
Assert.True(result.Value is EntitySavedResult); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_create_events() |
|||
{ |
|||
var command = MakeUpdateCommand(); |
|||
|
|||
await CreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateRuleCommand(command))); |
|||
|
|||
Assert.True(result.Value is EntitySavedResult); |
|||
|
|||
Assert.Same(command.Trigger, sut.Snapshot.RuleDef.Trigger); |
|||
Assert.Same(command.Action, sut.Snapshot.RuleDef.Action); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleUpdated { Trigger = command.Trigger, Action = command.Action }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Enable_should_handle_command() |
|||
{ |
|||
await sut.ExecuteAsync(J(CreateRuleCommand(MakeCreateCommand()))); |
|||
await sut.ExecuteAsync(J(CreateRuleCommand(new DisableRule()))); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Enable_should_create_events() |
|||
{ |
|||
await CreateAsync(); |
|||
await sut.ExecuteAsync(J(CreateRuleCommand(new DisableRule()))); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateRuleCommand(new EnableRule()))); |
|||
|
|||
Assert.True(result.Value is EntitySavedResult); |
|||
|
|||
Assert.True(sut.Snapshot.RuleDef.IsEnabled); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleEnabled()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Disable_should_create_events() |
|||
{ |
|||
await CreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateRuleCommand(new DisableRule()))); |
|||
|
|||
Assert.True(result.Value is EntitySavedResult); |
|||
|
|||
Assert.False(sut.Snapshot.RuleDef.IsEnabled); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleDisabled()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Delete_should_update_create_events() |
|||
{ |
|||
await CreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateRuleCommand(new DeleteRule()))); |
|||
|
|||
Assert.True(result.Value is EntitySavedResult); |
|||
|
|||
Assert.True(sut.Snapshot.IsDeleted); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateRuleEvent(new RuleDeleted()) |
|||
); |
|||
} |
|||
|
|||
private Task CreateAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateRuleCommand(MakeCreateCommand()))); |
|||
} |
|||
|
|||
private Task DeleteAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateRuleCommand(new DeleteRule()))); |
|||
} |
|||
|
|||
protected T CreateRuleEvent<T>(T @event) where T : RuleEvent |
|||
{ |
|||
@event.RuleId = ruleId; |
|||
|
|||
return CreateEvent(@event); |
|||
} |
|||
|
|||
protected T CreateRuleCommand<T>(T command) where T : RuleCommand |
|||
{ |
|||
command.RuleId = ruleId; |
|||
|
|||
return CreateCommand(command); |
|||
} |
|||
|
|||
private CreateRule MakeCreateCommand() |
|||
{ |
|||
var newTrigger = new ContentChangedTrigger |
|||
{ |
|||
Schemas = ImmutableList<ContentChangedTriggerSchema>.Empty |
|||
}; |
|||
|
|||
var newAction = new WebhookAction |
|||
{ |
|||
Url = new Uri("https://squidex.io/v2") |
|||
}; |
|||
|
|||
return new CreateRule { Trigger = newTrigger, Action = newAction }; |
|||
} |
|||
|
|||
private static UpdateRule MakeUpdateCommand() |
|||
{ |
|||
var newTrigger = new ContentChangedTrigger |
|||
{ |
|||
Schemas = ImmutableList<ContentChangedTriggerSchema>.Empty |
|||
}; |
|||
|
|||
var newAction = new WebhookAction |
|||
{ |
|||
Url = new Uri("https://squidex.io/v2") |
|||
}; |
|||
|
|||
return new UpdateRule { Trigger = newTrigger, Action = newAction }; |
|||
} |
|||
} |
|||
} |
|||
@ -1,280 +1,280 @@ |
|||
// ==========================================================================
|
|||
// 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 FakeItEasy; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Domain.Apps.Entities.Schemas.Commands; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Schemas |
|||
{ |
|||
public class SchemaCommandMiddlewareTests : HandlerTestBase<SchemaDomainObject> |
|||
{ |
|||
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|||
private readonly SchemaCommandMiddleware sut; |
|||
private readonly SchemaDomainObject schema; |
|||
private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry()); |
|||
private readonly string fieldName = "age"; |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return SchemaId; } |
|||
} |
|||
|
|||
public SchemaCommandMiddlewareTests() |
|||
{ |
|||
schema = new SchemaDomainObject(registry); |
|||
|
|||
sut = new SchemaCommandMiddleware(Handler, appProvider); |
|||
|
|||
A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName)) |
|||
.Returns((ISchemaEntity)null); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_schema_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId }); |
|||
|
|||
await TestCreate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Equal(SchemaId, context.Result<EntityCreatedResult<Guid>>().IdOrValue); |
|||
|
|||
A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName)).MustHaveHappened(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateSchema_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
|
|||
var context = CreateContextForCommand(new UpdateSchema { Properties = new SchemaProperties() }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ReorderSchema_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
|
|||
var context = CreateContextForCommand(new ReorderFields { FieldIds = new List<long>() }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task PublishSchema_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
|
|||
var context = CreateContextForCommand(new PublishSchema()); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UnpublishSchema_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
PublishSchema(); |
|||
|
|||
var context = CreateContextForCommand(new UnpublishSchema()); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ConfigureScripts_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
|
|||
var context = CreateContextForCommand(new ConfigureScripts()); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteSchema_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
|
|||
var context = CreateContextForCommand(new DeleteSchema()); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Add_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
|
|||
var context = CreateContextForCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
|
|||
Assert.Equal(1, context.Result<EntityCreatedResult<long>>().IdOrValue); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
var context = CreateContextForCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task LockField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
var context = CreateContextForCommand(new LockField { FieldId = 1 }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task HideField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
var context = CreateContextForCommand(new HideField { FieldId = 1 }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShowField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
HideField(); |
|||
|
|||
var context = CreateContextForCommand(new ShowField { FieldId = 1 }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DisableField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
var context = CreateContextForCommand(new DisableField { FieldId = 1 }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task EnableField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
DisableField(); |
|||
|
|||
var context = CreateContextForCommand(new EnableField { FieldId = 1 }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteField_should_update_domain_object() |
|||
{ |
|||
CreateSchema(); |
|||
CreateField(); |
|||
|
|||
var context = CreateContextForCommand(new DeleteField { FieldId = 1 }); |
|||
|
|||
await TestUpdate(schema, async _ => |
|||
{ |
|||
await sut.HandleAsync(context); |
|||
}); |
|||
} |
|||
|
|||
private void CreateSchema() |
|||
{ |
|||
schema.Create(CreateCommand(new CreateSchema { Name = SchemaName })); |
|||
} |
|||
|
|||
private void PublishSchema() |
|||
{ |
|||
schema.Publish(CreateCommand(new PublishSchema())); |
|||
} |
|||
|
|||
private void CreateField() |
|||
{ |
|||
schema.Add(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() })); |
|||
} |
|||
|
|||
private void HideField() |
|||
{ |
|||
schema.HideField(CreateCommand(new HideField { FieldId = 1 })); |
|||
} |
|||
|
|||
private void DisableField() |
|||
{ |
|||
schema.DisableField(CreateCommand(new DisableField { FieldId = 1 })); |
|||
} |
|||
} |
|||
} |
|||
//// ==========================================================================
|
|||
//// 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 FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Core.Schemas;
|
|||
//using Squidex.Domain.Apps.Entities.Schemas.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.Commands;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Schemas
|
|||
//{
|
|||
// public class SchemaCommandMiddlewareTests : HandlerTestBase<SchemaDomainObject>
|
|||
// {
|
|||
// private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
|
|||
// private readonly SchemaCommandMiddleware sut;
|
|||
// private readonly SchemaDomainObject schema;
|
|||
// private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry());
|
|||
// private readonly string fieldName = "age";
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return SchemaId; }
|
|||
// }
|
|||
|
|||
// public SchemaCommandMiddlewareTests()
|
|||
// {
|
|||
// schema = new SchemaDomainObject(registry);
|
|||
|
|||
// sut = new SchemaCommandMiddleware(Handler, appProvider);
|
|||
|
|||
// A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName))
|
|||
// .Returns((ISchemaEntity)null);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_create_schema_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId });
|
|||
|
|||
// await TestCreate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(SchemaId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);
|
|||
|
|||
// A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName)).MustHaveHappened();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UpdateSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateSchema { Properties = new SchemaProperties() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ReorderSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new ReorderFields { FieldIds = new List<long>() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task PublishSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new PublishSchema());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UnpublishSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// PublishSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new UnpublishSchema());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ConfigureScripts_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new ConfigureScripts());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DeleteSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new DeleteSchema());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Add_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(1, context.Result<EntityCreatedResult<long>>().IdOrValue);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UpdateField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task LockField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new LockField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task HideField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new HideField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ShowField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// HideField();
|
|||
|
|||
// var context = CreateContextForCommand(new ShowField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DisableField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new DisableField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task EnableField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// DisableField();
|
|||
|
|||
// var context = CreateContextForCommand(new EnableField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DeleteField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new DeleteField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// private void CreateSchema()
|
|||
// {
|
|||
// schema.Create(CreateCommand(new CreateSchema { Name = SchemaName }));
|
|||
// }
|
|||
|
|||
// private void PublishSchema()
|
|||
// {
|
|||
// schema.Publish(CreateCommand(new PublishSchema()));
|
|||
// }
|
|||
|
|||
// private void CreateField()
|
|||
// {
|
|||
// schema.Add(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() }));
|
|||
// }
|
|||
|
|||
// private void HideField()
|
|||
// {
|
|||
// schema.HideField(CreateCommand(new HideField { FieldId = 1 }));
|
|||
// }
|
|||
|
|||
// private void DisableField()
|
|||
// {
|
|||
// schema.DisableField(CreateCommand(new DisableField { FieldId = 1 }));
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
File diff suppressed because it is too large
Loading…
Reference in new issue