示例#1
0
        public async Task WhenSocketConnectionTerminates_PlayerShouldBeRemovedFromCollections()
        {
            collectionsMock.Setup(c => c.AddPlayer(It.IsAny <IPlayer>()));
            collectionsMock.Setup(c => c.RemovePlayer(It.IsAny <IPlayer>()))
            .Returns(() => Task.Delay(0));

            var socketMock = new Mock <IWebSocket>(MockBehavior.Strict);

            socketMock.SetupGet(s => s.State).Returns(WebSocketState.Open);
            socketMock.Setup(s => s.ReceiveAsync(It.IsAny <ArraySegment <byte> >(),
                                                 It.IsAny <CancellationToken>()))
            .Returns(() => throw new WebSocketException());

            var controller = new SocketController(loggerMock.Object,
                                                  collectionsMock.Object, msgHandlerMock.Object);

            await controller.ReceiveAsync(socketMock.Object);

            collectionsMock.Verify(c => c.AddPlayer(It.IsAny <IPlayer>()));
            collectionsMock.Verify(c => c.RemovePlayer(It.IsAny <IPlayer>()));
        }