-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fully hide date and identifier for account journal summary rows (#254)
- Loading branch information
Showing
5 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// <copyright> | ||
// Copyright (c) Lukas Grützmacher. All rights reserved. | ||
// </copyright> | ||
|
||
namespace lg2de.SimpleAccounting.Presentation; | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
|
||
/// <summary> | ||
/// Implements a converter for <see cref="DateTime"/> into date only supporting <langword>null</langword>. | ||
/// </summary> | ||
public class DateConverter : IValueConverter | ||
{ | ||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
const int firstYear = 1900; | ||
return value is not DateTime dateTime || dateTime.Year < firstYear | ||
? null | ||
: dateTime.ToString("d", culture); | ||
} | ||
|
||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/SimpleAccounting.UnitTests/Presentation/DateConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// <copyright> | ||
// Copyright (c) Lukas Grützmacher. All rights reserved. | ||
// </copyright> | ||
|
||
namespace lg2de.SimpleAccounting.UnitTests.Presentation; | ||
|
||
using System; | ||
using System.Globalization; | ||
using FluentAssertions; | ||
using lg2de.SimpleAccounting.Presentation; | ||
using Xunit; | ||
|
||
public class DateConverterTests | ||
{ | ||
[Fact] | ||
public void Convert_NullInput_NullReturned() | ||
{ | ||
var sut = new DateConverter(); | ||
|
||
var result = sut.Convert(null, typeof(string), null, CultureInfo.GetCultureInfo("de")); | ||
|
||
result.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public void Convert_MinInput_NullReturned() | ||
{ | ||
var sut = new DateConverter(); | ||
|
||
var result = sut.Convert(DateTime.MinValue, typeof(string), null, CultureInfo.GetCultureInfo("de")); | ||
|
||
result.Should().BeNull(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("de", "01.01.2023")] | ||
[InlineData("en", "1/1/2023")] | ||
public void Convert_ValidInput_FormattedReturned(string culture, string expectedResult) | ||
{ | ||
var sut = new DateConverter(); | ||
|
||
var result = sut.Convert( | ||
new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Local), typeof(string), null, | ||
CultureInfo.GetCultureInfo(culture)); | ||
|
||
result.Should().Be(expectedResult); | ||
} | ||
|
||
[Fact] | ||
public void ConvertBack_Throws() | ||
{ | ||
var sut = new DateConverter(); | ||
|
||
sut.Invoking(x => x.ConvertBack(null, typeof(DateTime), null, CultureInfo.CurrentCulture)).Should() | ||
.Throw<NotSupportedException>(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/SimpleAccounting.UnitTests/Presentation/JournalItemBaseViewModelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// <copyright> | ||
// Copyright (c) Lukas Grützmacher. All rights reserved. | ||
// </copyright> | ||
|
||
namespace lg2de.SimpleAccounting.UnitTests.Presentation; | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using FluentAssertions; | ||
using lg2de.SimpleAccounting.Presentation; | ||
using Xunit; | ||
|
||
public class JournalItemBaseViewModelTests | ||
{ | ||
[SuppressMessage("Minor Code Smell", "S2094:Classes should not be empty")] | ||
private class TestJournalItemBaseViewModel : JournalItemBaseViewModel; | ||
|
||
[Fact] | ||
public void IdentifierText_DefaultIdentifier_Empty() | ||
{ | ||
var sut = new TestJournalItemBaseViewModel { Identifier = 0 }; | ||
|
||
sut.IdentifierText.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void IdentifierText_SampleIdentifier_Formatted() | ||
{ | ||
var sut = new TestJournalItemBaseViewModel { Identifier = 42 }; | ||
|
||
sut.IdentifierText.Should().Be("42"); | ||
} | ||
} |