Skip to content

Commit 69811d2

Browse files
committed
Delete button "Decode". Add label for display input status. Update tests.
1 parent 065862b commit 69811d2

6 files changed

Lines changed: 63 additions & 53 deletions

File tree

FiscalDeviceStatusDecoder/Application/MainViewModel.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ namespace FiscalDeviceStatusDecoder.Application;
66

77
public class MainViewModel : INotifyPropertyChanged
88
{
9-
private readonly IMessageBox MessageBox;
9+
public const string ValidHexMessage = "Valid HEX";
10+
1011
private string bytes = string.Empty;
1112
private string hex = string.Empty;
13+
private string displayStatusInput = string.Empty;
1214
private List<StatusBit>? statusDevices;
1315

14-
public MainViewModel(IMessageBox messageBox)
16+
public MainViewModel()
1517
{
1618
Devices = InitializeDevices();
1719
SelectedDevices = Devices[0];
18-
MessageBox = messageBox;
1920
}
2021

2122
public event PropertyChangedEventHandler? PropertyChanged;
@@ -66,6 +67,16 @@ public string Bytes
6667
}
6768
}
6869

70+
public string DisplayStatusInput
71+
{
72+
get => displayStatusInput;
73+
set
74+
{
75+
displayStatusInput = value;
76+
OnPropertyChanged(nameof(DisplayStatusInput));
77+
}
78+
}
79+
6980
public ICommand DecodeCommand => new RelayCommand(execute: _ => StatusDevices = InitializeStatusDevice(SelectedDevices, hex), canExecute: _ => hex?.Length > 0);
7081

7182
public string DecodeToByte(ref string hex)
@@ -89,14 +100,15 @@ public void OnPropertyChanged(string prop = "")
89100
try
90101
{
91102
List<string> bytesArray = SetStatusBytesAndHex(selectedDevices, hex);
92-
return SetStatusDevice(selectedDevices, bytesArray);
103+
var statusBits = SetStatusDevice(selectedDevices, bytesArray);
104+
105+
DisplayStatusInput = ValidHexMessage;
106+
107+
return statusBits;
93108
}
94109
catch (Exception ex)
95110
{
96-
MessageBox.ShowMessage(ex.Message, "Oops..", MessageBoxButton.OK, MessageBoxImage.Error);
97-
98-
Hex = string.Empty;
99-
Bytes = string.Empty;
111+
DisplayStatusInput = ex.Message;
100112

101113
return null;
102114
}

FiscalDeviceStatusDecoder/Application/Services/MessageBox.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

FiscalDeviceStatusDecoder/Domain/Contracts/IMessageBox.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

FiscalDeviceStatusDecoder/Presentation/MainWindow.xaml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:conv="clr-namespace:FiscalDeviceStatusDecoder.Presentation.Converters"
7+
xmlns:app="clr-namespace:FiscalDeviceStatusDecoder.Application"
78
mc:Ignorable="d"
89
WindowStartupLocation="CenterScreen"
910
ResizeMode="CanMinimize"
1011
Title="FD Status Decoder"
1112
Height="750"
1213
Width="700">
14+
<Window.DataContext>
15+
<app:MainViewModel />
16+
</Window.DataContext>
1317
<Window.Resources>
1418
<conv:BoolToBrushConverter x:Key="BoolToBrushConverter" />
1519
</Window.Resources>
1620
<Grid>
1721
<Grid.RowDefinitions>
18-
<RowDefinition Height="0.1*" />
19-
<RowDefinition Height="0.1*" />
22+
<RowDefinition Height="0.11*" />
23+
<RowDefinition Height="0.11*" />
24+
<RowDefinition Height="0.11*" />
2025
<RowDefinition Height="*" />
2126
</Grid.RowDefinitions>
2227
<Grid Grid.Row="0">
@@ -39,8 +44,7 @@
3944
<Grid Grid.Row="1">
4045
<Grid.ColumnDefinitions>
4146
<ColumnDefinition Width="0.2*" />
42-
<ColumnDefinition Width="0.7*" />
43-
<ColumnDefinition Width="0.3*" />
47+
<ColumnDefinition Width="*" />
4448
</Grid.ColumnDefinitions>
4549
<Label Grid.Column="0"
4650
HorizontalAlignment="Center"
@@ -50,16 +54,30 @@
5054
HorizontalContentAlignment="Left"
5155
VerticalContentAlignment="Center"
5256
Padding="10"
53-
Margin="0,10,10,10"
57+
Margin="0,10,30,10"
5458
Text="{Binding DisplayHex , Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}">
5559
</TextBox>
56-
<Button Grid.Column="2"
57-
Margin="0,10,30,10"
58-
Command="{Binding DecodeCommand}"
59-
Content="Decode" />
6060
</Grid>
6161

