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)); }
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_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)); }
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); }
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_set_nullable_value_type_through_value_provider_generic_value_type() { var intValueProvider = Substitute.For <IValueProvider <int> >(); intValueProvider.GetValue().Returns(1234); var entity = new xts_entity { Id = Guid.NewGuid() }; entity.Set(e => e.xts_int, intValueProvider); Assert.Equal(1234, entity.Get(e => e.xts_int)); var date = new DateTime(2017, 3, 2); var dateValueProvider = Substitute.For <IValueProvider <DateTime> >(); dateValueProvider.GetValue().Returns(date); entity.Set(e => e.xts_datetime, dateValueProvider); Assert.Equal(date, entity.Get(e => e.xts_datetime)); }
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"]); }
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_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)); }
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)); }
public void Can_get_aliased_entity() { var entity = new xts_entity { Id = Guid.NewGuid() }; entity.Set(e => e.xts_int, 123); entity.Set(e => e.xts_money, 200m); entity["rel.xts_money"] = new AliasedValue( "xts_relatedentity", "xts_money", new Money(450m) ); entity["rel.xts_column"] = new AliasedValue( "xts_relatedentity", "xts_column", "MY-ALIASED-TEXT" ); var aliasedEntity = entity.GetAliasedEntity <xts_relatedentity>("rel"); Assert.Equal(450m, aliasedEntity.Get(e => e.xts_money).Value); Assert.Equal("MY-ALIASED-TEXT", aliasedEntity.Get(e => e.xts_withcolumnattribute)); }
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()))); }