示例#1
0
        public void Release_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.Release("test");

            // Assert
            Assert.Equal(ChannelState.Detaching, channel.State);
        }
示例#2
0
        public void Release_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.Release("test");

            // Assert
            Assert.Same(channel, target.Single());
        }
示例#3
0
        public void Release_RemovesChannelWhenFailed()
        {
            // 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.Release("test");

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

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