public static void CanSynchronize(SynchronizeSchema command) { Guard.NotNull(command, nameof(command)); Validate.It(e => { ValidateUpsert(command, e); }); }
public static void CanSynchronize(SynchronizeSchema command) { Guard.NotNull(command); Validate.It(() => "Cannot synchronize schema.", e => { ValidateUpsert(command, e); }); }
public async Task Synchronize_should_create_events_and_update_state() { var command = new SynchronizeSchema { Scripts = new SchemaScripts { Query = "<query-script" }, PreviewUrls = new Dictionary <string, string> { ["Web"] = "web-url" }, Fields = new List <UpsertSchemaField> { new UpsertSchemaField { Name = fieldId.Name, Properties = ValidProperties() } }, Category = "My-Category" }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(4)); Assert.NotNull(GetField(1)); Assert.Equal(command.Category, sut.Snapshot.SchemaDef.Category); Assert.Equal(command.Scripts, sut.Snapshot.SchemaDef.Scripts); Assert.Equal(command.PreviewUrls, sut.Snapshot.SchemaDef.PreviewUrls); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaCategoryChanged { Name = command.Category }), CreateEvent(new SchemaScriptsConfigured { Scripts = command.Scripts }), CreateEvent(new SchemaPreviewUrlsConfigured { PreviewUrls = command.PreviewUrls }), CreateEvent(new FieldAdded { FieldId = fieldId, Name = fieldId.Name, Properties = command.Fields[0].Properties, Partitioning = Partitioning.Invariant.Key }) ); }
public void Synchronize(SynchronizeSchema command) { var options = new SchemaSynchronizationOptions { NoFieldDeletion = command.NoFieldDeletion, NoFieldRecreation = command.NoFieldRecreation }; var schemaSource = Snapshot.SchemaDef; var schemaTarget = command.ToSchema(schemaSource.Name, schemaSource.IsSingleton); var events = schemaSource.Synchronize(schemaTarget, serializer, () => Snapshot.SchemaFieldsTotal + 1, options); foreach (var @event in events) { RaiseEvent(SimpleMapper.Map(command, (SchemaEvent)@event)); } }
private void Synchronize(SynchronizeSchema command) { var options = new SchemaSynchronizationOptions { NoFieldDeletion = command.NoFieldDeletion, NoFieldRecreation = command.NoFieldRecreation }; var schemaSource = Snapshot.SchemaDef; var schemaTarget = command.BuildSchema(schemaSource.Name, schemaSource.IsSingleton); var events = schemaSource.Synchronize(schemaTarget, () => Snapshot.SchemaFieldsTotal + 1, options); foreach (var @event in events) { Raise(command, @event); } }
public async Task Synchronize_should_create_events_and_update_state() { var command = new SynchronizeSchema { Category = "My-Category" }; await ExecuteCreateAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent2(sut.Snapshot); Assert.Equal(command.Category, sut.Snapshot.SchemaDef.Category); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaCategoryChanged { Name = command.Category }) ); }
public void Should_convert_upsert_command() { var command = new SynchronizeSchema { IsPublished = true, Properties = new SchemaProperties { Hints = "MyHints" }, Fields = new[] { new UpsertSchemaField { Name = "myString", IsDisabled = true, IsHidden = true, IsLocked = true, Properties = new StringFieldProperties { IsRequired = true }, Partitioning = "language" } }, FieldsInLists = FieldNames.Create("meta.id", "myString"), FieldsInReferences = FieldNames.Create("myString"), Scripts = new SchemaScripts { Change = "change-script" }, PreviewUrls = new Dictionary <string, string> { ["mobile"] = "http://mobile" }.ToReadonlyDictionary(), Category = "myCategory" }; var expected = new Schema("my-schema") .Update(new SchemaProperties { Hints = "MyHints" }) .AddString(1, "myString", Partitioning.Language, new StringFieldProperties { IsRequired = true }) .HideField(1).DisableField(1).LockField(1) .ChangeCategory("myCategory") .SetFieldsInLists(FieldNames.Create("meta.id", "myString")) .SetFieldsInReferences(FieldNames.Create("myString")) .SetScripts(new SchemaScripts { Change = "change-script" }) .SetPreviewUrls(new Dictionary <string, string> { ["mobile"] = "http://mobile" }.ToReadonlyDictionary()) .Publish(); var actual = command.BuildSchema("my-schema", SchemaType.Default); actual.Should().BeEquivalentTo(expected); }