public void SynchronizeChangesAddedItemTest() { var sourceGameWorld = new TestGameWorld(); sourceGameWorld.RandomIntProperty = 5; var syncSourceRoot = new SyncSourceRoot(sourceGameWorld, _sourceSettings); var syncTargetRoot = new SyncTargetRoot <TestGameWorld>(syncSourceRoot.WriteFullAndDispose(), _targetSettings); sourceGameWorld.Players.Add("player1", new TestPlayer { Health = 100, Level = 30 }); sourceGameWorld.Players.Add("player2", new TestPlayer { Health = 44, Level = 1337 }); syncTargetRoot.Read(syncSourceRoot.WriteChangesAndDispose().SetTick(0)); TestGameWorld targetGameWorld = syncTargetRoot.Root; AssertExtension.AssertCloneEqual(sourceGameWorld, targetGameWorld); }
public void ObservableDictionaryAddItemTest() { var sourceDictionary = new ObservableDictionary <int, string>(); sourceDictionary.Add(1, "1"); sourceDictionary.Add(2, "2"); // Full write var syncSourceRoot = new SyncSourceRoot(sourceDictionary, _sourceSettings); var syncTargetRoot = new SyncTargetRoot <ObservableDictionary <int, string> >(syncSourceRoot.WriteFullAndDispose(), _targetSettings); ObservableDictionary <int, string> targetDictionary = syncTargetRoot.Root; foreach (KeyValuePair <int, string> keyValuePair in sourceDictionary) { Assert.Equal(keyValuePair.Value, targetDictionary[keyValuePair.Key]); } // Changes sourceDictionary.Add(3, "3"); byte[] changesSynchronization = syncSourceRoot.WriteChangesAndDispose().SetTick(0); syncTargetRoot.Read(changesSynchronization); foreach (KeyValuePair <int, string> keyValuePair in sourceDictionary) { Assert.Equal(keyValuePair.Value, targetDictionary[keyValuePair.Key]); } }
public InterpolationState(SyncTargetProperty syncTargetProperty, SyncTargetRoot syncTargetRoot, IFieldSerializer fieldSerializer) { _synchronizedValue = syncTargetProperty.Property; _syncTargetProperty = syncTargetProperty; _syncTargetRoot = syncTargetRoot; _fieldSerializer = fieldSerializer; }
public SyncTarget Create(int referenceId, Type baseType, ExtendedBinaryReader reader, IFieldSerializerResolver fieldDeserializerResolver, SyncTargetRoot root) { Type[] genericArgs = baseType.GetGenericArguments(); Type observableDictionarySyncSourceObjectType = typeof(ObservableDictionarySyncTarget <,>).MakeGenericType(genericArgs); return((SyncTarget)Activator.CreateInstance(observableDictionarySyncSourceObjectType, referenceId, baseType, reader, root, fieldDeserializerResolver)); }
public void PropertiesUsedInConstructorShouldNotSynchronizeOnConstructionTest() { var sourceConstructorMock = new SynchronizeConstructorMock(); var syncSourceRoot = new SyncSourceRoot(sourceConstructorMock, _sourceSettings); var syncTargetRoot = new SyncTargetRoot <SynchronizeConstructorMock>(syncSourceRoot.WriteFullAndDispose(), _targetSettings); SynchronizeConstructorMock targetConstructorMock = syncTargetRoot.Root; Assert.Equal(1, targetConstructorMock.DictionarySetCount); }
public void WriteChangesShouldCreateNewReferenceTest() { var sourceGameWorld = new TestGameWorld { RandomIntProperty = 5 }; var syncSourceRoot = new SyncSourceRoot(sourceGameWorld, _sourceSettings); var syncTargetRoot = new SyncTargetRoot <TestGameWorld>(syncSourceRoot.WriteFullAndDispose(), _targetSettings); TestGameWorld previousTargetTestGameWorld = syncTargetRoot.Root; syncTargetRoot.Read(syncSourceRoot.WriteChangesAndDispose().SetTick(0)); Assert.Equal(previousTargetTestGameWorld, syncTargetRoot.Root); }
public void SyncConstructorShouldBeCalledTest() { var sourceConstructorMock = new SynchronizeConstructorMock(); var syncSourceRoot = new SyncSourceRoot(sourceConstructorMock, _sourceSettings); var syncTargetRoot = new SyncTargetRoot <SynchronizeConstructorMock>(syncSourceRoot.WriteFullAndDispose(), _targetSettings); syncTargetRoot.Read(syncSourceRoot.WriteChangesAndDispose().SetTick(0)); SynchronizeConstructorMock targetConstructorMock = syncTargetRoot.Root; Assert.True(targetConstructorMock.SyncConstructorCalled); }
public ObservableDictionarySyncTarget(int referenceId, Type baseType, ExtendedBinaryReader reader, SyncTargetRoot syncTargetRoot, IFieldSerializerResolver fieldDeserializerResolver) : base(referenceId) { _syncTargetRoot = syncTargetRoot; _clock = _syncTargetRoot.Clock; base.BaseObject = Activator.CreateInstance(baseType); BaseObject.CollectionChanged += OnCollectionChanged; _keySerializer = fieldDeserializerResolver.FindMatchingSerializer(typeof(TKey)); _valueSerializer = fieldDeserializerResolver.FindMatchingSerializer(typeof(TValue)); _syncTargetRoot.EndRead += EndRead; Read(reader); }
public NotifyPropertyChangedSyncTarget(int referenceId, Type baseType, ExtendedBinaryReader reader, SyncTargetRoot syncTargetRoot, IFieldSerializerResolver fieldDeserializerResolver) : base(referenceId) { _syncTargetRoot = syncTargetRoot; ConstructorInfo attributeMarkedConstructor = GetAttributeMarkedConstructor(baseType); bool attributeMarkedConstructorPresent = attributeMarkedConstructor != null; base.BaseObject = attributeMarkedConstructorPresent ? FormatterServices.GetUninitializedObject(baseType) : Activator.CreateInstance(baseType); BaseObject.PropertyChanged += TargetOnPropertyChanged; (PropertyInfo info, SyncAttribute attibute)[] syncPropertiesInfo = GetProperties();
public void RemovingAChangedReferenceShouldAlsoRemoveItFromDirtyListTest() { var world = new TestGameWorld(); var player = new TestPlayer(); world.Players.Add("player", player); var syncSourceRoot = new SyncSourceRoot(world, _sourceSettings); var syncTargetRoot = new SyncTargetRoot(syncSourceRoot.WriteFullAndDispose(), _targetSettings); player.Health = 3; world.Players.Remove("player"); // Changes are removed after write syncSourceRoot.WriteChangesAndDispose().SetTick(0); Assert.DoesNotContain(player, syncSourceRoot.DirtyReferences); }
public void MoreThanEightSyncAttributesTest() { var sourceTestMock = new SynchronizeManySyncAttributesTest() { Test = 0, Test2 = 2, Test3 = 34, Test4 = 43, Test5 = 122, Test6 = 99999999.32423, Test7 = 3434, Test8 = 23, Test9 = 2 }; var syncSourceRoot = new SyncSourceRoot(sourceTestMock, _sourceSettings); var target = new SyncTargetRoot <SynchronizeManySyncAttributesTest>(syncSourceRoot.WriteFullAndDispose(), _targetSettings); AssertExtension.AssertCloneEqual(sourceTestMock, target.Root); }
public SyncTarget Create(int referenceId, Type baseType, ExtendedBinaryReader reader, IFieldSerializerResolver fieldSerializerResolver, SyncTargetRoot root) { return(new StringSyncTarget(referenceId, reader)); }
public SyncTarget Create(int referenceId, Type baseType, ExtendedBinaryReader reader, IFieldSerializerResolver fieldSerializerResolver, SyncTargetRoot clock) { return(new NotifyPropertyChangedSyncTarget(referenceId, baseType, reader, clock, fieldSerializerResolver)); }
public LatestTickState(SyncTargetProperty syncTargetProperty, SyncTargetRoot syncTargetRoot) { _syncTargetProperty = syncTargetProperty; _syncTargetRoot = syncTargetRoot; }