public async Task Create_should_not_assign_client_as_contributor() { var command = new CreateApp { Name = AppName, Actor = ActorClient, AppId = AppId }; var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(AppName, sut.Snapshot.Name); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppCreated { Name = AppName }, true), CreateEvent(new AppPatternAdded { PatternId = patternId1, Name = "Number", Pattern = "[0-9]" }, true), CreateEvent(new AppPatternAdded { PatternId = patternId2, Name = "Numbers", Pattern = "[0-9]*" }, true) ); }
public void Create(CreateApp command) { var appId = NamedId.Of(command.AppId, command.Name); var events = new List <AppEvent> { CreateInitalEvent(command.Name), CreateInitialLanguage() }; if (command.Actor.IsSubject) { events.Add(CreateInitialOwner(command.Actor)); } foreach (var(key, value) in initialPatterns) { events.Add(CreateInitialPattern(key, value)); } foreach (var @event in events) { @event.Actor = command.Actor; @event.AppId = appId; RaiseEvent(@event); } }
public async Task Should_throw_exception_if_number_of_apps_reached() { var userId = Guid.NewGuid().ToString(); var command = new CreateApp { Actor = RefToken.User(userId) }; var commandContext = new CommandContext(command, commandBus); options.MaximumNumberOfApps = 3; var user = A.Fake <IUser>(); A.CallTo(() => user.Id) .Returns(userId); A.CallTo(() => user.Claims) .Returns(Enumerable.Repeat(new Claim(SquidexClaimTypes.TotalApps, "5"), 1).ToList()); A.CallTo(() => userResolver.FindByIdAsync(userId, default)) .Returns(user); var isNextCalled = false; await Assert.ThrowsAsync <ValidationException>(() => sut.HandleAsync(commandContext, x => { isNextCalled = true; return(Task.CompletedTask); })); Assert.False(isNextCalled); }
private async Task <string?> CheckAppAsync(IAppsCacheGrain cache, CreateApp command) { var token = await cache.ReserveAsync(command.AppId, command.Name); if (token == null) { throw new ValidationException(T.Get("apps.nameAlreadyExists")); } try { var existingId = await GetAppIdAsync(command.Name); if (existingId != default) { throw new ValidationException(T.Get("apps.nameAlreadyExists")); } } catch { // Catch our own exception, just in case something went wrong before. await cache.RemoveReservationAsync(token); throw; } return(token); }
public async Task Create_should_create_events_and_update_state() { var command = new CreateApp { Name = AppName, Actor = Actor, AppId = AppId }; var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(AppName, sut.Snapshot.Name); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppCreated { Name = AppName }), CreateEvent(new AppContributorAssigned { ContributorId = Actor.Identifier, Role = Role.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]*" }) ); }
public void Should_validate_command_and_save_new_app() { var command = new CreateApp { Id = Guid.NewGuid(), Name = "Name", Description = "Description", Folder = "Folder" }; var appRepositoryMock = new Mock <IAppRepository>(); appRepositoryMock.Setup(x => x.Create(It.IsAny <App>())); var validatorMock = new Mock <IValidator <CreateApp> >(); validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult()); var createAppHandler = new CreateAppHandler(appRepositoryMock.Object, validatorMock.Object); createAppHandler.Handle(command); validatorMock.Verify(x => x.Validate(command)); appRepositoryMock.Verify(x => x.Create(It.IsAny <App>())); }
public AppDomainObject Create(CreateApp command) { ThrowIfCreated(); var appId = new NamedId <Guid>(command.AppId, command.Name); var events = new List <AppEvent> { CreateInitalEvent(command.Name), CreateInitialOwner(command.Actor), CreateInitialLanguage() }; foreach (var pattern in initialPatterns) { events.Add(CreateInitialPattern(pattern.Key, pattern.Value)); } foreach (var @event in events) { @event.Actor = command.Actor; @event.AppId = appId; RaiseEvent(@event); } return(this); }
public async Task <IActionResult> Post([FromBody] CreateApp model) { model.Id = Guid.NewGuid(); await Task.Run(() => _commandSender.Send <CreateApp, App>(model)); return(new NoContentResult()); }
public static IApplicationBuilder EnsureAppInstalled(this IApplicationBuilder builder) { var appInstallationService = builder.ApplicationServices.GetRequiredService <IAppInstallationService>(); var createApp = new CreateApp { Id = Guid.NewGuid(), Name = "Weapsy.Apps.Text", Description = "Text App", Folder = "Weapsy.Apps.Text" }; var createModuleTypes = new List <CreateModuleType> { new CreateModuleType { AppId = createApp.Id, Id = Guid.NewGuid(), Name = "Text", Title = "Text Module", Description = "Text Module", ViewType = ViewType.ViewComponent, ViewName = "TextModule", EditType = EditType.Modal, EditUrl = "Home/Index" } }; appInstallationService.EnsureAppInstalled(createApp, createModuleTypes); return(builder); }
public async Task Should_increment_total_apps_if_maximum_not_reached_and_completed() { var userId = Guid.NewGuid().ToString(); var command = new CreateApp { Actor = RefToken.User(userId) }; var commandContext = new CommandContext(command, commandBus); options.MaximumNumberOfApps = 10; var user = A.Fake <IUser>(); A.CallTo(() => user.Id) .Returns(userId); A.CallTo(() => user.Claims) .Returns(Enumerable.Repeat(new Claim(SquidexClaimTypes.TotalApps, "5"), 1).ToList()); A.CallTo(() => userResolver.FindByIdAsync(userId, default)) .Returns(user); await sut.HandleAsync(commandContext, x => { x.Complete(true); return(Task.CompletedTask); }); A.CallTo(() => userResolver.SetClaimAsync(userId, SquidexClaimTypes.TotalApps, "6", true, default)) .MustHaveHappened(); }
public Task CanCreate_should_throw_exception_if_name_not_valid() { var command = new CreateApp { Name = "INVALID NAME" }; return(Assert.ThrowsAsync <ValidationException>(() => GuardApp.CanCreate(command, apps))); }
public Task CanCreate_should_not_throw_exception_if_app_name_is_free() { var command = new CreateApp { Name = "new-app" }; return(GuardApp.CanCreate(command, apps)); }
public void CanCreate_should_not_throw_exception_if_app_name_is_valid() { var command = new CreateApp { Name = "new-app" }; GuardApp.CanCreate(command); }
public void CanCreate_should_throw_exception_if_name_not_valid() { var command = new CreateApp { Name = "INVALID NAME" }; ValidationAssert.Throws(() => GuardApp.CanCreate(command), new ValidationError("Name is not a valid slug.", "Name")); }
public Task CanCreate_should_throw_exception_if_name_not_valid() { var command = new CreateApp { Name = "INVALID NAME" }; return(ValidationAssert.ThrowsAsync(() => GuardApp.CanCreate(command, apps), new ValidationError("Name must be a valid slug.", "Name"))); }
public Task CanCreate_should_throw_exception_if_name_already_in_use() { var command = new CreateApp { Name = "existing" }; return(ValidationAssert.ThrowsAsync(() => GuardApp.CanCreate(command, apps), new ValidationError("An app with the same name already exists.", "Name"))); }
private App(CreateApp cmd) : base(cmd.Id) { AddEvent(new AppCreated { AggregateRootId = Id, Name = cmd.Name, Description = cmd.Description, Folder = cmd.Folder, Status = AppStatus.Active }); }
protected async Task On(CreateApp command, CommandContext context) { var app = await handler.CreateSyncedAsync <AppDomainObject>(context, async a => { await GuardApp.CanCreate(command, appProvider); a.Create(command); context.Complete(EntityCreatedResult.Create(command.AppId, a.Version)); }); }
private static async Task <string?> CheckAppAsync(IAppsCacheGrain cache, CreateApp command) { var token = await cache.ReserveAsync(command.AppId, command.Name); if (token == null) { throw new ValidationException(T.Get("apps.nameAlreadyExists")); } return(token); }
public Task CanCreate_should_throw_exception_if_name_already_in_use() { A.CallTo(() => apps.GetAppAsync("new-app")) .Returns(A.Fake <IAppEntity>()); var command = new CreateApp { Name = "new-app" }; return(Assert.ThrowsAsync <ValidationException>(() => GuardApp.CanCreate(command, apps))); }
public static void CanCreate(CreateApp command) { Guard.NotNull(command); Validate.It(() => "Cannot create app.", e => { if (!command.Name.IsSlug()) { e(Not.ValidSlug("Name"), nameof(command.Name)); } }); }
public static void CanCreate(CreateApp command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot create app.", e => { if (!command.Name.IsSlug()) { e("Name must be a valid slug.", nameof(command.Name)); } }); }
public static void CanCreate(CreateApp command) { Guard.NotNull(command, nameof(command)); Validate.It(e => { if (!command.Name.IsSlug()) { e(Not.ValidSlug(nameof(command.Name)), nameof(command.Name)); } }); }
private App(CreateApp cmd) : base(cmd.Id) { Name = cmd.Name; Description = cmd.Description; Folder = cmd.Folder; AddEvent(new AppCreated { AggregateRootId = Id, Name = Name, Description = Description, Folder = Folder }); }
public void Setup() { _command = new CreateApp { Id = Guid.NewGuid(), Name = "Name", Description = "Description", Folder = "Folder" }; _validatorMock = new Mock <IValidator <CreateApp> >(); _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult()); _app = App.CreateNew(_command, _validatorMock.Object); _event = _app.Events.OfType <AppCreated>().SingleOrDefault(); }
public async Task Should_create_schemas(ICommandMiddleware middleware, string template) { var command = new CreateApp { AppId = Guid.NewGuid(), Name = "my-app", Template = template }; var context = new CommandContext(command, commandBus) .Complete(); await middleware.HandleAsync(context); A.CallTo(() => commandBus.PublishAsync(A <CreateSchema> ._)) .MustHaveHappened(); }
public void SetUp() { _command = new CreateApp { Id = Guid.NewGuid(), Name = "Name", Description = "Description", Folder = "Folder" }; _appRulesMock = new Mock <IAppRules>(); _appRulesMock.Setup(x => x.IsAppIdUnique(_command.Id)).Returns(true); _validator = new CreateAppValidator(_appRulesMock.Object); }
public AppDomainObject Create(CreateApp command) { ThrowIfCreated(); var appId = new NamedId <Guid>(command.AppId, command.Name); RaiseEvent(SimpleMapper.Map(command, new AppCreated { AppId = appId })); RaiseEvent(SimpleMapper.Map(command, CreateInitialOwner(appId, command))); RaiseEvent(SimpleMapper.Map(command, CreateInitialLanguage(appId))); return(this); }
public async Task CreateAppTest(string appName, bool exception, Type exceptionType = null) { var rep = AppRepositoryMock.CreateRepository(); try { await CreateApp.Execute(rep, appName); Assert.IsFalse(exception); } catch (Exception ex) { Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName)); } }
public async Task CreateAppInvalidParametersTest(string appName, bool isRepNull) { var rep = isRepNull ? null : AppRepositoryMock.CreateRepository(); try { await CreateApp.Execute(rep, appName); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual(ex.GetType(), isRepNull ? typeof(ArgumentNullException) : typeof(ArgumentException)); } }
public void CreateApp_Test() { using (ShimsContext.Create()) { CloudFoundry.CloudController.V2.Client.Fakes.ShimCloudFoundryClient.AllInstances.LoginCloudCredentials = TestUtils.CustomLogin; CloudFoundry.CloudController.V2.Client.Base.Fakes.ShimAbstractSpacesEndpoint.AllInstances.ListAllSpacesRequestOptions = TestUtils.CustomListAllSpaces; CloudFoundry.CloudController.V2.Client.Fakes.ShimPagedResponseCollection<ListAllSpacesResponse>.AllInstances.ResourcesGet = TestUtils.CustomGetPaged; CloudFoundry.CloudController.V2.Client.Base.Fakes.ShimAbstractStacksEndpoint.AllInstances.ListAllStacks = TestUtils.CustomListAllStacks; CloudFoundry.CloudController.V2.Client.Fakes.ShimPagedResponseCollection<ListAllStacksResponse>.AllInstances.ResourcesGet = TestUtils.CustomGetStacks; CloudFoundry.CloudController.V2.Client.Base.Fakes.ShimAbstractAppsEndpoint.AllInstances.CreateAppCreateAppRequest = TestUtils.CustomCreateApp; CloudFoundry.CloudController.V2.Client.Fakes.ShimPagedResponseCollection<ListAllAppsForSpaceResponse>.AllInstances.ResourcesGet = TestUtils.CusomListAllAppsForSpacePagedResponseCreate; CloudFoundry.CloudController.V2.Client.Base.Fakes.ShimAbstractSpacesEndpoint.AllInstances.ListAllAppsForSpaceNullableOfGuidRequestOptions = TestUtils.CustomListAllAppsForSpace; CloudFoundry.CloudController.V2.Client.Fakes.ShimPagedResponseCollection<ListAllOrganizationsResponse>.AllInstances.ResourcesGet = TestUtils.CustomListAllOrganizationsResponse; CloudFoundry.CloudController.V2.Client.Base.Fakes.ShimAbstractOrganizationsEndpoint.AllInstances.ListAllOrganizationsRequestOptions = TestUtils.CustomListAllOrganizations; CloudFoundry.CloudController.V2.Client.Fakes.ShimPagedResponseCollection<ListAllSpacesForOrganizationResponse>.AllInstances.ResourcesGet = TestUtils.CustomListAllSpacesForOrganizationResponse; CloudFoundry.CloudController.V2.Client.Base.Fakes.ShimAbstractOrganizationsEndpoint.AllInstances.ListAllSpacesForOrganizationNullableOfGuidRequestOptions = TestUtils.CustomListAllSpacesForOrganization; TestUtils.InitTestMetadata(); CreateApp task = new CreateApp(); task.CFUser = Settings.Default.User; task.CFPassword = Settings.Default.Password; task.CFServerUri = Settings.Default.ServerUri; task.CFSpace= "TestSpace"; task.CFOrganization = "TestOrg"; task.CFStack = "testStack"; task.BuildEngine = new FakeBuildEngine(); Assert.IsTrue(task.Execute()); } }
public void Flow_IntegrationTest() { string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string appPath = Path.Combine(assemblyDirectory, "TestApp"); LoginTask login = new LoginTask(); login.BuildEngine = new FakeBuildEngine(); login.CFUser = Settings.Default.User; login.CFPassword = Settings.Default.Password; login.CFServerUri = Settings.Default.ServerUri; login.CFSkipSslValidation = true; login.Execute(); CreateApp task = new CreateApp(); task.CFRefreshToken = login.CFRefreshToken; task.CFServerUri = Settings.Default.ServerUri; task.CFSkipSslValidation = true; task.CFAppName = Guid.NewGuid().ToString("N"); task.CFAppMemory = 256; task.CFAppInstances = 1; task.CFSpace = Settings.Default.Space; task.CFOrganization = Settings.Default.Organization; task.CFStack = Settings.Default.Stack; task.CFEnvironmentJson = "{\"mykey\":\"abcd\",\"secondkey\":\"efgh\"}"; task.BuildEngine = new FakeBuildEngine(); task.Execute(); PushApp pushTask = new PushApp(); pushTask.CFUser = Settings.Default.User; pushTask.CFPassword = Settings.Default.Password; pushTask.CFServerUri = Settings.Default.ServerUri; pushTask.CFSkipSslValidation = true; pushTask.CFAppGuid = task.CFAppGuid; pushTask.CFAppPath = appPath; pushTask.CFStart = true; pushTask.BuildEngine = new FakeBuildEngine(); pushTask.Execute(); CreateRoutes routeTask = new CreateRoutes(); routeTask.CFUser = Settings.Default.User; routeTask.CFPassword = Settings.Default.Password; routeTask.CFServerUri = Settings.Default.ServerUri; routeTask.CFSkipSslValidation = true; routeTask.CFRoutes = new string[1] { string.Format(Settings.Default.Route, task.CFAppName) }; routeTask.CFSpace = Settings.Default.Space; routeTask.CFOrganization = Settings.Default.Organization; routeTask.BuildEngine = new FakeBuildEngine(); routeTask.Execute(); BindRoutes bindTask = new BindRoutes(); bindTask.CFUser = Settings.Default.User; bindTask.CFPassword = Settings.Default.Password; bindTask.CFServerUri = Settings.Default.ServerUri; bindTask.BuildEngine = new FakeBuildEngine(); bindTask.CFSkipSslValidation = true; bindTask.CFAppGuid = task.CFAppGuid; bindTask.CFRouteGuids = routeTask.CFRouteGuids; bindTask.Execute(); CreateService serviceTask = new CreateService(); serviceTask.CFUser = Settings.Default.User; serviceTask.CFPassword = Settings.Default.Password; serviceTask.CFServerUri = Settings.Default.ServerUri; serviceTask.BuildEngine = new FakeBuildEngine(); serviceTask.CFSkipSslValidation = true; serviceTask.CFServiceName = Guid.NewGuid().ToString("N"); serviceTask.CFServicePlan = Settings.Default.ServicePlan; serviceTask.CFServiceType = Settings.Default.ServiceType; serviceTask.CFSpace = Settings.Default.Space; serviceTask.CFOrganization = Settings.Default.Organization; serviceTask.Execute(); BindServices bindServiceTask = new BindServices(); bindServiceTask.CFUser = Settings.Default.User; bindServiceTask.CFPassword = Settings.Default.Password; bindServiceTask.CFServerUri = Settings.Default.ServerUri; bindServiceTask.BuildEngine = new FakeBuildEngine(); bindServiceTask.CFSkipSslValidation = true; bindServiceTask.CFAppGuid = task.CFAppGuid; bindServiceTask.CFServicesGuids = new string[1] { serviceTask.CFServiceGuid }; bindServiceTask.Execute(); if (CheckIfAppIsWorking(routeTask.CFRoutes[0], 60) == true) { DeleteApp delTask = new DeleteApp(); delTask.CFUser = Settings.Default.User; delTask.CFPassword = Settings.Default.Password; delTask.CFServerUri = Settings.Default.ServerUri; delTask.CFSkipSslValidation = true; delTask.CFSpace = Settings.Default.Space; delTask.CFOrganization = Settings.Default.Organization; delTask.CFAppName = task.CFAppName; delTask.CFDeleteServices = true; delTask.CFDeleteRoutes = true; delTask.BuildEngine = new FakeBuildEngine(); Assert.IsTrue(delTask.Execute()); } else { Assert.Fail("Application is not working"); } }