62-
<GroupBox Grid.Row="2"
62+
<Grid Grid.Row="2">
63+
<Grid.ColumnDefinitions>
64+
<ColumnDefinition Width="0.2*" />
65+
<ColumnDefinition Width="*" />
66+
</Grid.ColumnDefinitions>
67+
<Label Grid.Column="0"
68+
HorizontalAlignment="Center"
69+
VerticalAlignment="Center"
70+
Content="Status input" />
71+
<Label Grid.Column="1"
72+
Padding="10"
73+
Margin="0,10,30,10"
74+
BorderThickness="1"
75+
BorderBrush="#FFABADB3"
76+
Content="{Binding DisplayStatusInput}">
77+
</Label>
78+
</Grid>
79+
80+
<GroupBox Grid.Row="3"
6381
FontSize="14"
6482
Header="{Binding DisplayBytes}"
6583
Margin="10"

FiscalDeviceStatusDecoder/Presentation/MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public partial class MainWindow : Window
1010
public MainWindow()
1111
{
1212
InitializeComponent();
13-
DataContext = new MainViewModel(new Presentation.Services.MessageBox());
1413
}
1514
}
1615
}

FiscalDeviceStatusDecoderTest/MainViewModelTest.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,17 @@
22
using FiscalDeviceStatusDecoder.Domain;
33
using NSubstitute;
44
using NUnit.Framework;
5-
using System.Windows;
65

76
namespace FiscalDeviceStatusDecoderTest;
87

9-
internal class MessageBox : IMessageBox
10-
{
11-
internal int CountMessage;
12-
13-
public void ShowMessage(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon)
14-
{
15-
CountMessage++;
16-
}
17-
}
18-
198
public class MainViewModelTest
209
{
2110
private MainViewModel target;
22-
private MessageBox messageBox;
2311

2412
[SetUp]
2513
public void Setup()
2614
{
27-
messageBox = new();
28-
target = new(messageBox);
15+
target = new();
2916
}
3017

3118
[Test]
@@ -99,6 +86,7 @@ public void InitializeStatusDevices_HexLessNumber_MessagesAboutError(string hex)
9986
{
10087
// arrange
10188
int countErrorForInvalidHex = 0;
89+
int countMessage = 0;
10290

10391
// act
10492
foreach (var devices in MainViewModel.Devices)
@@ -107,9 +95,14 @@ public void InitializeStatusDevices_HexLessNumber_MessagesAboutError(string hex)
10795
countErrorForInvalidHex += bytesArray.Length < devices.QuantityStatusByte ? 1 : 0;
10896

10997
target.InitializeStatusDevice(devices, hex);
98+
99+
if (target.DisplayStatusInput != MainViewModel.ValidHexMessage)
100+
{
101+
countMessage++;
102+
}
110103
}
111104
// assert
112-
Assert.That(messageBox.CountMessage, Is.EqualTo(countErrorForInvalidHex));
105+
Assert.That(countMessage, Is.EqualTo(countErrorForInvalidHex));
113106
}
114107

115108
[Test]
@@ -120,6 +113,7 @@ public void InitializeStatusDevices_HexAndInvalidModels_MessagesAboutError(strin
120113
{
121114
// arrange
122115
int countErrorForInvalidHex = 0;
116+
int countMessage = 0;
123117

124118
// act
125119
foreach (var devices in MainViewModel.Devices)
@@ -128,10 +122,15 @@ public void InitializeStatusDevices_HexAndInvalidModels_MessagesAboutError(strin
128122
countErrorForInvalidHex++;
129123

130124
target.InitializeStatusDevice(mock, hex);
125+
126+
if (target.DisplayStatusInput != MainViewModel.ValidHexMessage)
127+
{
128+
countMessage++;
129+
}
131130
}
132131

133132
// assert
134-
Assert.That(messageBox.CountMessage, Is.EqualTo(countErrorForInvalidHex));
133+
Assert.That(countMessage, Is.EqualTo(countErrorForInvalidHex));
135134
}
136135

137136
[Test]

0 commit comments

Comments
 (0)