Ejemplo n.º 1
0
        public void HashCode()
        {
            string key1 = "ModelName" + Guid.NewGuid();
            string key2 = Guid.NewGuid().ToString();
            var    t    = new TestConversation(key1);

            Assert.That(t.GetHashCode(), Is.EqualTo(key1.GetHashCode()));
            Assert.That(t.GetHashCode(new TestConversation(key2)), Is.EqualTo(key2.GetHashCode()));
        }
        public void TheAutoUnBindDefaultShouldBeTrue()
        {
            var           tc = new ThreadLocalConversationContainerStub();
            IConversation c  = new TestConversation();

            tc.Bind(c);
            c.End();
            Assert.That(tc.BindedConversationCount, Is.EqualTo(0));
            tc.Reset();
        }
        public void ShouldWorkWithAutoUnBindFalse()
        {
            var tc = new ThreadLocalConversationContainerStub {
                AutoUnbindAfterEndConversation = false
            };
            IConversation c = new TestConversation();

            tc.Bind(c);
            c.End();
            Assert.That(tc.BindedConversationCount, Is.EqualTo(1));
            tc.Reset();
        }
        public void Bind()
        {
            var           tc = new ThreadLocalConversationContainerStub();
            IConversation c  = new TestConversation();

            tc.Bind(c);
            Assert.That(tc.BindedConversationCount, Is.EqualTo(1));
            Assert.That(tc.CurrentConversation, Is.SameAs(c));
            tc.Bind(new TestConversation());
            Assert.That(tc.BindedConversationCount, Is.EqualTo(2));
            Assert.That(tc.CurrentConversation, Is.SameAs(c), "the current conversation was changed after a bind.");

            tc.Reset();
        }
Ejemplo n.º 5
0
 public void PauseAndFlushCallSequence()
 {
     using (var t = new TestConversation())
     {
         const string pausing = "Pausing called.";
         const string paused  = "Paused called.";
         t.Pausing += ((x, y) => t.Log.Debug(pausing));
         t.Paused  += ((x, y) => t.Log.Debug(paused));
         Assert.That(Spying.Logger <TestConversation>()
                     .Execute(t.FlushAndPause)
                     .MessageSequence,
                     Is.EqualTo(new[] { pausing, TestConversation.FlushAndPauseMessage, paused }));
     }
 }
Ejemplo n.º 6
0
 public void ResumeCallSequence()
 {
     using (var t = new TestConversation())
     {
         const string resuming = "Resuming called.";
         const string resumed  = "Resumed called.";
         t.Resuming += ((x, y) => t.Log.Debug(resuming));
         t.Resumed  += ((x, y) => t.Log.Debug(resumed));
         Assert.That(Spying.Logger <TestConversation>()
                     .Execute(t.Resume)
                     .MessageSequence,
                     Is.EqualTo(new[] { resuming, TestConversation.ResumeMessage, resumed }));
     }
 }
        public void SetAsCurrentWithConversation()
        {
            var tc = new ThreadLocalConversationContainerStub();

            Assert.Throws <ArgumentNullException>(() => tc.SetAsCurrent((IConversation)null));
            tc.Bind(new TestConversation());
            IConversation c = new TestConversation();

            tc.SetAsCurrent(c);
            Assert.That(tc.BindedConversationCount, Is.EqualTo(2));
            Assert.That(tc.CurrentConversation, Is.SameAs(c));
            tc.SetAsCurrent(c);
            Assert.That(tc.BindedConversationCount, Is.EqualTo(2), "a new conversation was added even if is contained.");
            Assert.That(tc.CurrentConversation, Is.SameAs(c));
            tc.Reset();
        }
        public void Unbind()
        {
            var tc = new ThreadLocalConversationContainerStub();

            Assert.That(tc.Unbind(null), Is.Null);
            Assert.That(tc.Unbind(""), Is.Null);

            IConversation c = new TestConversation();

            tc.Bind(c);
            Assert.That(tc.Unbind(c.Id), Is.SameAs(c));
            Assert.That(tc.BindedConversationCount, Is.EqualTo(0));
            Assert.That(tc.CurrentConversation, Is.Null);

            tc.Reset();
        }
