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