public void Can_set_formatted_value_generic()
        {
            var entity = new xts_entity();

            entity.SetFormattedValue(e => e.xts_optionsetvalue, "formatted-value-4567");
            Assert.Equal("formatted-value-4567", entity.FormattedValues["xts_optionsetvalue"]);
        }
        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()));
        }
        public void Can_get_formatted_value_generic()
        {
            var entity = new xts_entity();

            entity.FormattedValues["xts_optionsetvalue"] = "formatted-value-4567";
            Assert.Equal("formatted-value-4567", entity.GetFormattedValue(e => e.xts_optionsetvalue));
            Assert.Null(entity.GetFormattedValue(e => e.xts_decimal));
        }
Beispiel #4
0
        public void Can_set_formatted_value()
        {
            var entity   = new xts_entity();
            var accessor = new EntityAccessor <xts_entity>(entity);

            accessor.SetFormattedValue("xts_attribute", "formatted-value-1234");
            Assert.Equal("formatted-value-1234", entity.FormattedValues["xts_attribute"]);
        }
Beispiel #5
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());
        }
Beispiel #6
0
        public void Can_set_money_using_decimal()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };
            var accessor = new EntityAccessor <xts_entity>(entity);

            accessor.Set(e => e.xts_money, 1234);
            Assert.Equal(1234m, accessor.Get(e => e.xts_money).Value);
        }
        public void Can_set_option_set_value_using_enum()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity.Set(e => e.xts_optionsetvalue, TestOptions.SomeValue);

            Assert.Equal(47, entity.Get(e => e.xts_optionsetvalue).Value);
        }
        public void Can_remove_attribute_generic()
        {
            var entity = new xts_entity();

            entity.Set(e => e.xts_decimal, 1234);

            Assert.True(entity.Contains("xts_decimal"));
            entity.Remove(e => e.xts_decimal);
            Assert.False(entity.Contains("xts_decimal"));
        }
        public void Can_set_money_using_decimal()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity.Set(e => e.xts_money, 1234);

            Assert.Equal(1234m, entity.Get(e => e.xts_money).Value);
        }
Beispiel #10
0
        public void Can_get_formatted_value()
        {
            var entity = new xts_entity();

            entity.FormattedValues["xts_attribute"] = "formatted-value-1234";
            var accessor = new EntityAccessor <xts_entity>(entity);

            Assert.Equal("formatted-value-1234", accessor.GetFormattedValue("xts_attribute"));
            Assert.Null(entity.GetFormattedValue("xts_notexist"));
        }
Beispiel #11
0
        public void Can_set_option_set_value_using_int()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };
            var accessor = new EntityAccessor <xts_entity>(entity);

            accessor.Set(e => e.xts_optionsetvalue, 12);
            Assert.Equal(12, accessor.Get(e => e.xts_optionsetvalue).Value);
        }
        public void Can_get_attribute_name_from_custom_entity()
        {
            var entity = new xts_entity();

            Assert.Equal("xts_entityid", Helper.Name <xts_entity>(e => e.Id));
            Assert.Equal("xts_entityid", entity.Name(e => e.Id));
            Assert.Equal("xts_column", Helper.Name <xts_entity>(e => e.xts_withcolumnattribute));
            Assert.Equal("xts_column", entity.Name(e => e.xts_withcolumnattribute));
            Assert.Equal("attributewithcasechar", Helper.Name <xts_entity>(e => e.AttributeWithCaseChar));
            Assert.Equal("attributewithcasechar", entity.Name(e => e.AttributeWithCaseChar));
        }
        public void ContainsAny_generic_many_criterias(Expression <Func <xts_entity, object> >[] contains, bool expected)
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity["xts_attribute"] = null;
            var actual = entity.ContainsAny(contains.First(), contains.Skip(1).ToArray());

            Assert.Equal(expected, actual);
        }
        public void ContainsAny_generic_one_criteria()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity["xts_attribute"] = null;

            Assert.False(entity.ContainsAny(e => e.AttributeWithCaseChar));
            Assert.True(entity.ContainsAny(e => e.xts_attribute));
        }
        public void Can_get_attribute_value()
        {
            var entity = new xts_entity
            {
                Id = Guid.NewGuid()
            };
            var reference = new EntityReference("reference", Guid.NewGuid());

            entity["xts_attribute"] = reference;

            Assert.Equal(reference, entity.Get <EntityReference>("xts_attribute"));
        }
        public void Can_set_attribute_value_generic()
        {
            var entity = new xts_entity
            {
                Id = Guid.NewGuid()
            };
            var reference = new EntityReference("reference", Guid.NewGuid());

            entity.Set(e => e.xts_attribute, reference);

            Assert.Equal(reference, entity["xts_attribute"]);
        }
