Skip to content

Commit cc01637

Browse files
committed
add tests
1 parent 7ccb195 commit cc01637

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if NET6_0_OR_GREATER
2+
3+
namespace Microsoft.Maui.Controls.Core.UnitTests;
4+
5+
using System;
6+
using System.Globalization;
7+
using Xunit;
8+
9+
public class DateOnlyTypeConverterTests : BaseTestFixture
10+
{
11+
[Fact]
12+
public void TestSucceeds()
13+
{
14+
var converter = new DateOnlyToDateTimeConverter();
15+
16+
var dateOnlyValue = new DateOnly(2025, 2, 21);
17+
18+
var actualDateTime = converter.ConvertFromInvariantString(dateOnlyValue.ToString(CultureInfo.InvariantCulture));
19+
var expectedDateTime = new DateTime(2025, 2, 21);
20+
21+
Assert.Equal(expectedDateTime, actualDateTime);
22+
}
23+
24+
[Fact]
25+
public void TestConvertToInvariantStringThrowsNotSupportedException()
26+
{
27+
var converter = new DateOnlyToDateTimeConverter();
28+
29+
var stringValue = "Not a DateOnly string";
30+
31+
Assert.Throws<NotSupportedException>(() => converter.ConvertToInvariantString(stringValue));
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if NET6_0_OR_GREATER
2+
3+
namespace Microsoft.Maui.Controls.Core.UnitTests;
4+
5+
using System;
6+
using System.Globalization;
7+
using Xunit;
8+
9+
public class TimeOnlyTypeConverterTests : BaseTestFixture
10+
{
11+
[Fact]
12+
public void TestSucceeds()
13+
{
14+
var converter = new TimeOnlyToTimeSpanConverter();
15+
16+
var timeOnlyValue = new TimeOnly(8, 30, 0);
17+
18+
var actualTimeSpan = converter.ConvertFromInvariantString(timeOnlyValue.ToString(CultureInfo.InvariantCulture));
19+
var expectedTimeSpan = new TimeSpan(8, 30, 0);
20+
21+
Assert.Equal(expectedTimeSpan, actualTimeSpan);
22+
}
23+
24+
[Fact]
25+
public void TestConvertToInvariantStringThrowsNotSupportedException()
26+
{
27+
var converter = new TimeOnlyToTimeSpanConverter();
28+
29+
var stringValue = "Not a DateOnly string";
30+
31+
Assert.Throws<NotSupportedException>(() => converter.ConvertToInvariantString(stringValue));
32+
}
33+
}

0 commit comments

Comments
 (0)