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); }
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()); }
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()); }