Beispiel #17
0
        [Fact] // Assume ActivityParty
        public void Can_set_entity_collection_using_single_entity_reference()
        {
            var entityReference = new EntityReference("equipment", Guid.NewGuid());
            var entity          = new xts_entity();
            var accessor        = new EntityAccessor <xts_entity>(entity);

            accessor.Set(e => e.xts_activityparties, entityReference);

            var collection    = accessor.Get(e => e.xts_activityparties);
            var activityParty = collection.Entities[0].ToEntity <ActivityParty>();

            Assert.Equal(entityReference, activityParty.Get(e => e.PartyId));
        }
Beispiel #18
0
        public void Can_set_attribute_value()
        {
            var entity = new xts_entity
            {
                Id = Guid.NewGuid()
            };
            var accessor  = new EntityAccessor <xts_entity>(entity);
            var reference = new EntityReference("reference", Guid.NewGuid());

            accessor.Set("xts_attribute", reference);

            Assert.Equal(reference, entity["xts_attribute"]);
        }
        public void Can_set_money_from_decimal_value_provider()
        {
            var decimalValueProvider = Substitute.For <IValueProvider <decimal> >();

            decimalValueProvider.GetValue().Returns(1500m);

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

            entity.Set(e => e.xts_money, decimalValueProvider);

            Assert.Equal(1500m, entity.Get(e => e.xts_money).Value);
        }
        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());
        }
        public void Can_set_through_value_provider_generic()
        {
            var valueProvider = Substitute.For <IValueProvider <string> >();

            valueProvider.GetValue().Returns("1234");

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

            entity.Set(e => e.xts_string, valueProvider);

            Assert.Equal("1234", entity.Get(e => e.xts_string));
        }
        public void Can_set_through_attribute_value_provider_generic()
        {
            var valueProvider = Substitute.For <IAttributeValueProvider <xts_entity, string> >();

            valueProvider.GetValueFor(Arg.Any <Expression <Func <xts_entity, string> > >()).Returns("1234");

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

            entity.Set(e => e.xts_string, valueProvider);

            Assert.Equal("1234", entity.Get(e => e.xts_string));
        }
Beispiel #23
0
        public void Can_box_expression()
        {
            Expression <Func <xts_entity, DateTime?> > dateTimeExpression = e => e.Get(x => x.xts_datetime);
            var boxedExpression = Helper.BoxExpression(dateTimeExpression);

            var dateTime = DateTime.UtcNow;
            var entity   = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity.Set(e => e.xts_datetime, dateTime);

            Assert.Equal(dateTime, boxedExpression.Compile().Invoke(entity));
        }
Beispiel #24
0
        public void Can_get_attribute_value_generic()
        {
            var entity = new xts_entity
            {
                Id = Guid.NewGuid()
            };
            var reference = new EntityReference("reference", Guid.NewGuid());

            entity["xts_attribute"] = reference;

            var accessor = new EntityAccessor <xts_entity>(entity);

            Assert.Equal(reference, accessor.Get(e => e.xts_attribute));
        }
        public void Can_get_money_value()
        {
            var entity = new xts_entity
            {
                Id = Guid.NewGuid()
            };

            entity["xts_money"] = null;

            Assert.Equal(0m, entity.GetValue(e => e.xts_money));
            Assert.Equal(10m, entity.GetValue(e => e.xts_money, 10m));

            entity["xts_money"] = new Money(250m);
            Assert.Equal(250m, entity.GetValue(e => e.xts_money, 250m));
        }
