public void StatefulObserver_Versioning_NotSupportedByDefault() { var state = new MockOperatorStateContainer(); var writerFactory = state.CreateWriter(); var readerFactory = state.CreateReader(); var mo = new MyObserver() { State = 42 }; mo.Start(); var writer = writerFactory.Create(mo); Assert.ThrowsException <NotSupportedException>(() => mo.SaveState(writer, new Version(2, 0, 0, 0))); var mor = new MyObserver(); var reader = readerFactory.Create(mor); Assert.ThrowsException <NotSupportedException>(() => mor.LoadState(reader, new Version(2, 0, 0, 0))); }
public void StatefulObserver_State() { var state = new MockOperatorStateContainer(); var writerFactory = state.CreateWriter(); var readerFactory = state.CreateReader(); var mo = new MyObserver() { State = 42 }; mo.Start(); Assert.IsTrue(mo.Started); Assert.IsTrue(mo.StateChanged); Assert.ThrowsException <ArgumentNullException>(() => mo.SaveState(null, mo.Version)); var writer = writerFactory.Create(mo); mo.SaveState(writer, mo.Version); Assert.IsTrue(mo.StateChanged); mo.OnStateSaved(); Assert.IsFalse(mo.StateChanged); var mor = new MyObserver(); var reader = readerFactory.Create(mor); Assert.ThrowsException <ArgumentNullException>(() => mor.LoadState(null, mor.Version)); mor.LoadState(reader, mor.Version); mor.Start(); Assert.IsTrue(mor.Started); Assert.AreEqual(42, mor.State); mo.State = 43; Assert.IsTrue(mo.StateChanged); writer = writerFactory.Create(mo); mo.SaveState(writer, mo.Version); mo.OnStateSaved(); Assert.IsFalse(mo.StateChanged); var moq = new MyObserver(); reader = readerFactory.Create(moq); moq.LoadState(reader, moq.Version); moq.Start(); Assert.IsTrue(moq.Started); Assert.AreEqual(43, moq.State); mo.Dispose(); Assert.IsTrue(mo.Disposed); writer = writerFactory.Create(mo); mo.SaveState(writer, mo.Version); mo.OnStateSaved(); var mop = new MyObserver(); reader = readerFactory.Create(mop); mop.LoadState(reader, mop.Version); mop.Start(); Assert.IsTrue(mop.Disposed); Assert.IsFalse(mop.Started); }