-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbParameterMapperTests.cs
More file actions
74 lines (59 loc) · 2.29 KB
/
Copy pathDbParameterMapperTests.cs
File metadata and controls
74 lines (59 loc) · 2.29 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using DBAClientX.Mapping;
namespace DbaClientX.Tests;
public class DbParameterMapperTests
{
private sealed class NestedItem
{
public string? Name { get; init; }
}
private sealed class TestItem
{
public string? RunId { get; init; }
public NestedItem? User { get; init; }
}
[Fact]
public void MapItem_PrefersItemValues_OverAmbientValues()
{
var item = new TestItem { RunId = "item-run-id" };
var map = new Dictionary<string, string> { ["RunId"] = "@RunId" };
var ambient = new Dictionary<string, object?> { ["RunId"] = "ambient-run-id" };
var result = DbParameterMapper.MapItem(item, map, ambient: ambient);
Assert.Equal("item-run-id", result["@RunId"]);
}
[Fact]
public void MapItem_UsesAmbientValues_WhenItemDoesNotProvideValue()
{
var item = new TestItem { User = new NestedItem { Name = "Alice" } };
var map = new Dictionary<string, string>
{
["User.Name"] = "@UserName",
["RunId"] = "@RunId"
};
var ambient = new Dictionary<string, object?> { ["RunId"] = "ambient-run-id" };
var result = DbParameterMapper.MapItem(item, map, ambient: ambient);
Assert.Equal("Alice", result["@UserName"]);
Assert.Equal("ambient-run-id", result["@RunId"]);
}
[Fact]
public void MapItem_UsesAmbientValues_CaseInsensitively()
{
var map = new Dictionary<string, string> { ["RunId"] = "@RunId" };
var ambient = new Dictionary<string, object?>(StringComparer.Ordinal)
{
["runid"] = "ambient-run-id"
};
var result = DbParameterMapper.MapItem(item: null, map, ambient: ambient);
Assert.Equal("ambient-run-id", result["@RunId"]);
}
[Fact]
public void MapItem_ConvertsDateTimeOffsetAmbientValues_ToUtcDateTime()
{
var timestamp = new DateTimeOffset(2026, 3, 9, 12, 30, 0, TimeSpan.FromHours(2));
var map = new Dictionary<string, string> { ["TsUtc"] = "@TsUtc" };
var ambient = new Dictionary<string, object?> { ["TsUtc"] = timestamp };
var result = DbParameterMapper.MapItem(item: null, map, ambient: ambient);
Assert.Equal(timestamp.UtcDateTime, result["@TsUtc"]);
}
}