private void StartClient() { _client = new ClientCommunicationService(); if (_enableLogging) { ILoggerService loggerService = new LoggerService(); _client.CurrentLogLevel = _logLevel; _client.LogFileName = _logFileName; _client.LoggerService = loggerService; } _client.MulticastIPAddress = _multicastIPAddress; _client.MulticastPort = _multicastPort; _client.ServerIPAddress = _serverIPAddress; _client.ServerPort = _serverPort; _client.UseMulticast = _useMulticast; _client.DataReceived += new EventHandler <DataReceivedEventArgs>(OnDataReceived); try { _client.Start(); ClearGrid(); SendRequestForMessageList(); } catch (SocketException) { StopClient(); MessageBox.Show(this, "Error connecting to server " + _serverIPAddress + ":" + _serverPort + Environment.NewLine + "Configure server address and port.", "Mocs Notification", MessageBoxButtons.OK, MessageBoxIcon.Warning); ShowConfigurationForm(); } }
private void StopClient() { if (_client != null) { _client.DataReceived -= new EventHandler <DataReceivedEventArgs>(OnDataReceived); if (_client.IsStarted) { _client.Stop(); } _client = null; } }
public async void Get_null_record() { var mock = new ServiceMockFacade <IClientCommunicationRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ClientCommunication>(null)); var service = new ClientCommunicationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock, mock.DALMapperMockFactory.DALClientCommunicationMapperMock); ApiClientCommunicationResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Create() { var mock = new ServiceMockFacade <IClientCommunicationRepository>(); var model = new ApiClientCommunicationRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ClientCommunication>())).Returns(Task.FromResult(new ClientCommunication())); var service = new ClientCommunicationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock, mock.DALMapperMockFactory.DALClientCommunicationMapperMock); CreateResponse <ApiClientCommunicationResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiClientCommunicationRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ClientCommunication>())); }
public async void All() { var mock = new ServiceMockFacade <IClientCommunicationRepository>(); var records = new List <ClientCommunication>(); records.Add(new ClientCommunication()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); var service = new ClientCommunicationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock, mock.DALMapperMockFactory.DALClientCommunicationMapperMock); List <ApiClientCommunicationResponseModel> response = await service.All(); response.Should().HaveCount(1); mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public async void Delete() { var mock = new ServiceMockFacade <IClientCommunicationRepository>(); var model = new ApiClientCommunicationRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new ClientCommunicationService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLClientCommunicationMapperMock, mock.DALMapperMockFactory.DALClientCommunicationMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.ClientCommunicationModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
private void StopClient() { if (_client != null) { _client.DataReceived -= new EventHandler<DataReceivedEventArgs>(OnDataReceived); if (_client.IsStarted) { _client.Stop(); } _client = null; } }
private void StartClient() { _client = new ClientCommunicationService(); if (_enableLogging) { ILoggerService loggerService = new LoggerService(); _client.CurrentLogLevel = _logLevel; _client.LogFileName = _logFileName; _client.LoggerService = loggerService; } _client.MulticastIPAddress = _multicastIPAddress; _client.MulticastPort = _multicastPort; _client.ServerIPAddress = _serverIPAddress; _client.ServerPort = _serverPort; _client.UseMulticast = _useMulticast; _client.DataReceived += new EventHandler<DataReceivedEventArgs>(OnDataReceived); try { _client.Start(); ClearGrid(); SendRequestForMessageList(); } catch (SocketException) { StopClient(); MessageBox.Show(this, "Error connecting to server " + _serverIPAddress + ":" + _serverPort + Environment.NewLine + "Configure server address and port.", "Mocs Notification", MessageBoxButtons.OK, MessageBoxIcon.Warning); ShowConfigurationForm(); } }