public void StreamOperatorsAreGarbageCollectedOnSingleSubscriptionDisposal() { var storage = new InMemoryStorageEngine(); var source = new Source <int>(); var staticNonPersistable = new StaticAndNonStaticValue(); staticNonPersistable.SetUpSubscription(source); source.Emit(25); staticNonPersistable.Value.ShouldBe(25); StaticAndNonStaticValue.StaticValue.ShouldBe(25); var store = ObjectStore.New(storage); store.Entangle(source); store.Entangle(staticNonPersistable); store.Persist(); store = ObjectStore.Load(storage, true, new MockScheduler()); source = store.Resolve <Source <int> >(); staticNonPersistable = store.Resolve <StaticAndNonStaticValue>(); source.Emit(50); staticNonPersistable.Value.ShouldBe(50); StaticAndNonStaticValue.StaticValue.ShouldBe(50); staticNonPersistable.Subscription1.Dispose(); source.Emit(100); staticNonPersistable.Value.ShouldBe(50); StaticAndNonStaticValue.StaticValue.ShouldBe(50); }
private static StaticAndNonStaticValue Deserialize(IReadOnlyDictionary <string, object> sd) { var instance = new StaticAndNonStaticValue { Value = sd.Get <int>(nameof(Value)) }; sd.ResolveReference <IDisposable>(nameof(Subscription1), s => instance.Subscription1 = s); sd.ResolveReference <IDisposable>(nameof(Subscription2), s => instance.Subscription2 = s); return(instance); }