public void Can_get_set_indexer() { var entity = new Entity("entity") { Id = Guid.NewGuid() }; var txEntity = new TransactionContextEntity <Entity>(entity) { ["xts_attribute"] = new Money(2500m) }; Assert.Equal(2500m, ((Money)txEntity["xts_attribute"]).Value); Assert.Equal(2500m, ((Money)entity["xts_attribute"]).Value); }
public void Can_create_command() { var context = Substitute.For <ITransactionContext <Entity> >(); var reference = new Entity("entity", Guid.NewGuid()); var txReference = new TransactionContextEntity <Entity>(reference); context.Current.Returns(txReference); var input = new Entity("entity", reference.Id); var txInput = new TransactionContextEntity <Entity>(input); context.Target.Returns(txInput); var command = new Command(context); Assert.NotNull(command.PublicWrapper); Assert.Same(reference, command.PublicWrapper.Entity); }
public void Can_copy_attribute_value() { var id = Guid.NewGuid(); var sourceEntity = new Entity("entity") { Id = id, FormattedValues = { ["attribute"] = "$100.00" } }; var source = new TransactionContextEntity <Entity>(sourceEntity); var currentEntity = new Entity("entity") { Id = id, FormattedValues = { ["optionsetvalue"] = "Release" } }; var current = new TransactionContextEntity <Entity>(currentEntity); var actionContext = new CurrentActionContext { TransactionContext = null, Target = source, Current = current }; var action = new CopyValueEventCurrentAction(); action.Execute(actionContext); source["attribute"] = new Money(100m); Assert.Equal(100m, current.Get <Money>("attribute").Value); Assert.Equal("$100.00", current.Entity.FormattedValues["attribute"]); Assert.Equal("Release", current.Entity.FormattedValues["optionsetvalue"]); source["optionsetvalue"] = new OptionSetValue(12); Assert.Equal(12, current.Get <OptionSetValue>("optionsetvalue").Value); Assert.Equal("$100.00", current.Entity.FormattedValues["attribute"]); Assert.Null(current.Entity.FormattedValues["optionsetvalue"]); source.SetFormattedValue("new_format", "Formatted-Value"); Assert.Equal("Formatted-Value", current.Entity.FormattedValues["new_format"]); }
public void Can_access_wrapper(string message, int stage) { var pluginContext = Substitute.For <IPluginExecutionContext>(); pluginContext.MessageName.Returns(message); pluginContext.Stage.Returns(stage); var referenceEntity = new Entity("reference"); var reference = new TransactionContextEntity <Entity>(referenceEntity); var context = Substitute.For <ITransactionContext <Entity> >(); context.PluginExecutionContext.Returns(pluginContext); context.Current.Returns(reference); var operation = new Operation(context); Assert.Equal(referenceEntity, operation.PublicWrapper.Entity); }
public void Can_copy_attribute_value_from_ms_generated_entity() { var id = Guid.NewGuid(); var sourceEntity = new MsGenerated.Account { Id = id, FormattedValues = { ["creditlimit"] = "$100.00" } }; var source = new TransactionContextEntity <MsGenerated.Account>(sourceEntity); var currentEntity = new MsGenerated.Account { Id = id, FormattedValues = { ["accountratingcode"] = "Release" } }; var current = new TransactionContextEntity <MsGenerated.Account>(currentEntity); var actionContext = new CurrentActionContext { TransactionContext = null, Target = source, Current = current }; var action = new CopyValueEventCurrentAction(); action.Execute(actionContext); source.Set(e => e.CreditLimit, new Money(100m)); Assert.Equal(100m, current.Get <Money>("creditlimit").Value); Assert.Equal("$100.00", current.Entity.FormattedValues["creditlimit"]); Assert.Equal("Release", current.Entity.FormattedValues["accountratingcode"]); source.Entity.AccountRatingCode = new OptionSetValue(12); Assert.Equal(12, current.Get <OptionSetValue>("accountratingcode").Value); Assert.Equal("$100.00", current.Entity.FormattedValues["creditlimit"]); Assert.Null(current.Entity.FormattedValues["accountratingcode"]); }
public void Can_access_update(string message, int stage) { var pluginContext = Substitute.For <IPluginExecutionContext>(); pluginContext.MessageName.Returns(message); pluginContext.Stage.Returns(stage); var inputEntity = new Entity("input"); var input = new TransactionContextEntity <Entity>(inputEntity); var context = Substitute.For <ITransactionContext <Entity> >(); context.PluginExecutionContext.Returns(pluginContext); context.Target.Returns(input); var operation = new Operation(context); Assert.Equal(input, operation.PublicInput); var update = operation.PublicInput; // other retrieve. var temp = context.Received(2).Target; }
public void Can_access_wrapper_generic(string message, int stage) { var pluginContext = Substitute.For <IPluginExecutionContext>(); pluginContext.MessageName.Returns(message); pluginContext.Stage.Returns(stage); var referenceEntity = new xts_entity { Id = Guid.NewGuid() }; var reference = new TransactionContextEntity <xts_entity>(referenceEntity); var context = Substitute.For <ITransactionContext <xts_entity> >(); context.PluginExecutionContext.Returns(pluginContext); context.Current.Returns(reference); Assert.Equal(referenceEntity.ToEntityReference(), ((ITransactionContext <Entity>)context).Current.Entity.ToEntityReference()); var operation = new WrapperOperation(context); Assert.Equal(referenceEntity.ToEntityReference(), operation.PublicWrapper.Entity.ToEntityReference()); }
public void Can_create_command_generic() { var context = Substitute.For <ITransactionContext <xts_entity> >(); var reference = new xts_entity { Id = Guid.NewGuid() }; var txReference = new TransactionContextEntity <xts_entity>(reference); context.Current.Returns(txReference); Assert.Same(reference, context.Current.Entity); var input = new xts_entity { Id = reference.Id }; var txInput = new TransactionContextEntity <xts_entity>(input); context.Target.Returns(txInput); var command = new CommandGeneric(context); Assert.NotNull(command.PublicWrapper); Assert.Same(reference, command.PublicWrapper.Entity); }
public void Can_copy_attribute_values(int stage) { var id = Guid.NewGuid(); var reference = new EntityReference("entity", Guid.NewGuid()) { Name = "name" }; var optionSet = new OptionSetValue(1); var money = new Money(100m); var number = 123; var source = new Entity { ["attr_1"] = id, ["attr_2"] = reference, ["attr_3"] = optionSet, ["attr_4"] = money, ["attr_5"] = number, FormattedValues = { ["attr_3"] = "Release", ["attr_4"] = "Rp100.000,45" } }; var txSource = new TransactionContextEntity <Entity>(source); var target = new Entity { ["attr_1"] = Guid.NewGuid(), ["attr_2"] = new EntityReference("entity", Guid.NewGuid()) { Name = "another-name" }, ["attr_3"] = new OptionSetValue(2), ["attr_4"] = new Money(125m), ["attr_5"] = 345, ["attr_6"] = new Money(700m) }; var txTarget = new TransactionContextEntity <Entity>(target); var context = Substitute.For <ICurrentActionContext>(); context.TransactionContext.PluginExecutionContext.Stage.Returns(stage); context.Target.Returns(txSource); context.Current.Returns(txTarget); var action = new CopyToCurrentAction(); action.Execute(context); Assert.Equal(6, txTarget.Attributes.Count); Assert.Equal(id, txTarget["attr_1"]); Assert.NotSame(reference, txTarget["attr_2"]); Assert.Equal(reference, txTarget["attr_2"]); Assert.Equal(reference.Name, ((EntityReference)txTarget["attr_2"]).Name); Assert.NotSame(optionSet, txTarget["attr_3"]); Assert.Equal(optionSet, txTarget["attr_3"]); Assert.NotSame(money, txTarget["attr_4"]); Assert.Equal(money, txTarget["attr_4"]); Assert.Equal(number, txTarget["attr_5"]); Assert.Equal(700m, ((Money)txTarget["attr_6"]).Value); Assert.Equal("Release", target.FormattedValues["attr_3"]); Assert.Equal("Rp100.000,45", target.FormattedValues["attr_4"]); }