|
5 | 5 | using Linq.PropertyTranslator.Core;
|
6 | 6 | using QueryInterceptor.Core;
|
7 | 7 | using Xunit;
|
| 8 | +using NFluent; |
8 | 9 | #if EFCORE
|
9 | 10 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
10 | 11 | #else
|
@@ -161,6 +162,71 @@ public void Select_Dynamic_IntoType()
|
161 | 162 | Assert.Equal(testList.Select(x => x.Profile).Cast<object>().ToList(), userProfiles.ToDynamicList());
|
162 | 163 | }
|
163 | 164 |
|
| 165 | + public class Example |
| 166 | + { |
| 167 | + public DateTime Time { get; set; } |
| 168 | + public DayOfWeek? DOWNull { get; set; } |
| 169 | + public DayOfWeek DOW { get; set; } |
| 170 | + public int Sec { get; set; } |
| 171 | + public int? SecNull { get; set; } |
| 172 | + } |
| 173 | + |
| 174 | + public class ExampleWithConstructor |
| 175 | + { |
| 176 | + public DateTime Time { get; set; } |
| 177 | + public DayOfWeek? DOWNull { get; set; } |
| 178 | + public DayOfWeek DOW { get; set; } |
| 179 | + public int Sec { get; set; } |
| 180 | + public int? SecNull { get; set; } |
| 181 | + |
| 182 | + public ExampleWithConstructor(DateTime t, DayOfWeek? dn, DayOfWeek d, int s, int? sn) |
| 183 | + { |
| 184 | + Time = t; |
| 185 | + DOWNull = dn; |
| 186 | + DOW = d; |
| 187 | + Sec = s; |
| 188 | + SecNull = sn; |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + [Fact] |
| 193 | + public void Select_Dynamic_IntoTypeWithNullableProperties1() |
| 194 | + { |
| 195 | + // Arrange |
| 196 | + var dates = Enumerable.Repeat(0, 7) |
| 197 | + .Select((d, i) => new DateTime(2000, 1, 1).AddDays(i).AddSeconds(i)) |
| 198 | + .AsQueryable(); |
| 199 | + |
| 200 | + // Act |
| 201 | + IQueryable<Example> result = dates |
| 202 | + .Select(d => new Example { Time = d, DOWNull = d.DayOfWeek, DOW = d.DayOfWeek, Sec = d.Second, SecNull = d.Second }); |
| 203 | + IQueryable<Example> resultDynamic = dates |
| 204 | + .Select<Example>("new (it as Time, DayOfWeek as DOWNull, DayOfWeek as DOW, Second as Sec, int?(Second) as SecNull)"); |
| 205 | + |
| 206 | + // Assert |
| 207 | + Check.That(resultDynamic.First()).Equals(result.First()); |
| 208 | + Check.That(resultDynamic.Last()).Equals(result.Last()); |
| 209 | + } |
| 210 | + |
| 211 | + [Fact] |
| 212 | + public void Select_Dynamic_IntoTypeWithNullableProperties2() |
| 213 | + { |
| 214 | + // Arrange |
| 215 | + var dates = Enumerable.Repeat(0, 7) |
| 216 | + .Select((d, i) => new DateTime(2000, 1, 1).AddDays(i).AddSeconds(i)) |
| 217 | + .AsQueryable(); |
| 218 | + |
| 219 | + // Act |
| 220 | + IQueryable<ExampleWithConstructor> result = dates |
| 221 | + .Select(d => new ExampleWithConstructor(d, d.DayOfWeek, d.DayOfWeek, d.Second, d.Second)); |
| 222 | + IQueryable<ExampleWithConstructor> resultDynamic = dates |
| 223 | + .Select<ExampleWithConstructor>("new (it as Time, DayOfWeek as DOWNull, DayOfWeek as DOW, Second as Sec, int?(Second) as SecNull)"); |
| 224 | + |
| 225 | + // Assert |
| 226 | + Check.That(resultDynamic.First()).Equals(result.First()); |
| 227 | + Check.That(resultDynamic.Last()).Equals(result.Last()); |
| 228 | + } |
| 229 | + |
164 | 230 | [Fact]
|
165 | 231 | public void Select_Dynamic_Exceptions()
|
166 | 232 | {
|
|
0 commit comments