Ejemplo n.º 1
0
        public void AuthorityChanged_gets_triggered_when_the_reader_receives_an_authority_change()
        {
            var authorityChangedCalled = false;

            ReaderPublic.AuthorityChanged += authority =>
            {
                Assert.AreEqual(Authority.Authoritative, authority);

                authorityChangedCalled = true;
            };

            Assert.AreEqual(false, authorityChangedCalled, "Adding an event should not fire it immediately");

            ReaderWriterInternal.OnAuthorityChange(Authority.Authoritative);

            Assert.AreEqual(true, authorityChangedCalled);
        }
Ejemplo n.º 2
0
        public void AuthorityChanged_calls_non_failure_callbacks_even_if_some_callbacks_fail()
        {
            var secondAuthorityChangeCalled = false;

            ReaderPublic.AuthorityChanged += authority =>
                                             throw new Exception("Authority failure: backwards time travel");
            ReaderPublic.AuthorityChanged += authority => { secondAuthorityChangeCalled = true; };
            ReaderPublic.AuthorityChanged += authority =>
                                             throw new Exception("Authority failure: help I'm stuck in an exception factory");

            LogAssert.Expect(LogType.Exception, "Exception: Authority failure: backwards time travel");
            LogAssert.Expect(LogType.Exception, "Exception: Authority failure: help I'm stuck in an exception factory");

            Assert.DoesNotThrow(() => { ReaderWriterInternal.OnAuthorityChange(Authority.NotAuthoritative); },
                                "Exceptions that happen within authority change callbacks should not propagate to callers.");

            Assert.IsTrue(secondAuthorityChangeCalled);
        }