コード例 #1
0
        public void ReleaseAll_DoesNotRemoveChannelBeforeDetached()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            channel.Attach();

            // Act
            target.ReleaseAll();

            // Assert
            Assert.Same(channel, target.Single());
        }
コード例 #2
0
        public void ReleaseAll_DetachesChannel()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            channel.Attach();

            // Act
            target.ReleaseAll();

            // Assert
            Assert.Equal(ChannelState.Detaching, channel.State);
        }
コード例 #3
0
        public void ReleaseAll_RemovesChannelWhenFailded()
        {
            // Arrange
            Mock <IConnectionManager> manager = new Mock <IConnectionManager>();
            Mock <IChannelFactory>    factory = new Mock <IChannelFactory>();

            factory.Setup(c => c.Create(It.IsAny <string>())).Returns <string>(c => new Channel(c, "", manager.Object));
            ChannelList target  = new ChannelList(manager.Object, factory.Object);
            var         channel = target.Get("test");

            channel.Attach();
            target.ReleaseAll();

            // Act
            manager.Raise(c => c.MessageReceived += null, new ProtocolMessage(ProtocolMessage.MessageAction.Error, "test"));

            // Assert
            Assert.False(target.Any());
        }