Skip to content

Commit

Permalink
Added MessageType enum for future ConsoleWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
pepinovimr committed Nov 15, 2023
1 parent 959170b commit 6fc99cf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 20 deletions.
13 changes: 8 additions & 5 deletions ApplicationLayer/ConsoleViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ApplicationLayer.Services.Interfaces;
using ApplicationLayer.Models;
using ApplicationLayer.Services.Interfaces;
using Microsoft.Extensions.Logging;
using System;

namespace ApplicationLayer
{
Expand All @@ -15,7 +17,7 @@ public class ConsoleViewModel
/// Handles notifications for views.
/// Should be the only interaction with Views
/// </summary>
public event EventHandler<string> Notify;
public event EventHandler<(string, MessageType)> Notify;

/// <summary>
/// Constructor for <see cref="ConsoleViewModel"/>
Expand All @@ -26,11 +28,12 @@ public ConsoleViewModel( ILogger<ConsoleViewModel> logger)
}

/// <summary>
/// Temporary
/// Starts application
/// </summary>
public void PerformApplicationLogic()
public void StartApplication()
{
Notify?.Invoke(this, "ApplicationName");
_logger.Log(LogLevel.Information, "Application Started");
Notify?.Invoke(this, ("ApplicationName", MessageType.Header));
}
}
}
23 changes: 23 additions & 0 deletions ApplicationLayer/Enums/MessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ApplicationLayer.Models
{
/// <summary>
/// Represents possible message types to be displayed on ConsoleView
/// </summary>
public enum MessageType
{
/// <summary>
/// Normal text
/// </summary>
Normal = 0,
/// <summary>
/// Indicates to user in which part of program he is
/// eg.: Creating Validation, Validating MARC etc...
/// </summary>
Section = 1,
/// <summary>
/// Header - should only by localized Value for ApplicationName
/// </summary>
Header = 2

}
}
14 changes: 3 additions & 11 deletions ConsoleView/ConsoleView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ApplicationLayer;
using ApplicationLayer.Models;
using ApplicationLayer.Services.Interfaces;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -36,18 +37,9 @@ public ConsoleView(ConsoleViewModel viewModel, ILogger<ConsoleViewModel> logger,
/// <summary>
/// Handles notifiactions from ViewModel
/// </summary>
private void ViewModel_Notify(object sender, string message)
private void ViewModel_Notify(object sender, (string, MessageType)message)
{
Console.WriteLine(_localizationService[message]);
}

/// <summary>
/// Starts Application
/// </summary>
public void StartApplication()
{
_logger.Log(LogLevel.Information, "Application Started");
_viewModel.PerformApplicationLogic();
Console.WriteLine(_localizationService[message.Item1]);
}
}
}
4 changes: 2 additions & 2 deletions ConsoleView/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ private static void Main()
IHost host = BuildApplication(builder);


ConsoleView consoleView = host.Services.GetRequiredService<ConsoleView>();
ConsoleViewModel consoleViewModel = host.Services.GetRequiredService<ConsoleViewModel>();

consoleView.StartApplication();
consoleViewModel.StartApplication();

Console.ReadKey();
}
Expand Down
5 changes: 5 additions & 0 deletions MARCValidator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharedLayer", "SharedLayer\SharedLayer.csproj", "{79E313B0-6C73-4AD8-95AB-3376417C2A10}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MARCValidatorTests", "MARCValidatorTests\MARCValidatorTests.csproj", "{7D866DA2-1F8E-4EA3-9F90-8570BB788BF2}"
ProjectSection(ProjectDependencies) = postProject
{14841012-CFB3-4EC6-A7C9-52F8AB390261} = {14841012-CFB3-4EC6-A7C9-52F8AB390261}
{97120ECD-9E21-42DF-89A8-F47BAA1D4F34} = {97120ECD-9E21-42DF-89A8-F47BAA1D4F34}
{B3771A70-949F-4621-81FD-15B7DA994469} = {B3771A70-949F-4621-81FD-15B7DA994469}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Globalization;
using System.Resources;

namespace MARCValidatorTests
namespace MARCValidatorTests.ApplicationLayerTests
{
/// <summary>
/// Example unit test class for localization service
Expand All @@ -18,7 +18,7 @@ public void Setup()
_resourceManagerMock = new Mock<ResourceManager>();
CultureInfo.CurrentCulture = new CultureInfo("cs");
}

[TestMethod]
public void GetLocalizedValue_UsingProperKey_ReturnsItsValue()
{
Expand Down
7 changes: 7 additions & 0 deletions MARCValidatorTests/MARCValidatorTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
<ProjectReference Include="..\SharedLayer\SharedLayer.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="ConsoleViewLayerTests\" />
<Folder Include="DataAccessLayerTests\" />
<Folder Include="DomainLayerTests\" />
<Folder Include="SharedLayerTests\" />
</ItemGroup>

</Project>

0 comments on commit 6fc99cf

Please sign in to comment.