diff --git a/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs b/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs index 0a9ca47a3..03d8e4881 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/AppDomainObject.cs @@ -181,7 +181,7 @@ namespace Squidex.Domain.Apps.Entities.Apps private static AppPatternAdded CreateInitialPattern(NamedId appId, RefToken actor, Guid id, AppPattern p) { - return new AppPatternAdded { AppId = appId, Actor = actor, Id = id, Name = p.Name, Pattern = p.Pattern, Message = p.Message }; + return new AppPatternAdded { AppId = appId, Actor = actor, PatternId = id, Name = p.Name, Pattern = p.Pattern, Message = p.Message }; } private static AppLanguageAdded CreateInitialLanguage(NamedId appId, RefToken actor) diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Commands/AddPattern.cs b/src/Squidex.Domain.Apps.Entities/Apps/Commands/AddPattern.cs index 12df12042..1c438c376 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Commands/AddPattern.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Commands/AddPattern.cs @@ -12,7 +12,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands { public sealed class AddPattern : AppAggregateCommand { - public Guid Id { get; set; } + public Guid PatternId { get; set; } public string Name { get; set; } @@ -22,7 +22,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands public AddPattern() { - Id = Guid.NewGuid(); + PatternId = Guid.NewGuid(); } } } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Commands/DeletePattern.cs b/src/Squidex.Domain.Apps.Entities/Apps/Commands/DeletePattern.cs index d152f40d0..5fdd10028 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Commands/DeletePattern.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Commands/DeletePattern.cs @@ -12,6 +12,6 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands { public sealed class DeletePattern : AppAggregateCommand { - public Guid Id { get; set; } + public Guid PatternId { get; set; } } } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Commands/UpdatePattern.cs b/src/Squidex.Domain.Apps.Entities/Apps/Commands/UpdatePattern.cs index da4b7f097..b025aeb22 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Commands/UpdatePattern.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Commands/UpdatePattern.cs @@ -12,7 +12,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Commands { public sealed class UpdatePattern : AppAggregateCommand { - public Guid Id { get; set; } + public Guid PatternId { get; set; } public string Name { get; set; } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppPattern.cs b/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppPattern.cs index 3aea26e1c..142cb6061 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppPattern.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppPattern.cs @@ -51,9 +51,9 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards { Guard.NotNull(command, nameof(command)); - if (!patterns.ContainsKey(command.Id)) + if (!patterns.ContainsKey(command.PatternId)) { - throw new DomainObjectNotFoundException(command.Id.ToString(), typeof(AppPattern)); + throw new DomainObjectNotFoundException(command.PatternId.ToString(), typeof(AppPattern)); } } @@ -61,9 +61,9 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards { Guard.NotNull(command, nameof(command)); - if (!patterns.ContainsKey(command.Id)) + if (!patterns.ContainsKey(command.PatternId)) { - throw new DomainObjectNotFoundException(command.Id.ToString(), typeof(AppPattern)); + throw new DomainObjectNotFoundException(command.PatternId.ToString(), typeof(AppPattern)); } Validate.It(() => "Cannot update pattern.", error => @@ -73,7 +73,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards error(new ValidationError("Pattern name can not be empty.", nameof(command.Name))); } - if (patterns.Any(x => x.Key != command.Id && x.Value.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase))) + if (patterns.Any(x => x.Key != command.PatternId && x.Value.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase))) { error(new ValidationError("Pattern name is already assigned.", nameof(command.Name))); } @@ -87,7 +87,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards error(new ValidationError("Pattern is not a valid regular expression.", nameof(command.Pattern))); } - if (patterns.Any(x => x.Key != command.Id && x.Value.Pattern == command.Pattern)) + if (patterns.Any(x => x.Key != command.PatternId && x.Value.Pattern == command.Pattern)) { error(new ValidationError("Pattern already exists.", nameof(command.Pattern))); } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs b/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs index b44ca76bf..b2d404e83 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/State/AppState.cs @@ -82,17 +82,17 @@ namespace Squidex.Domain.Apps.Entities.Apps.State protected void On(AppPatternAdded @event) { - Patterns = Patterns.Add(@event.Id, @event.Name, @event.Pattern, @event.Message); + Patterns = Patterns.Add(@event.PatternId, @event.Name, @event.Pattern, @event.Message); } protected void On(AppPatternDeleted @event) { - Patterns = Patterns.Remove(@event.Id); + Patterns = Patterns.Remove(@event.PatternId); } protected void On(AppPatternUpdated @event) { - Patterns = Patterns.Update(@event.Id, @event.Name, @event.Pattern, @event.Message); + Patterns = Patterns.Update(@event.PatternId, @event.Name, @event.Pattern, @event.Message); } protected void On(AppLanguageAdded @event) diff --git a/src/Squidex.Domain.Apps.Events/Apps/AppPatternAdded.cs b/src/Squidex.Domain.Apps.Events/Apps/AppPatternAdded.cs index dd37f4ec7..49bc41e10 100644 --- a/src/Squidex.Domain.Apps.Events/Apps/AppPatternAdded.cs +++ b/src/Squidex.Domain.Apps.Events/Apps/AppPatternAdded.cs @@ -14,7 +14,7 @@ namespace Squidex.Domain.Apps.Events.Apps [EventType(nameof(AppPatternAdded))] public sealed class AppPatternAdded : AppEvent { - public Guid Id { get; set; } + public Guid PatternId { get; set; } public string Name { get; set; } diff --git a/src/Squidex.Domain.Apps.Events/Apps/AppPatternDeleted.cs b/src/Squidex.Domain.Apps.Events/Apps/AppPatternDeleted.cs index 0a595e3d4..854980f94 100644 --- a/src/Squidex.Domain.Apps.Events/Apps/AppPatternDeleted.cs +++ b/src/Squidex.Domain.Apps.Events/Apps/AppPatternDeleted.cs @@ -14,7 +14,7 @@ namespace Squidex.Domain.Apps.Events.Apps [EventType(nameof(AppPatternDeleted))] public sealed class AppPatternDeleted : AppEvent { - public Guid Id { get; set; } + public Guid PatternId { get; set; } public string Name { get; set; } } diff --git a/src/Squidex.Domain.Apps.Events/Apps/AppPatternUpdated.cs b/src/Squidex.Domain.Apps.Events/Apps/AppPatternUpdated.cs index c24da6327..b27b5d4e1 100644 --- a/src/Squidex.Domain.Apps.Events/Apps/AppPatternUpdated.cs +++ b/src/Squidex.Domain.Apps.Events/Apps/AppPatternUpdated.cs @@ -14,7 +14,7 @@ namespace Squidex.Domain.Apps.Events.Apps [EventType(nameof(AppPatternUpdated))] public sealed class AppPatternUpdated : AppEvent { - public Guid Id { get; set; } + public Guid PatternId { get; set; } public string Name { get; set; } diff --git a/src/Squidex/Areas/Api/Controllers/Apps/AppPatternsController.cs b/src/Squidex/Areas/Api/Controllers/Apps/AppPatternsController.cs index 6dff37ad9..0dfb36706 100644 --- a/src/Squidex/Areas/Api/Controllers/Apps/AppPatternsController.cs +++ b/src/Squidex/Areas/Api/Controllers/Apps/AppPatternsController.cs @@ -52,7 +52,8 @@ namespace Squidex.Areas.Api.Controllers.Apps public IActionResult GetPatterns(string app) { var response = - App.Patterns.Select(x => SimpleMapper.Map(x.Value, new AppPatternDto { Id = x.Key })).OrderBy(x => x.Name).ToList(); + App.Patterns.Select(x => SimpleMapper.Map(x.Value, new AppPatternDto { PatternId = x.Key })) + .OrderBy(x => x.Name).ToList(); return Ok(response); } @@ -76,6 +77,8 @@ namespace Squidex.Areas.Api.Controllers.Apps await CommandBus.PublishAsync(command); + var response = SimpleMapper.Map(request, new AppPatternDto { PatternId = command.PatternId }); + return CreatedAtAction(nameof(GetPatterns), new { app }, request); } @@ -95,7 +98,7 @@ namespace Squidex.Areas.Api.Controllers.Apps [ApiCosts(1)] public async Task UpdatePattern(string app, Guid id, [FromBody] UpdatePatternDto request) { - var command = SimpleMapper.Map(request, new UpdatePattern { Id = id }); + var command = SimpleMapper.Map(request, new UpdatePattern { PatternId = id }); await CommandBus.PublishAsync(command); @@ -119,7 +122,7 @@ namespace Squidex.Areas.Api.Controllers.Apps [ApiCosts(1)] public async Task DeletePattern(string app, Guid id) { - await CommandBus.PublishAsync(new DeletePattern { Id = id }); + await CommandBus.PublishAsync(new DeletePattern { PatternId = id }); return NoContent(); } diff --git a/src/Squidex/Areas/Api/Controllers/Apps/Models/AppPatternDto.cs b/src/Squidex/Areas/Api/Controllers/Apps/Models/AppPatternDto.cs index 9fb65d14d..ca5b7422e 100644 --- a/src/Squidex/Areas/Api/Controllers/Apps/Models/AppPatternDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Apps/Models/AppPatternDto.cs @@ -16,7 +16,7 @@ namespace Squidex.Areas.Api.Controllers.Apps.Models /// /// Identifier for Pattern /// - public Guid Id { get; set; } + public Guid PatternId { get; set; } /// /// The name of the suggestion. diff --git a/src/Squidex/app/features/schemas/pages/schema/field.component.html b/src/Squidex/app/features/schemas/pages/schema/field.component.html index 07203613f..322930909 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.html @@ -139,7 +139,7 @@
- +
diff --git a/src/Squidex/app/features/schemas/pages/schema/field.component.ts b/src/Squidex/app/features/schemas/pages/schema/field.component.ts index 0233f931a..b86ec1086 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.ts @@ -9,6 +9,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormBuilder, Validators } from '@angular/forms'; import { + AppPatternDto, createProperties, fadeAnimation, FieldDto, @@ -31,6 +32,9 @@ export class FieldComponent implements OnInit { @Input() public schemas: SchemaDto[]; + @Input() + public regexSuggestions: AppPatternDto[] = []; + @Output() public locking = new EventEmitter(); diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html index 8415c4ac2..30265a7f6 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.html @@ -62,6 +62,7 @@
; + public regexSuggestions: AppPatternDto[] = []; + public exportSchemaDialog = new ModalView(); public configureScriptsDialog = new ModalView(); @@ -86,7 +90,8 @@ export class SchemaPageComponent implements OnDestroy, OnInit { constructor(public readonly ctx: AppContext, private readonly formBuilder: FormBuilder, private readonly router: Router, - private readonly schemasService: SchemasService + private readonly schemasService: SchemasService, + private readonly appPatternsService: AppPatternsService ) { } @@ -114,6 +119,11 @@ export class SchemaPageComponent implements OnDestroy, OnInit { } private load() { + this.appPatternsService.getPatterns(this.ctx.appName) + .subscribe(dtos => { + this.regexSuggestions = dtos.patterns; + }); + this.schemasService.getSchemas(this.ctx.appName) .subscribe(dtos => { this.schemas = ImmutableArray.of(dtos); diff --git a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html index a81166ef9..b98ffd8ac 100644 --- a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html +++ b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.html @@ -33,14 +33,17 @@

Suggestions

-
+
{{suggestion.name}}
{{suggestion.pattern}}
+ + {{patternName}} +
-
+
diff --git a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts index 772da9f1e..bf00e09dd 100644 --- a/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/types/string-validation.component.ts @@ -10,10 +10,9 @@ import { FormControl, FormGroup } from '@angular/forms'; import { Observable, Subscription } from 'rxjs'; import { + AppPatternDto, ModalView, - StringFieldPropertiesDto, - UIRegexSuggestionDto, - UIService + StringFieldPropertiesDto } from 'shared'; @Component({ @@ -23,7 +22,6 @@ import { }) export class StringValidationComponent implements OnDestroy, OnInit { private patternSubscription: Subscription; - private uiSettingsSubscription: Subscription; @Input() public editForm: FormGroup; @@ -31,22 +29,18 @@ export class StringValidationComponent implements OnDestroy, OnInit { @Input() public properties: StringFieldPropertiesDto; + @Input() + public regexSuggestions: AppPatternDto[] = []; + public showDefaultValue: Observable; - public showPatternMessage: Observable; + public showPatternMessage: boolean; public showPatternSuggestions: Observable; - - public regexSuggestions: UIRegexSuggestionDto[] = []; + public patternName: string; public regexSuggestionsModal = new ModalView(false, false); - constructor( - private readonly uiService: UIService - ) { - } - public ngOnDestroy() { this.patternSubscription.unsubscribe(); - this.uiSettingsSubscription.unsubscribe(); } public ngOnInit() { @@ -71,31 +65,39 @@ export class StringValidationComponent implements OnDestroy, OnInit { .map(x => !x); this.showPatternMessage = - this.editForm.controls['pattern'].valueChanges - .startWith('') - .map(x => x && x.trim().length > 0); + this.editForm.controls['pattern'].value && this.editForm.controls['pattern'].value.trim().length > 0; this.showPatternSuggestions = this.editForm.controls['pattern'].valueChanges .startWith('') .map(x => !x || x.trim().length === 0); - this.uiSettingsSubscription = - this.uiService.getSettings() - .subscribe(settings => { - this.regexSuggestions = settings.regexSuggestions; - }); - this.patternSubscription = this.editForm.controls['pattern'].valueChanges .subscribe((value: string) => { if (!value || value.length === 0) { this.editForm.controls['patternMessage'].setValue(undefined); } + this.setPatternName(); }); } - public setPattern(pattern: string) { - this.editForm.controls['pattern'].setValue(pattern); + public setPattern(pattern: AppPatternDto) { + this.patternName = pattern.name; + this.editForm.controls['pattern'].setValue(pattern.pattern); + this.editForm.controls['patternMessage'].setValue(pattern.message); + this.showPatternMessage = true; + } + + private setPatternName() { + const matchingPattern = this.regexSuggestions.find(x => x.pattern === this.editForm.controls['pattern'].value); + + if (matchingPattern) { + this.patternName = matchingPattern.name; + } else if (this.editForm.controls['pattern'].value && this.editForm.controls['pattern'].value.trim() !== '') { + this.patternName = 'Advanced'; + } else { + this.patternName = undefined; + } } } \ No newline at end of file diff --git a/src/Squidex/app/shared/declarations-base.ts b/src/Squidex/app/shared/declarations-base.ts index fecc4272e..ece0df32e 100644 --- a/src/Squidex/app/shared/declarations-base.ts +++ b/src/Squidex/app/shared/declarations-base.ts @@ -20,6 +20,7 @@ export * from './interceptors/auth.interceptor'; export * from './services/app-contributors.service'; export * from './services/app-clients.service'; export * from './services/app-languages.service'; +export * from './services/app-patterns.service'; export * from './services/apps-store.service'; export * from './services/apps.service'; export * from './services/assets.service'; diff --git a/src/Squidex/app/shared/module.ts b/src/Squidex/app/shared/module.ts index 7d60668a8..e6d23c16e 100644 --- a/src/Squidex/app/shared/module.ts +++ b/src/Squidex/app/shared/module.ts @@ -17,6 +17,7 @@ import { AppContributorsService, AppLanguagesService, AppMustExistGuard, + AppPatternsService, AppsStoreService, AppsService, AssetComponent, @@ -118,6 +119,7 @@ export class SqxSharedModule { AppContributorsService, AppLanguagesService, AppMustExistGuard, + AppPatternsService, AppsService, AppsStoreService, AssetsService, diff --git a/src/Squidex/app/shared/services/ui.service.spec.ts b/src/Squidex/app/shared/services/ui.service.spec.ts index 182eb502a..1ca53dc26 100644 --- a/src/Squidex/app/shared/services/ui.service.spec.ts +++ b/src/Squidex/app/shared/services/ui.service.spec.ts @@ -41,7 +41,7 @@ describe('UIService', () => { settings1 = result; }); - const response: UISettingsDto = { regexSuggestions: [], mapType: 'OSM', mapKey: '' }; + const response: UISettingsDto = { mapType: 'OSM', mapKey: '' }; const req = httpMock.expectOne('http://service/p/api/ui/settings'); @@ -75,6 +75,5 @@ describe('UIService', () => { req.error(new ErrorEvent('500')); expect(settings).toBeDefined(); - expect(settings!.regexSuggestions).toEqual([]); })); }); \ No newline at end of file diff --git a/src/Squidex/app/shared/services/ui.service.ts b/src/Squidex/app/shared/services/ui.service.ts index 633639291..a1f4841ef 100644 --- a/src/Squidex/app/shared/services/ui.service.ts +++ b/src/Squidex/app/shared/services/ui.service.ts @@ -14,15 +14,10 @@ import 'framework/angular/http-extensions'; import { ApiUrlConfig } from 'framework'; export interface UISettingsDto { - regexSuggestions: UIRegexSuggestionDto[]; mapType: string; mapKey: string; } -export interface UIRegexSuggestionDto { - name: string; pattern: string; -} - @Injectable() export class UIService { private settings: UISettingsDto; diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppCommandMiddlewareTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppCommandMiddlewareTests.cs index ef62c44b1..1e141b6c9 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppCommandMiddlewareTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppCommandMiddlewareTests.cs @@ -250,9 +250,9 @@ namespace Squidex.Domain.Apps.Entities.Apps public async Task UpdatePattern_should_update_domain() { CreateApp() - .AddPattern(CreateCommand(new AddPattern { Id = patternId, Name = "Any", Pattern = "." })); + .AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = "." })); - var context = CreateContextForCommand(new UpdatePattern { Id = patternId, Name = "Number", Pattern = "[0-9]" }); + var context = CreateContextForCommand(new UpdatePattern { PatternId = patternId, Name = "Number", Pattern = "[0-9]" }); await TestUpdate(app, async _ => { @@ -264,9 +264,9 @@ namespace Squidex.Domain.Apps.Entities.Apps public async Task DeletePattern_should_update_domain_object() { CreateApp() - .AddPattern(CreateCommand(new AddPattern { Id = patternId, Name = "Any", Pattern = "." })); + .AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = "." })); - var context = CreateContextForCommand(new DeletePattern { Id = patternId }); + var context = CreateContextForCommand(new DeletePattern { PatternId = patternId }); await TestUpdate(app, async _ => { diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppDomainObjectTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppDomainObjectTests.cs index 2a964de5c..b311d4223 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppDomainObjectTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppDomainObjectTests.cs @@ -66,8 +66,8 @@ namespace Squidex.Domain.Apps.Entities.Apps CreateEvent(new AppCreated { Name = AppName }), CreateEvent(new AppContributorAssigned { ContributorId = User.Identifier, Permission = AppContributorPermission.Owner }), CreateEvent(new AppLanguageAdded { Language = Language.EN }), - CreateEvent(new AppPatternAdded { Id = id1, Name = "Number", Pattern = "[0-9]" }), - CreateEvent(new AppPatternAdded { Id = id2, Name = "Numbers", Pattern = "[0-9]*" }) + CreateEvent(new AppPatternAdded { PatternId = id1, Name = "Number", Pattern = "[0-9]" }), + CreateEvent(new AppPatternAdded { PatternId = id2, Name = "Numbers", Pattern = "[0-9]*" }) ); } @@ -298,7 +298,7 @@ namespace Squidex.Domain.Apps.Entities.Apps [Fact] public void AddPattern_should_throw_exception_if_app_not_created() { - Assert.Throws(() => sut.AddPattern(CreateCommand(new AddPattern { Id = patternId, Name = "Any", Pattern = ".*" }))); + Assert.Throws(() => sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = ".*" }))); } [Fact] @@ -306,13 +306,13 @@ namespace Squidex.Domain.Apps.Entities.Apps { CreateApp(); - sut.AddPattern(CreateCommand(new AddPattern { Id = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })); + sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })); Assert.Single(sut.State.Patterns); sut.GetUncomittedEvents() .ShouldHaveSameEvents( - CreateEvent(new AppPatternAdded { Id = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }) + CreateEvent(new AppPatternAdded { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }) ); } @@ -323,7 +323,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { sut.DeletePattern(CreateCommand(new DeletePattern { - Id = Guid.NewGuid() + PatternId = Guid.NewGuid() })); }); } @@ -334,20 +334,20 @@ namespace Squidex.Domain.Apps.Entities.Apps CreateApp(); CreatePattern(); - sut.DeletePattern(CreateCommand(new DeletePattern { Id = patternId })); + sut.DeletePattern(CreateCommand(new DeletePattern { PatternId = patternId })); Assert.Empty(sut.State.Patterns); sut.GetUncomittedEvents() .ShouldHaveSameEvents( - CreateEvent(new AppPatternDeleted { Id = patternId }) + CreateEvent(new AppPatternDeleted { PatternId = patternId }) ); } [Fact] public void UpdatePattern_should_throw_exception_if_app_not_created() { - Assert.Throws(() => sut.UpdatePattern(CreateCommand(new UpdatePattern { Id = patternId, Name = "Any", Pattern = ".*" }))); + Assert.Throws(() => sut.UpdatePattern(CreateCommand(new UpdatePattern { PatternId = patternId, Name = "Any", Pattern = ".*" }))); } [Fact] @@ -356,19 +356,19 @@ namespace Squidex.Domain.Apps.Entities.Apps CreateApp(); CreatePattern(); - sut.UpdatePattern(CreateCommand(new UpdatePattern { Id = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })); + sut.UpdatePattern(CreateCommand(new UpdatePattern { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" })); Assert.Single(sut.State.Patterns); sut.GetUncomittedEvents() .ShouldHaveSameEvents( - CreateEvent(new AppPatternUpdated { Id = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }) + CreateEvent(new AppPatternUpdated { PatternId = patternId, Name = "Any", Pattern = ".*", Message = "Msg" }) ); } private void CreatePattern() { - sut.AddPattern(CreateCommand(new AddPattern { Id = patternId, Name = "Name", Pattern = ".*" })); + sut.AddPattern(CreateCommand(new AddPattern { PatternId = patternId, Name = "Name", Pattern = ".*" })); sut.ClearUncommittedEvents(); } diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppPatternsTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppPatternsTests.cs index e6f3202ef..f30de365b 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppPatternsTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppPatternsTests.cs @@ -25,7 +25,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards [Fact] public void CanAdd_should_throw_exception_if_name_empty() { - var command = new AddPattern { Id = patternId, Name = string.Empty, Pattern = ".*" }; + var command = new AddPattern { PatternId = patternId, Name = string.Empty, Pattern = ".*" }; Assert.Throws(() => GuardAppPattern.CanAdd(patterns_0, command)); } @@ -41,7 +41,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards [Fact] public void CanAdd_should_throw_exception_if_pattern_empty() { - var command = new AddPattern { Id = patternId, Name = "any", Pattern = string.Empty }; + var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = string.Empty }; Assert.Throws(() => GuardAppPattern.CanAdd(patterns_0, command)); } @@ -49,7 +49,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards [Fact] public void CanAdd_should_throw_exception_if_pattern_not_valid() { - var command = new AddPattern { Id = patternId, Name = "any", Pattern = "[0-9{1}" }; + var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = "[0-9{1}" }; Assert.Throws(() => GuardAppPattern.CanAdd(patterns_0, command)); } @@ -59,7 +59,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards { var patterns_1 = patterns_0.Add(Guid.NewGuid(), "any", "[a-z]", "Message"); - var command = new AddPattern { Id = patternId, Name = "any", Pattern = ".*" }; + var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = ".*" }; Assert.Throws(() => GuardAppPattern.CanAdd(patterns_1, command)); } @@ -67,7 +67,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards [Fact] public void CanAdd_should_not_throw_exception_if_success() { - var command = new AddPattern { Id = patternId, Name = "any", Pattern = ".*" }; + var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = ".*" }; GuardAppPattern.CanAdd(patterns_0, command); } @@ -75,7 +75,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards [Fact] public void CanDelete_should_throw_exception_if_pattern_not_found() { - var command = new DeletePattern { Id = patternId }; + var command = new DeletePattern { PatternId = patternId }; Assert.Throws(() => GuardAppPattern.CanDelete(patterns_0, command)); } @@ -85,7 +85,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards { var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message"); - var command = new DeletePattern { Id = patternId }; + var command = new DeletePattern { PatternId = patternId }; GuardAppPattern.CanDelete(patterns_1, command); } @@ -95,7 +95,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards { var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message"); - var command = new UpdatePattern { Id = patternId, Name = string.Empty, Pattern = ".*" }; + var command = new UpdatePattern { PatternId = patternId, Name = string.Empty, Pattern = ".*" }; Assert.Throws(() => GuardAppPattern.CanUpdate(patterns_1, command)); } @@ -105,7 +105,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards { var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message"); - var command = new UpdatePattern { Id = patternId, Name = "any", Pattern = string.Empty }; + var command = new UpdatePattern { PatternId = patternId, Name = "any", Pattern = string.Empty }; Assert.Throws(() => GuardAppPattern.CanUpdate(patterns_1, command)); } @@ -115,7 +115,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards { var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message"); - var command = new UpdatePattern { Id = patternId, Name = "any", Pattern = "[0-9{1}" }; + var command = new UpdatePattern { PatternId = patternId, Name = "any", Pattern = "[0-9{1}" }; Assert.Throws(() => GuardAppPattern.CanUpdate(patterns_1, command)); } @@ -129,7 +129,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards var patterns_1 = patterns_0.Add(id1, "Pattern1", "[0-5]", "Message"); var patterns_2 = patterns_1.Add(id2, "Pattern2", "[0-4]", "Message"); - var command = new UpdatePattern { Id = id2, Name = "Pattern1", Pattern = "[0-4]" }; + var command = new UpdatePattern { PatternId = id2, Name = "Pattern1", Pattern = "[0-4]" }; Assert.Throws(() => GuardAppPattern.CanUpdate(patterns_2, command)); } @@ -143,7 +143,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards var patterns_1 = patterns_0.Add(id1, "Pattern1", "[0-5]", "Message"); var patterns_2 = patterns_1.Add(id2, "Pattern2", "[0-4]", "Message"); - var command = new UpdatePattern { Id = id2, Name = "Pattern2", Pattern = "[0-5]" }; + var command = new UpdatePattern { PatternId = id2, Name = "Pattern2", Pattern = "[0-5]" }; Assert.Throws(() => GuardAppPattern.CanUpdate(patterns_2, command)); } @@ -151,7 +151,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards [Fact] public void CanUpdate_should_throw_exception_if_pattern_does_not_exists() { - var command = new UpdatePattern { Id = patternId, Name = "Pattern1", Pattern = ".*" }; + var command = new UpdatePattern { PatternId = patternId, Name = "Pattern1", Pattern = ".*" }; Assert.Throws(() => GuardAppPattern.CanUpdate(patterns_0, command)); } @@ -161,7 +161,7 @@ namespace Squidex.Domain.Apps.Write.Apps.Guards { var patterns_1 = patterns_0.Add(patternId, "any", ".*", "Message"); - var command = new UpdatePattern { Id = patternId, Name = "Pattern1", Pattern = ".*" }; + var command = new UpdatePattern { PatternId = patternId, Name = "Pattern1", Pattern = ".*" }; GuardAppPattern.CanUpdate(patterns_1, command); }