-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobParametersTests.cs
More file actions
59 lines (50 loc) · 1.83 KB
/
Copy pathJobParametersTests.cs
File metadata and controls
59 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using NeoReports.Jobs;
using Shouldly;
using Xunit;
namespace NeoReports.Jobs.UnitTests;
public class JobParametersTests
{
[Fact]
public void Round_trips_primitive_values()
{
var original = new Dictionary<string, object?>
{
["name"] = "sales",
["count"] = 42L,
["ratio"] = 1.5,
["active"] = true,
["missing"] = null,
};
var json = JobParameters.Serialize(original);
var back = JobParameters.Deserialize(json);
back["name"].ShouldBe("sales");
// ShouldBe alone can't police this: Shouldly compares numerics by value, so a double 42.0
// satisfies ShouldBe(42L) and the whole-number-boxed-as-double bug slipped through. Assert
// the runtime type — a provider binds an integer column by the CLR type it is handed, and a
// double past 2^53 silently loses precision.
back["count"].ShouldBeOfType<long>().ShouldBe(42L);
back["ratio"].ShouldBeOfType<double>().ShouldBe(1.5);
back["active"].ShouldBe(true);
back["missing"].ShouldBeNull();
}
[Fact]
public void Round_trips_datetime_as_datetime()
{
var date = new DateTime(2026, 1, 15, 0, 0, 0, DateTimeKind.Utc);
var json = JobParameters.Serialize(new Dictionary<string, object?> { ["start"] = date });
var back = JobParameters.Deserialize(json);
back["start"].ShouldBeOfType<DateTime>();
((DateTime)back["start"]!).ShouldBe(date);
}
[Fact]
public void Null_or_empty_json_yields_empty_dictionary()
{
JobParameters.Deserialize(null).ShouldBeEmpty();
JobParameters.Deserialize("").ShouldBeEmpty();
}
[Fact]
public void Serialize_null_parameters_yields_empty_object()
{
JobParameters.Serialize(null).ShouldBe("{}");
}
}