protected override void Given() { var registry = new Registry(null); var registeredGraph = new RegisteredGraph<IsolatedClass>(registry); subject = new JsonSerializer<IsolatedClass>(registeredGraph); graph = new IsolatedClass {AProperty = "test property"}; session = Substitute.For<ISerializationSession>(); }
/// <summary> /// <paramref name="session"/> is used transiently in the constructor. /// </summary> /// <param name="session"></param> /// <param name="storedGraph"></param> /// <param name="registeredGraph"></param> public Track(ISerializationSession session, IStoredGraph storedGraph, IRegisteredGraph registeredGraph) { this.storedGraph = storedGraph; this.registeredGraph = registeredGraph; OriginalHash = hashCodeGenerator.ComputeHash(storedGraph.SerialisedGraph); //Reset stream after calculating hash. storedGraph.SerialisedGraph.Position = 0; UntypedGraph = registeredGraph.Deserialize(storedGraph.SerialisedGraph, session); }
public void Complete(IStorageWork work, ISerializationSession session) { storedGraph.SerialisedGraph = registeredGraph.Serialize(UntypedGraph, session); var trackedGraph = new TrackedGraph( storedGraph, CalculateIndexes(), registeredGraph); work.InsertGraph(trackedGraph); }
protected override void Given() { session = Substitute.For<ISerializationSession>(); var backingStore = Substitute.For<IBackingStore>(); var registry = new Registry(backingStore); registry.RegisterGraph<IsolatedClass>(); registry.RegisterGraph<ComposingClass>(); subject = new JsonSerializer<ComposingClass>((IRegisteredGraph<ComposingClass>)registry.RegisteredGraphs[typeof(ComposingClass)]); isolatedGraph = new IsolatedClass {AProperty = "test property"}; composingGraph = new ComposingClass {AnotherProperty = "another property", Composed = isolatedGraph}; expectedInternalId = new InternalId(Guid.NewGuid()); session.InternalIdOfTrackedGraph(isolatedGraph).Returns(expectedInternalId); }
protected override void Given() { session = Substitute.For<ISerializationSession>(); var backingStore = Substitute.For<IBackingStore>(); var registry = new Registry(backingStore); registry.RegisterGraph<IsolatedClass>(); registry.RegisterGraph<ComposingClass>(); subject = new JsonSerializer<ComposingClass>((IRegisteredGraph<ComposingClass>)registry.RegisteredGraphs[typeof(ComposingClass)]); expectedInternalId = new InternalId(Guid.NewGuid()); jsonSource = @"{""Composed"":{""__StashInternalId"":""" + expectedInternalId + @"""},""AnotherProperty"":""another property""}"; serialised = new PreservedMemoryStream(); using(var sw = new StreamWriter(serialised)) sw.Write(jsonSource); expected = new IsolatedClass(); session.TrackedGraphForInternalId(expectedInternalId).Returns(expected); }
public virtual void Complete(IStorageWork work, ISerializationSession session) { storedGraph.SerialisedGraph = registeredGraph.Serialize(UntypedGraph, session); CompletionHash = hashCodeGenerator.ComputeHash(storedGraph.SerialisedGraph); //Reset stream after calculating hash. storedGraph.SerialisedGraph.Position = 0; if(CompletionHash.SequenceEqual(OriginalHash)) //No change to object. No work to do. return; var trackedGraph = new TrackedGraph(storedGraph, CalculateIndexes(), registeredGraph); work.UpdateGraph(trackedGraph); }
public abstract Stream Serialize(object graph, ISerializationSession session);
public abstract object Deserialize(Stream serializedGraph, ISerializationSession session);
public void Complete(IStorageWork work, ISerializationSession session) { work.DeleteGraph(InternalId, registeredGraph); }