public void ShouldContainsAllSendingCommands() { var applicationServices = new ApplicationServices(); var hartCommunicationService = new TestHartCommunicationService(); applicationServices.HartCommunicationService = hartCommunicationService; var viewModel = new HistoryViewModel(applicationServices); hartCommunicationService.SimulateSendingCommand(new CommandRequest(Command.Zero())); hartCommunicationService.SimulateSendingCommand(new CommandRequest(Command.Zero())); viewModel.Items.Count.Should().Be(2); viewModel.Items[0].Address[0].Should().Be(128); viewModel.Items[0].Command[0].Should().Be(0); viewModel.Items[0].CommandType.Should().Be(CommandType.Send); viewModel.Items[0].Delimiter[0].Should().Be(2); viewModel.Items[0].Length[0].Should().Be(0); viewModel.Items[0].Preambles[2].Should().Be(0xFF); viewModel.Items[0].Preambles[0].Should().Be(0xFF); viewModel.Items[0].Preambles[1].Should().Be(0xFF); viewModel.Items[0].Preambles[3].Should().Be(0xFF); viewModel.Items[0].Preambles[4].Should().Be(0xFF); viewModel.Items[0].Time.Should().BeAfter(DateTime.MinValue); }
public void ShouldContainsAllReceives() { var applicationServices = new ApplicationServices(); var hartCommunicationService = new TestHartCommunicationService(); applicationServices.HartCommunicationService = hartCommunicationService; var viewModel = new HistoryViewModel(applicationServices); var command = Command.Zero(); command.ResponseCode = new byte[] { 0x00, 0x01 }; hartCommunicationService.SimulateReceive(new CommandResult(command)); hartCommunicationService.SimulateReceive(new CommandResult(command)); viewModel.Items.Count.Should().Be(2); viewModel.Items[0].Address[0].Should().Be(128); viewModel.Items[0].Command[0].Should().Be(0); viewModel.Items[0].CommandType.Should().Be(CommandType.Receive); viewModel.Items[0].Delimiter[0].Should().Be(2); viewModel.Items[0].Length[0].Should().Be(0); viewModel.Items[0].Preambles[0].Should().Be(0xFF); viewModel.Items[0].Preambles[1].Should().Be(0xFF); viewModel.Items[0].Preambles[2].Should().Be(0xFF); viewModel.Items[0].Preambles[3].Should().Be(0xFF); viewModel.Items[0].Preambles[4].Should().Be(0xFF); viewModel.Items[0].Time.Should().BeAfter(DateTime.MinValue); viewModel.Items[0].ResponseCode[0].Should().Be(0x00); viewModel.Items[0].ResponseCode[1].Should().Be(0x01); }
public void ShouldBeChangedIfServiceChangeTheState() { var communicationService = new TestHartCommunicationService(); var viewModel = new StatusBarViewModel(communicationService); communicationService.PortState = Services.PortState.Opening; viewModel.PortState.Should().Be(Services.PortState.Opening); }
public void ShouldBeSetTooIfStateIsNotOpened(Services.PortState portState) { var communicationService = new TestHartCommunicationService { PortState = portState }; var viewModel = new StatusBarViewModel(communicationService); viewModel.PortName.Should().Be("COM1"); }
public void ShouldBeChangedIfServiceChangeTheState() { var communicationService = new TestHartCommunicationService(); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = communicationService }, null); communicationService.PortState = Services.PortState.Opening; viewModel.PortState.Should().Be(Services.PortState.Opening); }
public void CanExecuteShouldBeTrueIfPortIsOpened() { var applicationServices = new ApplicationServices(); var hartCommunicationService = new TestHartCommunicationService(); applicationServices.HartCommunicationService = hartCommunicationService; hartCommunicationService.PortState = Services.PortState.Opened; var viewModel = new RibbonViewModel(applicationServices, new CommonServices()); viewModel.SendCommand0.CanExecute(null).Should().BeTrue(); }
public void CanExecuteShouldBeFalseIfNotConnected() { var applicationServices = new ApplicationServices(); var hartCommunicationService = new TestHartCommunicationService(); applicationServices.HartCommunicationService = hartCommunicationService; hartCommunicationService.PortState = Services.PortState.Closing; var viewModel = new RibbonViewModel(applicationServices, new CommonServices()); viewModel.SendCommand0.CanExecute(null).Should().BeFalse(); }
public void ShouldSetPortNameOfHartCommunicationService() { var service = new TestHartCommunicationService("COM2"); new ConnectionConfigurationViewModel(new ApplicationServices { HartCommunicationService = service }) { SelectedPortName = { DataValue = "COM3" } }; service.PortName.Should().Be("COM3"); }
public void ShouldCanExecuteIfStateIsNotChanging(Services.PortState portState) { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService { PortState = portState }; var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); viewModel.ConnectionCommand.CanExecute(null).Should().BeTrue(); }
public void ShouldClosePopupOnCancelCommandExecuted() { var service = new TestHartCommunicationService("COM2"); var viewModel = new ConnectionConfigurationViewModel(new ApplicationServices { HartCommunicationService = service }); var isClosedRequested = false; viewModel.CloseRequest += (sender, args) => isClosedRequested = true; viewModel.CancelCommand.Execute(null); isClosedRequested.Should().BeTrue(); }
public async void ShouldSendCommandZero() { var applicationServices = new ApplicationServices(); var hartCommunicationService = new TestHartCommunicationService(); applicationServices.HartCommunicationService = hartCommunicationService; hartCommunicationService.PortState = Services.PortState.Opened; var viewModel = new RibbonViewModel(applicationServices, new CommonServices()); await viewModel.SendCommand0.Execute(null); var request = hartCommunicationService.SentCommands.Dequeue(); request.Item1.Should().Be(0); request.Item2.Length.Should().Be(0); }
public async void ShouldNotShowMessageIfOpenedResultIsReceived() { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService(); hartCommunicationService.OpenAsyncResponders.Enqueue(() => OpenResult.Opened); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); messageBoxService.ShowInformationRequests.Count.Should().Be(0); }
public void PortNameOfServiceShouldBeResettedAfterCancelCommandExecuted() { var service = new TestHartCommunicationService("COM2"); var viewModel = new ConnectionConfigurationViewModel(new ApplicationServices { HartCommunicationService = service }); var viewAwareStatusService = new TestViewAwareStatus(); viewModel.InitialiseViewAwareService(viewAwareStatusService); viewAwareStatusService.SimulateViewIsLoadedEvent(); viewModel.SelectedPortName.DataValue = "COM3"; viewModel.CancelCommand.Execute(null); service.PortName.Should().Be("COM2"); }
public async void ShouldShowMessageIfNotOpenedIsReceived(OpenResult openResult) { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService(); hartCommunicationService.OpenAsyncResponders.Enqueue(() => openResult); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); messageBoxService.ShowInformationRequests.Count.Should().Be(1); messageBoxService.ShowInformationRequests[0].Message.Should().NotBeNullOrEmpty(); }
public async void ShouldCallCloseIfStateIsOpened() { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService { PortState = Services.PortState.Opened }; hartCommunicationService.CloseAsyncResponders.Enqueue(() => CloseResult.Closed); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); hartCommunicationService.OpenAsyncResponders.Count.Should().Be(0); }