public async Task UpdateAsync() { var ids = await appRepository.QueryAppIdsAsync(); foreach (var id in ids) { var app = await stateFactory.GetSingleAsync <AppDomainObject>(id); if (app.Snapshot.Patterns.Count == 0) { foreach (var pattern in initialPatterns.Values) { var command = new AddPattern { Actor = app.Snapshot.CreatedBy, AppId = app.Snapshot.Id, Name = pattern.Name, PatternId = Guid.NewGuid(), Pattern = pattern.Pattern, Message = pattern.Message }; app.AddPattern(command); } await app.WriteAsync(); } } }
public async Task UpdateAsync() { var ids = await grainFactory.GetGrain <IAppsByNameIndex>(SingleGrain.Id).GetAppIdsAsync(); foreach (var id in ids) { var app = grainFactory.GetGrain <IAppGrain>(id); var state = await app.GetStateAsync(); if (state.Value.Patterns.Count == 0) { foreach (var pattern in initialPatterns.Values) { var command = new AddPattern { Actor = state.Value.CreatedBy, AppId = state.Value.Id, Name = pattern.Name, PatternId = Guid.NewGuid(), Pattern = pattern.Pattern, Message = pattern.Message }; await app.ExecuteAsync(command); } } } }
public static void CanAdd(AppPatterns patterns, AddPattern command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot add pattern.", error => { if (string.IsNullOrWhiteSpace(command.Name)) { error(new ValidationError("Pattern name can not be empty.", nameof(command.Name))); } if (patterns.Values.Any(x => x.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase))) { error(new ValidationError("Pattern name is already assigned.", nameof(command.Name))); } if (string.IsNullOrWhiteSpace(command.Pattern)) { error(new ValidationError("Pattern can not be empty.", nameof(command.Pattern))); } else if (!command.Pattern.IsValidRegex()) { error(new ValidationError("Pattern is not a valid regular expression.", nameof(command.Pattern))); } if (patterns.Values.Any(x => x.Pattern == command.Pattern)) { error(new ValidationError("Pattern already exists.", nameof(command.Pattern))); } }); }
public async Task UpdateAsync() { var ids = await indexForApps.GetIdsAsync(); foreach (var id in ids) { var app = await indexForApps.GetAppAsync(id); if (app != null && app.Patterns.Count == 0) { foreach (var pattern in initialPatterns.Values) { var command = new AddPattern { Actor = app.CreatedBy, AppId = id, Name = pattern.Name, PatternId = Guid.NewGuid(), Pattern = pattern.Pattern, Message = pattern.Message }; await commandBus.PublishAsync(command); } } } }
public void CanAdd_should_throw_exception_if_pattern_not_valid() { var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = "[0-9{1}" }; Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_0, command)); }
public void CanAdd_should_throw_exception_if_pattern_empty() { var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = string.Empty }; Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_0, command)); }
public void CanAdd_should_not_throw_exception_if_command_is_valid() { var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = ".*" }; GuardAppPatterns.CanAdd(patterns_0, command); }
public AppDomainObject AddPattern(AddPattern command) { ThrowIfNotCreated(); RaiseEvent(SimpleMapper.Map(command, new AppPatternAdded())); return(this); }
public void CanAdd_should_throw_exception_if_id_empty_guid() { var command = new AddPattern { Name = string.Empty, Pattern = ".*" }; Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_0, command)); }
protected Task On(AddPattern command, CommandContext context) { return(handler.UpdateSyncedAsync <AppDomainObject>(context, a => { GuardAppPattern.CanAdd(a.Snapshot.Patterns, command); a.AddPattern(command); })); }
public void CanAdd_should_throw_exception_if_pattern_not_valid() { var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = "[0-9{1}" }; ValidationAssert.Throws(() => GuardAppPatterns.CanAdd(patterns_0, command), new ValidationError("Pattern is not a valid value.", "Pattern")); }
public void CanAdd_should_throw_exception_if_pattern_empty() { var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = string.Empty }; ValidationAssert.Throws(() => GuardAppPatterns.CanAdd(patterns_0, command), new ValidationError("Pattern is required.", "Pattern")); }
public void CanAdd_should_throw_exception_if_name_empty() { var command = new AddPattern { PatternId = patternId, Name = string.Empty, Pattern = ".*" }; ValidationAssert.Throws(() => GuardAppPatterns.CanAdd(command, App(patterns_0)), new ValidationError("Name is required.", "Name")); }
public async Task Should_assign_app_id_to_app_self_command() { var command = new AddPattern(); var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); Assert.Equal(appId.Id, command.AppId); }
public void CanAdd_should_throw_exception_if_name_exists() { var patterns_1 = patterns_0.Add(Guid.NewGuid(), "any", "[a-z]", "Message"); var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = ".*" }; Assert.Throws <ValidationException>(() => GuardAppPattern.CanAdd(patterns_1, command)); }
public async Task Should_not_override_app_id() { var command = new AddPattern { AppId = Guid.NewGuid() }; var context = new CommandContext(command, commandBus); await sut.HandleAsync(context); Assert.NotEqual(appId.Id, command.AppId); }
public void CanAdd_should_throw_exception_if_name_exists() { var patterns_1 = patterns_0.Add(DomainId.NewGuid(), "any", "[a-z]", "Message"); var command = new AddPattern { PatternId = patternId, Name = "any", Pattern = ".*" }; ValidationAssert.Throws(() => GuardAppPatterns.CanAdd(patterns_1, command), new ValidationError("A pattern with the same name already exists.")); }
public void CanAdd_should_throw_exception_if_pattern_exists() { var patterns_1 = patterns_0.Add(DomainId.NewGuid(), "any", "[a-z]", "Message"); var command = new AddPattern { PatternId = patternId, Name = "other", Pattern = "[a-z]" }; ValidationAssert.Throws(() => GuardAppPatterns.CanAdd(patterns_1, command), new ValidationError("This pattern already exists but with another name.")); }
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(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(initialPatterns.Count + 1, sut.Snapshot.Patterns.Count); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppPatternAdded { PatternId = patternId3, Name = "Any", Pattern = ".*", Message = "Msg" }) ); }
public static void CanAdd(AddPattern command, IAppEntity app) { Guard.NotNull(command, nameof(command)); var patterns = app.Patterns; Validate.It(e => { if (command.PatternId == DomainId.Empty) { e(Not.Defined(nameof(command.PatternId)), nameof(command.PatternId)); } if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined(nameof(command.Name)), nameof(command.Name)); } if (patterns.Values.Any(x => x.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase))) { e(T.Get("apps.patterns.nameAlreadyExists")); } if (string.IsNullOrWhiteSpace(command.Pattern)) { e(Not.Defined(nameof(command.Pattern)), nameof(command.Pattern)); } else if (!command.Pattern.IsValidRegex()) { e(Not.Valid(nameof(command.Pattern)), nameof(command.Pattern)); } if (patterns.Values.Any(x => x.Pattern == command.Pattern)) { e(T.Get("apps.patterns.patternAlreadyExists")); } }); }
public static void CanAdd(AppPatterns patterns, AddPattern command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot add pattern.", e => { if (command.PatternId == Guid.Empty) { e(Not.Defined("Id"), nameof(command.PatternId)); } if (string.IsNullOrWhiteSpace(command.Name)) { e(Not.Defined("Name"), nameof(command.Name)); } if (patterns.Values.Any(x => x.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase))) { e("A pattern with the same name already exists."); } if (string.IsNullOrWhiteSpace(command.Pattern)) { e(Not.Defined("Pattern"), nameof(command.Pattern)); } else if (!command.Pattern.IsValidRegex()) { e(Not.Valid("Pattern"), nameof(command.Pattern)); } if (patterns.Values.Any(x => x.Pattern == command.Pattern)) { e("This pattern already exists but with another name."); } }); }
private void AddPattern(AddPattern command) { Raise(command, new AppPatternAdded()); }
public void AddPattern(AddPattern command) { Raise(command, new AppPatternAdded()); }
public static AppPatternDto FromCommand(AddPattern command) { return(SimpleMapper.Map(command, new AppPatternDto())); }
public void AddPattern(AddPattern command) { RaiseEvent(SimpleMapper.Map(command, new AppPatternAdded())); }
private void MainWindow_AddPattern(object sender, RoutedEventArgs e) { AddPattern?.Invoke(this, e); }