|
@@ -8,6 +8,7 @@ using Luticate2.Auth.Utils.Business.Fields;
|
8
|
8
|
using Luticate2.Auth.Utils.Business.ObjectConverter;
|
9
|
9
|
using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
|
10
|
10
|
using Luticate2.Auth.Utils.Dbo;
|
|
11
|
+using Luticate2.Auth.Utils.Dbo.Fields;
|
11
|
12
|
using Luticate2.Auth.Utils.Dbo.Result;
|
12
|
13
|
using Luticate2.Auth.Utils.Interfaces;
|
13
|
14
|
using Microsoft.Extensions.DependencyInjection;
|
|
@@ -79,12 +80,9 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
|
79
|
80
|
return options;
|
80
|
81
|
}
|
81
|
82
|
|
82
|
|
- [Fact]
|
83
|
|
- void Test1()
|
|
83
|
+ protected TestModel1 GetBasicModel()
|
84
|
84
|
{
|
85
|
|
- var serviceProvider = GetServiceProvider();
|
86
|
|
- var converter = serviceProvider.GetService<ILuObjectConverter<TestModel1, TestDbo1>>();
|
87
|
|
- var model = new TestModel1
|
|
85
|
+ return new TestModel1
|
88
|
86
|
{
|
89
|
87
|
id = Guid.NewGuid(),
|
90
|
88
|
name = "Test.",
|
|
@@ -100,12 +98,21 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
|
100
|
98
|
}
|
101
|
99
|
}
|
102
|
100
|
};
|
103
|
|
- var result = converter.Convert(model, LuPartialFieldsParser.Parse("*").Data, GetConverterOptions());
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ [Fact]
|
|
104
|
+ public void TestBasic1()
|
|
105
|
+ {
|
|
106
|
+ var serviceProvider = GetServiceProvider();
|
|
107
|
+ var converter = serviceProvider.GetService<ILuObjectConverter<TestModel1, TestDbo1>>();
|
|
108
|
+ var model = GetBasicModel();
|
|
109
|
+ var result = converter.Convert(model, new LuFieldDbo(), LuPartialFieldsParser.Parse("*").Data, GetConverterOptions());
|
104
|
110
|
Assert.Equal(LuStatus.Success.ToInt(), result.Status);
|
105
|
111
|
var dbo = result.Data as TestDbo1;
|
106
|
112
|
Assert.NotNull(dbo);
|
107
|
113
|
Assert.Equal(model.id, dbo.Id);
|
108
|
114
|
Assert.Equal(model.name, dbo.Name);
|
|
115
|
+ Assert.NotNull(dbo.TestDbo2s);
|
109
|
116
|
Assert.Equal(model.test_model2.Count, dbo.TestDbo2s.Count);
|
110
|
117
|
foreach (var e in model.test_model2.Zip(dbo.TestDbo2s, (model2, dbo2) => new {Model = model2, Dbo = dbo2}))
|
111
|
118
|
{
|
|
@@ -116,5 +123,59 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
|
116
|
123
|
Assert.Null(e.Dbo.TestDbo1);
|
117
|
124
|
}
|
118
|
125
|
}
|
|
126
|
+
|
|
127
|
+ [Fact]
|
|
128
|
+ void TestPath1()
|
|
129
|
+ {
|
|
130
|
+ var serviceProvider = GetServiceProvider();
|
|
131
|
+ var converter = serviceProvider.GetService<ILuObjectConverter<TestModel1, TestDbo1>>();
|
|
132
|
+ var model = GetBasicModel();
|
|
133
|
+ var result = converter.Convert(model, new LuFieldDbo(), LuPartialFieldsParser.Parse("Id").Data, GetConverterOptions());
|
|
134
|
+ Assert.Equal(LuStatus.Success.ToInt(), result.Status);
|
|
135
|
+ var dbo = result.Data as TestDbo1;
|
|
136
|
+ Assert.NotNull(dbo);
|
|
137
|
+ Assert.Equal(model.id, dbo.Id);
|
|
138
|
+ Assert.Null(dbo.Name);
|
|
139
|
+ Assert.Null(dbo.TestDbo2s);
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ [Fact]
|
|
143
|
+ void TestPath2()
|
|
144
|
+ {
|
|
145
|
+ var serviceProvider = GetServiceProvider();
|
|
146
|
+ var converter = serviceProvider.GetService<ILuObjectConverter<TestModel1, TestDbo1>>();
|
|
147
|
+ var model = GetBasicModel();
|
|
148
|
+ var result = converter.Convert(model, new LuFieldDbo(), LuPartialFieldsParser.Parse("id").Data, GetConverterOptions());
|
|
149
|
+ Assert.Equal(LuStatus.Success.ToInt(), result.Status);
|
|
150
|
+ var dbo = result.Data as TestDbo1;
|
|
151
|
+ Assert.NotNull(dbo);
|
|
152
|
+ Assert.Equal(model.id, dbo.Id);
|
|
153
|
+ Assert.Null(dbo.Name);
|
|
154
|
+ Assert.Null(dbo.TestDbo2s);
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ [Fact]
|
|
158
|
+ public void TestPath3()
|
|
159
|
+ {
|
|
160
|
+ var serviceProvider = GetServiceProvider();
|
|
161
|
+ var converter = serviceProvider.GetService<ILuObjectConverter<TestModel1, TestDbo1>>();
|
|
162
|
+ var model = GetBasicModel();
|
|
163
|
+ var result = converter.Convert(model, new LuFieldDbo(), LuPartialFieldsParser.Parse("Id, TestDbo2s(Id, Name)").Data, GetConverterOptions());
|
|
164
|
+ Assert.Equal(LuStatus.Success.ToInt(), result.Status);
|
|
165
|
+ var dbo = result.Data as TestDbo1;
|
|
166
|
+ Assert.NotNull(dbo);
|
|
167
|
+ Assert.Equal(model.id, dbo.Id);
|
|
168
|
+ Assert.Null(dbo.Name);
|
|
169
|
+ Assert.NotNull(dbo.TestDbo2s);
|
|
170
|
+ Assert.Equal(model.test_model2.Count, dbo.TestDbo2s.Count);
|
|
171
|
+ foreach (var e in model.test_model2.Zip(dbo.TestDbo2s, (model2, dbo2) => new {Model = model2, Dbo = dbo2}))
|
|
172
|
+ {
|
|
173
|
+ Assert.Equal(e.Model.id, e.Dbo.Id);
|
|
174
|
+ Assert.Equal(e.Model.name, e.Dbo.Name);
|
|
175
|
+ Assert.Null(e.Dbo.NameVirtual);
|
|
176
|
+ Assert.Null(e.Dbo.Parent);
|
|
177
|
+ Assert.Null(e.Dbo.TestDbo1);
|
|
178
|
+ }
|
|
179
|
+ }
|
119
|
180
|
}
|
120
|
181
|
}
|