Beispiel #26
0
        [Fact] // Assume ActivityParty
        public void Can_set_entity_collection_using_entity_references()
        {
            var equipmentReference = new EntityReference("equipment", Guid.NewGuid());
            var leadReference      = new EntityReference("lead", Guid.NewGuid());
            var references         = new[] { equipmentReference, leadReference };
            var entity             = new xts_entity();
            var accessor           = new EntityAccessor <xts_entity>(entity);

            accessor.Set(e => e.xts_activityparties, references);

            var collection = accessor.Get(e => e.xts_activityparties);

            Assert.Equal(equipmentReference, collection.Entities[0].ToEntity <ActivityParty>().Get(e => e.PartyId));
            Assert.Equal(leadReference, collection.Entities[1].ToEntity <ActivityParty>().Get(e => e.PartyId));
        }
        public void Can_set_option_set_value_using_int()
        {
            var entity = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity.Set(e => e.xts_optionsetvalue, 12);

            Assert.Equal(12, entity.Get(e => e.xts_optionsetvalue).Value);

            entity.Set(e => e.xts_optionsetvalue, (int?)15);
            Assert.Equal(15, entity.Get(e => e.xts_optionsetvalue).Value);

            entity.Set(e => e.xts_optionsetvalue, (int?)null);
            Assert.Null(entity.Get(e => e.xts_optionsetvalue));
        }
Beispiel #28
0
        public void Can_use_equal_string_attribute_name()
        {
            var id        = Guid.NewGuid();
            var reference = new EntityReference("xts_reference", id);
            var entity    = new xts_entity {
                Id = Guid.NewGuid()
            };

            entity.Set(e => e.xts_referenceid, reference);
            var accessor = new EntityAccessor <xts_entity>(entity);

            var comparisonValue = new EntityReference("xts_reference", id);

            Assert.True(accessor.Equal("xts_referenceid", comparisonValue));
            Assert.False(accessor.Equal("xts_referenceid", new EntityReference("xts_reference", Guid.NewGuid())));
        }
Beispiel #29
0
        public void Can_get_money_value()
        {
            var entity = new xts_entity
            {
                Id = Guid.NewGuid()
            };

            entity["xts_money"] = null;

            var accessor = new EntityAccessor <xts_entity>(entity);

            Assert.Equal(0m, accessor.GetValue(e => e.xts_money));
            Assert.Equal(10m, accessor.GetValue(e => e.xts_money, 10m));

            entity["xts_money"] = new Money(250m);
            Assert.Equal(250m, accessor.GetValue(e => e.xts_money, 250m));
        }
Beispiel #30
0
        public void Can_get_value_nullable_type()
        {
            var entity   = new xts_entity();
            var accessor = new EntityAccessor <xts_entity>(entity);

            Assert.Equal(0, accessor.GetValue(e => e.xts_int));
            Assert.Equal(111, accessor.GetValue(e => e.xts_int, 111));
            entity.Set(e => e.xts_int, 123);
            Assert.Equal(123, accessor.GetValue(e => e.xts_int));
            Assert.Equal(123, accessor.GetValue(e => e.xts_int, 3333));

            Assert.Equal(0m, accessor.GetValue(e => e.xts_decimal));
            Assert.Equal(1000m, accessor.GetValue(e => e.xts_decimal, 1000m));
            entity.Set(e => e.xts_decimal, 2300m);
            Assert.Equal(2300m, accessor.GetValue(e => e.xts_decimal));
            Assert.Equal(2300m, accessor.GetValue(e => e.xts_decimal, 4000m));
        }