-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToAttributeExpressionTests.cs
172 lines (153 loc) · 5.64 KB
/
ToAttributeExpressionTests.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using AutoFixture;
using DynamoDBGenerator.Attributes;
using DynamoDBGenerator.Extensions;
namespace DynamoDBGenerator.SourceGenerator.Tests.Extensions;
[DynamoDBMarshaller(EntityType = typeof(OrderAttributeExpressionTests))]
public partial class ToAttributeExpressionTests
{
private readonly Fixture _fixture = new();
[Fact]
public void ToAttributeExpression_Single_ObjectAssignmentExpression()
{
var order = _fixture.Create<OrderAttributeExpressionTests>();
var result = OrderAttributeExpressionTestsMarshaller
.ToAttributeExpression(order, (x, y) => $"SET {x.UserEntity} = {y.UserEntity}");
result.Values
.Should()
.SatisfyRespectively(x =>
{
x.Key.Should().Be(":p1");
x.Value.M.Should().SatisfyRespectively(
y =>
{
y.Key.Should().Be(nameof(OrderAttributeExpressionTests.UserEntity.Id));
y.Value.S.Should().Be(order.UserEntity.Id);
}, y =>
{
y.Key.Should().Be(nameof(OrderAttributeExpressionTests.UserEntity.DisplayName));
y.Value.S.Should().Be(order.UserEntity.DisplayName);
});
});
result.Names.Should().SatisfyRespectively(x =>
{
x.Key.Should().Be("#User");
x.Value.Should().Be("User");
});
result.Expressions.Should().SatisfyRespectively(x => x.Should().Be("SET #User = :p1"));
}
[Fact]
public void ToAttributeExpression_Double_ObjectAssignmentExpression()
{
var order = _fixture.Create<OrderAttributeExpressionTests>();
var result = OrderAttributeExpressionTestsMarshaller
.ToAttributeExpression(order, (x, y) => $"SET {x.UserEntity} = {y.UserEntity}", (x, y) => $"{x.Id} = {y.Id}");
// Order of Values and Names do not match the access pattern in the expression.
// Their order is based on the the order of the yield returns of AccessedValues and AccessedNames.
result.Values
.Should()
.SatisfyRespectively(
x =>
{
x.Key.Should().Be(":p2");
x.Value.S.Should().Be(order.Id);
},
x =>
{
x.Key.Should().Be(":p1");
x.Value.M.Should().SatisfyRespectively(
y =>
{
y.Key.Should().Be(nameof(OrderAttributeExpressionTests.UserEntity.Id));
y.Value.S.Should().Be(order.UserEntity.Id);
}, y =>
{
y.Key.Should().Be(nameof(OrderAttributeExpressionTests.UserEntity.DisplayName));
y.Value.S.Should().Be(order.UserEntity.DisplayName);
});
}
);
result.Names
.Should()
.SatisfyRespectively(
x =>
{
x.Key.Should().Be("#Id");
x.Value.Should().Be("Id");
},
x =>
{
x.Key.Should().Be("#User");
x.Value.Should().Be("User");
}
);
result.Expressions.Should().SatisfyRespectively(x => x.Should().Be("SET #User = :p1"), x => x.Should().Be("#Id = :p2"));
}
[Fact]
public void ToAttributeExpression_Single_Expression()
{
var order = _fixture.Create<OrderAttributeExpressionTests>();
var result = OrderAttributeExpressionTestsMarshaller
.ToAttributeExpression(order, (x, y) => $"{x.Id} <> {y.Id}");
result.Expressions
.Should()
.SatisfyRespectively(x => x.Should().Be("#Id <> :p1"));
result.Names
.Should()
.SatisfyRespectively(x =>
{
x.Key.Should().Be("#Id");
x.Value.Should().Be("Id");
});
result.Values
.Should()
.SatisfyRespectively(x =>
{
x.Key.Should().Be(":p1");
x.Value.S.Should().Be(order.Id);
});
}
[Fact]
public void ToAttributeExpression_Double_Expressions()
{
var order = _fixture.Create<OrderAttributeExpressionTests>();
var result = OrderAttributeExpressionTestsMarshaller
.ToAttributeExpression(
order,
(x, y) => $"{x.Id} <> {y.Id}",
(x, y) => $"SET {x.Id} = {y.Id}"
);
result.Expressions
.Should()
.SatisfyRespectively(
x => x.Should().Be("#Id <> :p1"),
x => x.Should().Be("SET #Id = :p1")
);
result.Names
.Should()
.SatisfyRespectively(x =>
{
x.Key.Should().Be("#Id");
x.Value.Should().Be("Id");
});
result.Values
.Should()
.SatisfyRespectively(x =>
{
x.Key.Should().Be(":p1");
x.Value.S.Should().Be(order.Id);
});
}
}
public class OrderAttributeExpressionTests
{
public string Id { get; set; } = null!;
public decimal TotalPrice { get; set; }
public string ClientId { get; set; } = null!;
[DynamoDBProperty("User")]
public User UserEntity { get; set; } = null!;
public class User
{
public string Id { get; set; } = null!;
public string DisplayName { get; set; } = null!;
}
}