private static IFahClient SetupFahClientForSendingMockCommands()
        {
            var mockClient = new Mock <IFahClient>();
            var connection = new MockFahClientConnection();

            mockClient.SetupGet(x => x.Connection).Returns(connection);
            return(mockClient.Object);
        }
Пример #2
0
 public void FahClientReader_ReadAsyncThrowsInvalidOperationExceptionWhenTcpConnectionIsNoLongerConnected()
 {
     // Arrange
     using (var connection = new MockFahClientConnection())
     {
         connection.Open();
         var reader = new FahClientReader(connection);
         // Act & Assert
         Assert.ThrowsAsync <InvalidOperationException>(() => reader.ReadAsync());
     }
 }
Пример #3
0
 public void FahClientCommand_ExecuteAsyncThrowsInvalidOperationExceptionWhenTcpConnectionIsNoLongerConnected()
 {
     // Arrange
     using (var connection = new MockFahClientConnection())
     {
         connection.Open();
         var command = new FahClientCommand(connection);
         // Act & Assert
         Assert.ThrowsAsync <InvalidOperationException>(() => command.ExecuteAsync());
     }
 }
        private static IFahClient SetupFahClientForHandlingLogMessages(string path)
        {
            var mockClient = new Mock <IFahClient>();

            mockClient.SetupGet(x => x.Logger).Returns(NullLogger.Instance);
            var preferences = new InMemoryPreferencesProvider(null, path, null);

            mockClient.SetupGet(x => x.Preferences).Returns(preferences);
            var settings = new ClientSettings {
                Name = "test"
            };

            mockClient.SetupProperty(x => x.Settings);
            mockClient.Object.Settings = settings;
            var connection = new MockFahClientConnection();

            mockClient.SetupGet(x => x.Connection).Returns(connection);
            return(mockClient.Object);
        }
Пример #5
0
        public void FahClientSettingsPresenter_ConnectClicked_ConnectsAndShowsMessageBoxWhenFahClientReaderFailsToRead()
        {
            // Arrange
            var messageBox = new MockMessageBoxPresenter();

            using (var connection = new MockFahClientConnection())
            {
                var model = new MockConnectionFahClientSettingsModel(connection)
                {
                    Name = "foo", Server = "bar"
                };
                using (var presenter = new MockDialogFahClientSettingsPresenter(model, messageBox))
                {
                    // Act
                    presenter.ConnectClicked();
                    // Assert
                    Assert.AreEqual(1, messageBox.Invocations.Count);
                    Assert.IsNotNull(presenter.Connection);
                    Assert.IsFalse(presenter.Connection.Connected);
                    Assert.IsTrue(presenter.Model.ConnectEnabled);
                    Assert.AreEqual(0, presenter.Model.Slots.Count);
                }
            }
        }