Exemple #1
0
        public void DebugDispatcher_AddWithNull()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var countBefore     = debugDispatcher.Count;

            debugDispatcher.Add(workspaceID, null);

            Assert.AreEqual(countBefore, debugDispatcher.Count);
        }
Exemple #2
0
        public void DebugDispatcher_AddWithWriter()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var writer          = new Mock <IDebugWriter>();

            debugDispatcher.Add(workspaceID, writer.Object);

            var theWriter = debugDispatcher.Get(workspaceID);

            Assert.AreEqual(writer.Object, theWriter);
        }
Exemple #3
0
        public void DebugDispatcher_GetWithValidID()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var writer          = new Mock <IDebugWriter>();

            debugDispatcher.Add(workspaceID, writer.Object);

            var result = debugDispatcher.Get(workspaceID);

            Assert.AreSame(writer.Object, result);
        }
Exemple #4
0
        public void DebugDispatcher_RemoveWithValidID()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var writer          = new Mock <IDebugWriter>();

            debugDispatcher.Add(workspaceID, writer.Object);

            debugDispatcher.Remove(workspaceID);
            var theWriter = debugDispatcher.Get(workspaceID);

            Assert.IsNull(theWriter);
        }
Exemple #5
0
        public void DebugDispatcher_RemoveWithInvalidID()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var writer          = new Mock <IDebugWriter>();

            debugDispatcher.Add(workspaceID, writer.Object);

            var countBefore = debugDispatcher.Count;

            debugDispatcher.Remove(Guid.NewGuid());
            Assert.AreEqual(countBefore, debugDispatcher.Count);
        }
Exemple #6
0
        public void DebugDispatcher_AddAfterShutdown_DoesNotAdd()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var writer          = new Mock <IDebugWriter>();

            Assert.AreEqual(0, debugDispatcher.Count);

            debugDispatcher.Shutdown();
            debugDispatcher.Add(workspaceID, writer.Object);

            var theWriter = debugDispatcher.Get(workspaceID);

            Assert.AreEqual(0, debugDispatcher.Count);
            Assert.AreEqual(null, theWriter);
        }
Exemple #7
0
        public void DebugDispatcher_Write_WhenRemoteInvoke_ExpectRemoteItemsAddedToRepo()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            //------------Setup for test--------------------------
            var workspaceID = Guid.NewGuid();
            var writer      = new Mock <IDebugWriter>();

            writer.Setup(s => s.Write(It.IsAny <IDebugState>())).Verifiable();

            debugDispatcher.Add(workspaceID, writer.Object);

            var state = new Mock <IDebugState>();

            state.Setup(s => s.WorkspaceID).Returns(workspaceID);

            var remoteID = Guid.NewGuid();

            var writeArgs = new WriteArgs
            {
                debugState      = state.Object,
                isRemoteInvoke  = true,
                remoteInvokerId = remoteID.ToString()
            };

            //------------Execute Test---------------------------
            debugDispatcher.Write(writeArgs);

            //------------Assert Results-------------------------

            // Write happens asynchronously on a separate thread
            Thread.Sleep(50);
            writer.Verify(s => s.Write(It.IsAny <IDebugState>()), Times.Exactly(0));
            var items = RemoteDebugMessageRepo.Instance.FetchDebugItems(remoteID);

            Assert.AreEqual(1, items.Count);
            Assert.IsNotNull(items[0]);
        }
Exemple #8
0
        public void DebugDispatcher_Write()
        {
            var debugDispatcher = new DebugDispatcherImplementation();
            var workspaceID     = Guid.NewGuid();
            var writer          = new Mock <IDebugWriter>();

            writer.Setup(s => s.Write(It.IsAny <IDebugState>())).Verifiable();
            debugDispatcher.Add(workspaceID, writer.Object);

            var mockState = new Mock <IDebugState>();
            var clientId  = Guid.NewGuid();
            var sessionId = Guid.NewGuid();

            mockState.Setup(o => o.WorkspaceID).Returns(workspaceID);
            mockState.Setup(o => o.ClientID).Returns(clientId);
            mockState.Setup(o => o.SessionID).Returns(sessionId);
            mockState.Setup(o => o.IsFinalStep()).Returns(true);

            var expectedJson = JsonConvert.SerializeObject(mockState.Object, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
            });

            var writeArgs = new WriteArgs
            {
                debugState = mockState.Object
            };

            debugDispatcher.Write(writeArgs);
            debugDispatcher.Write(writeArgs);
            debugDispatcher.Write(writeArgs);

            Thread.Sleep(50);
            writer.Verify(s => s.Write(expectedJson), Times.Exactly(3));
        }