Ejemplo n.º 9
0
        public void StartCallSequence()
        {
            // I'm using log instad a mock, I know
            using (var t = new TestConversation())
            {
                const string starting = "Starting called.";
                const string started  = "Started called.";
                t.Starting += ((x, y) => t.Log.Debug(starting));
                t.Started  += ((x, y) => t.Log.Debug(started));

                Assert.That(Spying.Logger <TestConversation>()
                            .Execute(t.Start)
                            .MessageSequence,
                            Is.EqualTo(new[] { starting, TestConversation.StartMessage, started }));
            }
        }
Ejemplo n.º 10
0
        public void DisposeCallSequence()
        {
            const string ended = "End called.";

            Assert.That(Spying.Logger <TestConversation>()
                        .Execute(() =>
            {
                using (var t = new TestConversation())
                {
                    t.Ended += ((x, y) => t.Log.Debug(ended));
                    t.Ended += ((x, y) => Assert.That(y.Disposing));
                }
            })
                        .MessageSequence,
                        Is.EqualTo(new[] { TestConversation.AbortMessage, ended, TestConversation.DisposeMessage }));
        }
Ejemplo n.º 11
0
        public void EndCallSequence()
        {
            using (var t = new TestConversation())
            {
                const string ending = "Ending called.";
                const string ended  = "Ended called.";
                t.Ending += ((x, y) => t.Log.Debug(ending));
                t.Ended  += ((x, y) => t.Log.Debug(ended));
                t.Ended  += AssertEndedOutOfDisposing;
                Assert.That(Spying.Logger <TestConversation>()
                            .Execute(t.End)
                            .MessageSequence,
                            Is.EqualTo(new[] { ending, TestConversation.EndMessage, ended }));

                t.Ended -= AssertEndedOutOfDisposing;
            }
        }
        public void SetAsCurrentWithId()
        {
            var tc = new ThreadLocalConversationContainerStub();

            Assert.Throws <ArgumentNullException>(() => tc.SetAsCurrent((string)null));
            IConversation c1 = new TestConversation();

            tc.Bind(c1);
            IConversation c2 = new TestConversation();

            Assert.Throws <ConversationException>(() => tc.SetAsCurrent(c2.Id));
            Assert.That(tc.BindedConversationCount, Is.EqualTo(1));
            Assert.That(tc.CurrentConversation, Is.SameAs(c1));
            tc.Bind(c2);
            tc.SetAsCurrent(c2.Id);
            Assert.That(tc.CurrentConversation, Is.SameAs(c2));
            tc.Reset();
        }
        public void FullPlay()
        {
            var           tc1 = new ThreadLocalConversationContainerStub();
            var           tc2 = new ThreadLocalConversationContainerStub();
            IConversation c1  = new TestConversation();
            IConversation c2  = new TestConversation();

            tc1.Bind(c1);
            tc2.Bind(c2);

            Assert.That(tc1.BindedConversationCount, Is.EqualTo(2));
            Assert.That(tc2.CurrentConversation, Is.SameAs(c1));
            tc2.SetAsCurrent(c2);
            Assert.That(tc1.CurrentConversation, Is.SameAs(c2));
            Assert.That(tc1.Unbind(c2.Id), Is.SameAs(c2));
            Assert.That(tc1.BindedConversationCount, Is.EqualTo(1));
            Assert.That(tc2.CurrentConversation, Is.SameAs(c1));
            tc1.Reset();
        }
Ejemplo n.º 14
0
        public void Equality()
        {
            var t = new TestConversation();

            Assert.That(t.Equals(t));
            Assert.That(!t.Equals(new TestConversation()));
            Assert.That(!t.Equals(null));
            Assert.That(!t.Equals(new object()));

            string key1 = "ModelName" + Guid.NewGuid();
            string key2 = Guid.NewGuid().ToString();

            t = new TestConversation(key1);
            Assert.That(t.Equals(new TestConversation(key1)));
            Assert.That(!t.Equals(new TestConversation(key2)));
            Assert.That(t.Equals(null, null));
            Assert.That(!t.Equals(new TestConversation(key1), null));
            Assert.That(!t.Equals(null, new TestConversation(key1)));
            Assert.That(t.Equals(new TestConversation(key1), new TestConversation(key1)));
            Assert.That(!t.Equals(new TestConversation(key1), new TestConversation(key2)));
        }