public MemberReplicationInfo(Type containerType, FieldReplicationInfo fieldReplicationInfo) { Behavior = fieldReplicationInfo.Behavior; IMemberAccessor memberAccessor = FieldAccessorBuilder.BuildFor(containerType, fieldReplicationInfo.Field, true); GetMember = memberAccessor.GetMember; SetMember = memberAccessor.SetMember; }
private static ReplicationStrategyFactory StrategyWhere <T>(ReplicationBehavior isMarkedAs) { var metadataProvider = A.Fake <IMetadataProvider>(x => x.Strict()); metadataProvider .CallsTo(x => x.GetPerTypeBehavior(typeof(T))) .Returns(isMarkedAs); metadataProvider .CallsTo(x => x.GetFieldsReplicationInfo(typeof(T))) .Returns(new FieldReplicationInfo[0]); return(new ReplicationStrategyFactory(metadataProvider)); }
private static ReplicationStrategyFactory StrategyForArrayOf <T>(ReplicationBehavior whereElementsAreMarkedAs) { var metadataProvider = A.Fake <IMetadataProvider>(x => x.Strict()); metadataProvider .CallsTo(x => x.GetPerTypeBehavior(typeof(T[]))) .Returns(ReplicationBehavior.DeepCopy); metadataProvider .CallsTo(x => x.GetPerTypeBehavior(typeof(T))) .Returns(whereElementsAreMarkedAs); metadataProvider .CallsTo(x => x.GetFieldsReplicationInfo(typeof(T))) .Returns(new FieldReplicationInfo[0]); return(new ReplicationStrategyFactory(metadataProvider)); }
/// <summary> /// Constructor for <see cref="CustomReplicationBehaviorAttribute"/>. /// </summary> public CustomReplicationBehaviorAttribute(ReplicationBehavior replicationBehavior) { this.replicationBehavior = replicationBehavior; }
public void GetBehaviorForAnnotatedStruct_BehaviorFromAnnotationReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(AnnotatedStruct)); Assert.That(result, Is.EqualTo(ReplicationBehavior.DeepCopy)); }
public void GetBehaviorForStruct_CopyReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(ConsoleKeyInfo)); Assert.That(result, Is.EqualTo(ReplicationBehavior.Copy)); }
public void GetBehaviorForDelegate_IgnoreReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(Func <int>)); Assert.That(result, Is.EqualTo(ReplicationBehavior.Ignore)); }
/// <summary> /// Constructor for <see cref="FieldReplicationInfo"/> /// </summary> public FieldReplicationInfo(FieldInfo field, ReplicationBehavior behavior) { Field = field; Behavior = behavior; }
public void GetBehaviorForArray_ReplicateReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(char[])); Assert.That(result, Is.EqualTo(ReplicationBehavior.DeepCopy)); }
public void GetBehaviorForNullableStruct_ReplicateReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(SomeValueType?)); Assert.That(result, Is.EqualTo(ReplicationBehavior.DeepCopy)); }
public void GetBehaviorForNullableInt_CopyOnlyReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(int?)); Assert.That(result, Is.EqualTo(ReplicationBehavior.Copy)); }
public void GetBehaviorForPrimitiveType_CopyOnlyReturned() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(UInt64)); Assert.That(result, Is.EqualTo(ReplicationBehavior.Copy)); }
public Replicator(IDataStore destination, ReplicationBehavior behavior) : this(destination, behavior, false) { }
private static IMetadataProvider MetadataProviderFor <T>(Expression <Func <T, object> > member, ReplicationBehavior returnsBehavior) { Expression memberAccess = member.Body is UnaryExpression ? member.Body.As <UnaryExpression>().Operand : member.Body; var fieldInfo = memberAccess.As <MemberExpression>().Member.As <FieldInfo>(); var metadataProvider = A.Fake <IMetadataProvider>(); metadataProvider .CallsTo(x => x.GetFieldsReplicationInfo(typeof(T))) .Returns(new[] { new FieldReplicationInfo(fieldInfo, returnsBehavior) }); return(metadataProvider); }
public void WhenTypeIsMarkedWithAttribute_GetBehaviorReturnsBehaviorFromAttribute() { ReplicationBehavior result = metadataProvider.GetPerTypeBehavior(typeof(Class)); Assert.That(result, Is.EqualTo(ReplicationBehavior.Ignore)); }