public void Can_get_name_from_entity_reference_query_using_metadata()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity.Set(e => e.xts_string, "Hello world");

            var service = Substitute.For <IOrganizationService>();

            service.Retrieve(Arg.Is <string>(name => name == "xts_entity"), Arg.Any <Guid>(), Arg.Any <ColumnSet>())
            .Returns(entity);

            var metadata = new EntityMetadata
            {
                LogicalName = "xts_entity"
            };

            typeof(EntityMetadata).GetProperty("PrimaryNameAttribute").SetValue(metadata, "xts_string");
            service.Execute(Arg.Is <OrganizationRequest>(req => req is RetrieveEntityRequest))
            .Returns(ci =>
            {
                var request = ci.ArgAt <RetrieveEntityRequest>(0);
                Assert.Equal("xts_entity", request.LogicalName);
                Assert.Equal(EntityFilters.Entity, request.EntityFilters);
                return(new RetrieveEntityResponse
                {
                    ["EntityMetadata"] = metadata
                });
            });

            Assert.Equal("Hello world", service.GetReferenceName <xts_entity>(entity.ToEntityReference()));
        }
Example #2
0
        public void TransactionContextEntityGeneric_ToEntityReference()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };
            var txEntity = new TransactionContextEntity <xts_entity>(entity);

            Assert.Equal(entity.ToEntityReference(), txEntity.ToEntityReference());
        }
        public void Can_convert_entity_to_entity_accessor()
        {
            var entity   = new Entity("xts_entity", Guid.NewGuid());
            var accessor = entity.ToEntityAccessor <xts_entity>();

            Assert.Equal(entity.ToEntityReference(), accessor.Entity.ToEntityReference());

            var earlyBoundEntity = new xts_entity {
                Id = Guid.NewGuid()
            };
            var earlyBoundAccessor = earlyBoundEntity.ToEntityAccessor();

            Assert.Equal(earlyBoundEntity.ToEntityReference(), earlyBoundAccessor.Entity.ToEntityReference());
        }