Hello,
I'm attempting to use the following code to arrange that all TcpClients return true for having a valid connection:
TcpClient localClient = Mock.Create<TcpClient>(Constructor.Mocked, Behavior.Strict);
Mock.Arrange(() => localClient.Connected).IgnoreInstance().Returns(true);
This code seems to work fine when I'm on the same thread, but if the access to Connected occurs on a different thread, this does not seem to function correctly.
My best guess is it has something to do with the use of either IgnoreInstance in conjunction with a property instead of a method (something I can't seem to find examples of so I wonder if it's supported or not), the fact that Threadpool mocking is not supported on the trial version, something I'm doing wrong, or a bug.
I've also attempted to mock the containing class such that it will always return a mocked instance of the TcpClient for any instance and that does not seem to function correctly on a thread either:
Mock.NonPublic.Arrange<TcpClient>(typeof(CustomConnectionHandler), "TcpConnection").IgnoreInstance().Returns(localClient);
On the thread I always seem to get a different instance of the TcpClient - not localClient
Any thoughts,
Thanks
I'm attempting to use the following code to arrange that all TcpClients return true for having a valid connection:
TcpClient localClient = Mock.Create<TcpClient>(Constructor.Mocked, Behavior.Strict);
Mock.Arrange(() => localClient.Connected).IgnoreInstance().Returns(true);
This code seems to work fine when I'm on the same thread, but if the access to Connected occurs on a different thread, this does not seem to function correctly.
My best guess is it has something to do with the use of either IgnoreInstance in conjunction with a property instead of a method (something I can't seem to find examples of so I wonder if it's supported or not), the fact that Threadpool mocking is not supported on the trial version, something I'm doing wrong, or a bug.
I've also attempted to mock the containing class such that it will always return a mocked instance of the TcpClient for any instance and that does not seem to function correctly on a thread either:
Mock.NonPublic.Arrange<TcpClient>(typeof(CustomConnectionHandler), "TcpConnection").IgnoreInstance().Returns(localClient);
On the thread I always seem to get a different instance of the TcpClient - not localClient
Any thoughts,
Thanks