mirror of https://github.com/Squidex/squidex.git
13 changed files with 454 additions and 731 deletions
@ -1,291 +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.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")));
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -1,399 +0,0 @@ |
|||
//// ==========================================================================
|
|||
//// 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();
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -0,0 +1,407 @@ |
|||
// ==========================================================================
|
|||
// 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 Orleans.Core; |
|||
using Orleans.Runtime; |
|||
using Squidex.Domain.Apps.Core.Apps; |
|||
using Squidex.Domain.Apps.Entities.Apps.Commands; |
|||
using Squidex.Domain.Apps.Entities.Apps.Services; |
|||
using Squidex.Domain.Apps.Entities.Apps.State; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Apps; |
|||
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 AppGrainTests : HandlerTestBase<AppGrain, AppState> |
|||
{ |
|||
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 string contributorId = Guid.NewGuid().ToString(); |
|||
private readonly string clientId = "client"; |
|||
private readonly string clientNewName = "My Client"; |
|||
private readonly string planId = "premium"; |
|||
private readonly AppGrain sut; |
|||
private readonly Guid patternId1 = Guid.NewGuid(); |
|||
private readonly Guid patternId2 = Guid.NewGuid(); |
|||
private readonly Guid patternId3 = Guid.NewGuid(); |
|||
private readonly InitialPatterns initialPatterns; |
|||
|
|||
public class MyAppGrain : AppGrain |
|||
{ |
|||
public MyAppGrain( |
|||
InitialPatterns initialPatterns, |
|||
IStore<Guid> store, |
|||
IAppProvider appProvider, |
|||
IAppPlansProvider appPlansProvider, |
|||
IAppPlanBillingManager appPlansBillingManager, |
|||
IUserResolver userResolver, |
|||
IGrainIdentity identity, |
|||
IGrainRuntime runtime) |
|||
: base(initialPatterns, store, appProvider, appPlansProvider, appPlansBillingManager, userResolver, identity, runtime) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return AppId; } |
|||
} |
|||
|
|||
public AppGrainTests() |
|||
{ |
|||
A.CallTo(() => appProvider.GetAppAsync(AppName)) |
|||
.Returns((IAppEntity)null); |
|||
|
|||
A.CallTo(() => userResolver.FindByIdAsync(contributorId)) |
|||
.Returns(A.Fake<IUser>()); |
|||
|
|||
initialPatterns = new InitialPatterns |
|||
{ |
|||
{ patternId1, new AppPattern("Number", "[0-9]") }, |
|||
{ patternId2, new AppPattern("Numbers", "[0-9]*") } |
|||
}; |
|||
|
|||
sut = new MyAppGrain(initialPatterns, Store, appProvider, appPlansProvider, appPlansBillingManager, userResolver, Identity, Runtime); |
|||
sut.OnActivateAsync(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_events_and_update_state() |
|||
{ |
|||
var command = new CreateApp { Name = AppName, Actor = User, AppId = AppId }; |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(EntityCreatedResult.Create(Id, 4)); |
|||
|
|||
Assert.Equal(AppName, sut.Snapshot.Name); |
|||
|
|||
LastEvents |
|||
.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 = patternId1, Name = "Number", Pattern = "[0-9]" }), |
|||
CreateEvent(new AppPatternAdded { PatternId = patternId2, Name = "Numbers", Pattern = "[0-9]*" }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ChangePlan_should_create_events_and_update_state() |
|||
{ |
|||
var command = new ChangePlan { PlanId = planId }; |
|||
|
|||
A.CallTo(() => appPlansProvider.IsConfiguredPlan(planId)) |
|||
.Returns(true); |
|||
|
|||
A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, planId)) |
|||
.Returns(new PlanChangedResult()); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
Assert.True(result.Value is PlanChangedResult); |
|||
|
|||
Assert.Equal(planId, sut.Snapshot.Plan.PlanId); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPlanChanged { PlanId = planId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ChangePlan_should_not_make_update_for_redirect_result() |
|||
{ |
|||
var command = new ChangePlan { PlanId = planId }; |
|||
|
|||
A.CallTo(() => appPlansProvider.IsConfiguredPlan(planId)) |
|||
.Returns(true); |
|||
|
|||
A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, planId)) |
|||
.Returns(new RedirectToCheckoutResult(new Uri("http://squidex.io"))); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new RedirectToCheckoutResult(new Uri("http://squidex.io"))); |
|||
|
|||
Assert.Null(sut.Snapshot.Plan); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ChangePlan_should_not_call_billing_manager_for_callback() |
|||
{ |
|||
var command = new ChangePlan { PlanId = planId, FromCallback = true }; |
|||
|
|||
A.CallTo(() => appPlansProvider.IsConfiguredPlan(planId)) |
|||
.Returns(true); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(5)); |
|||
|
|||
A.CallTo(() => appPlansBillingManager.ChangePlanAsync(User.Identifier, AppId, AppName, planId)) |
|||
.MustNotHaveHappened(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AssignContributor_should_create_events_and_update_state() |
|||
{ |
|||
var command = new AssignContributor { ContributorId = contributorId, Permission = AppContributorPermission.Editor }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(5)); |
|||
|
|||
Assert.Equal(AppContributorPermission.Editor, sut.Snapshot.Contributors[contributorId]); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppContributorAssigned { ContributorId = contributorId, Permission = AppContributorPermission.Editor }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RemoveContributor_should_create_events_and_update_state() |
|||
{ |
|||
var command = new RemoveContributor { ContributorId = contributorId }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAssignContributorAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(6)); |
|||
|
|||
Assert.False(sut.Snapshot.Contributors.ContainsKey(contributorId)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppContributorRemoved { ContributorId = contributorId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AttachClient_should_create_events_and_update_state() |
|||
{ |
|||
var command = new AttachClient { Id = clientId }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(5)); |
|||
|
|||
Assert.True(sut.Snapshot.Clients.ContainsKey(clientId)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppClientAttached { Id = clientId, Secret = command.Secret }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RevokeClient_should_create_events_and_update_state() |
|||
{ |
|||
var command = new RevokeClient { Id = clientId }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAttachClientAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(6)); |
|||
|
|||
Assert.False(sut.Snapshot.Clients.ContainsKey(clientId)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppClientRevoked { Id = clientId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateClient_should_create_events_and_update_state() |
|||
{ |
|||
var command = new UpdateClient { Id = clientId, Name = clientNewName, Permission = AppClientPermission.Developer }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAttachClientAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(7)); |
|||
|
|||
Assert.Equal(clientNewName, sut.Snapshot.Clients[clientId].Name); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppClientRenamed { Id = clientId, Name = clientNewName }), |
|||
CreateEvent(new AppClientUpdated { Id = clientId, Permission = AppClientPermission.Developer }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AddLanguage_should_create_events_and_update_state() |
|||
{ |
|||
var command = new AddLanguage { Language = Language.DE }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(5)); |
|||
|
|||
Assert.True(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppLanguageAdded { Language = Language.DE }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task RemoveLanguage_should_create_events_and_update_state() |
|||
{ |
|||
var command = new RemoveLanguage { Language = Language.DE }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddLanguageAsync(Language.DE); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(6)); |
|||
|
|||
Assert.False(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppLanguageRemoved { Language = Language.DE }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateLanguage_should_create_events_and_update_state() |
|||
{ |
|||
var command = new UpdateLanguage { Language = Language.DE, Fallback = new List<Language> { Language.EN } }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddLanguageAsync(Language.DE); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(6)); |
|||
|
|||
Assert.True(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppLanguageUpdated { Language = Language.DE, Fallback = new List<Language> { Language.EN } }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task AddPattern_should_create_events_and_update_state() |
|||
{ |
|||
var command = new AddPattern { PatternId = patternId3, Name = "Any", Pattern = ".*", Message = "Msg" }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(5)); |
|||
|
|||
Assert.Equal(initialPatterns.Count + 1, sut.Snapshot.Patterns.Count); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPatternAdded { PatternId = patternId3, Name = "Any", Pattern = ".*", Message = "Msg" }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeletePattern_should_create_events_and_update_state() |
|||
{ |
|||
var command = new DeletePattern { PatternId = patternId3 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddPatternAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(6)); |
|||
|
|||
Assert.Equal(initialPatterns.Count, sut.Snapshot.Patterns.Count); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPatternDeleted { PatternId = patternId3 }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdatePattern_should_create_events_and_update_state() |
|||
{ |
|||
var command = new UpdatePattern { PatternId = patternId3, Name = "Any", Pattern = ".*", Message = "Msg" }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddPatternAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquivalent(new EntitySavedResult(6)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new AppPatternUpdated { PatternId = patternId3, Name = "Any", Pattern = ".*", Message = "Msg" }) |
|||
); |
|||
} |
|||
|
|||
private Task ExecuteAddPatternAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new AddPattern { PatternId = patternId3, Name = "Name", Pattern = ".*" }))); |
|||
} |
|||
|
|||
private Task ExecuteCreateAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new CreateApp { Name = AppName }))); |
|||
} |
|||
|
|||
private Task ExecuteAssignContributorAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new AssignContributor { ContributorId = contributorId, Permission = AppContributorPermission.Editor }))); |
|||
} |
|||
|
|||
private Task ExecuteAttachClientAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new AttachClient { Id = clientId }))); |
|||
} |
|||
|
|||
private Task ExecuteAddLanguageAsync(Language language) |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new AddLanguage { Language = language }))); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue