public void Can_execute_command_methods() { var test = new TestHelper(); var related = new xts_relatedentity { Id = Guid.NewGuid() }; related.Set(e => e.xts_name, "RELATED"); var reference = new xts_entity { Id = Guid.NewGuid() }; reference.Set(e => e.xts_optionsetvalue, 12); reference.Set(e => e.xts_int, 345); reference.Set(e => e.xts_string, "PARENT"); reference.Set(e => e.xts_referenceid, related.ToEntityReference()); reference.Set(e => e.xts_money, new Money(1234m)); reference.SetFormattedValue(e => e.xts_attribute, "Hello Formatted Value"); reference.SetFormattedValue("xts_anotherattribute", "1234-another-fv"); var child = new xts_relatedentity { Id = Guid.NewGuid() }; child.Set(e => e.xts_name, "CHILD"); child.Set(e => e.xts_relatedid, reference.ToEntityReference()); test.Service.Retrieve(Arg.Any <string>(), Arg.Is <Guid>(id => id == related.Id), Arg.Any <ColumnSet>()) .Returns(related); test.Service.Retrieve(Arg.Any <string>(), Arg.Is <Guid>(id => id == child.Id), Arg.Any <ColumnSet>()) .Returns(child); test.Service.RetrieveMultiple(Arg.Any <QueryBase>()).Returns(new EntityCollection(new List <Entity> { child })); var context = Substitute.For <ITransactionContext <xts_entity> >(); context.Service.Returns(test.Service); var txReference = new TransactionContextEntity <xts_entity>(reference); context.Current.Returns(txReference); var commandTest = new CommandTest(context); commandTest.ExecuteTest(); IEntityWrapperRelation <xts_entity> wrapper = commandTest; var relatedColumnSet = new ColumnSet <xts_relatedentity>( e => e.Id, e => e.xts_name ); var relatedGeneric = wrapper.GetRelated(e => e.xts_referenceid, relatedColumnSet); Assert.Equal("RELATED", relatedGeneric.Get(e => e.xts_name)); }
public void Can_use_extensions() { var derived = new xts_derivedentity { Id = Guid.NewGuid() }; derived.Set(e => e.xts_string, "Hello world"); var related = new xts_relatedentity { Id = Guid.NewGuid() }; related.Set(e => e.xts_relatedid, derived.ToEntityReference()); var service = Substitute.For <IOrganizationService>(); service.Retrieve(Arg.Any <string>(), Arg.Is <Guid>(id => id == derived.Id), Arg.Any <ColumnSet>()) .Returns(derived); service.Retrieve(Arg.Any <string>(), Arg.Is <Guid>(id => id == related.Id), Arg.Any <ColumnSet>()) .Returns(related); var entity = new xts_entity { Id = Guid.NewGuid() }; entity.Set(e => e.xts_referenceid, related.ToEntityReference()); var context = Substitute.For <ITransactionContextBase>(); context.Service.Returns(service); var wrapper = new EntityWrapper <xts_entity>(entity, context); var text = wrapper .GetReference(new ColumnSet <xts_relatedentity>(e => e.xts_relatedid)) .GetProduct(new ColumnSet <xts_derivedentity>(e => e.xts_string)) .Get(e => e.xts_string); Assert.Equal("Hello world", text); }