-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
FormatNamesOfMembers.cs
66 lines (64 loc) · 2.74 KB
/
FormatNamesOfMembers.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
using System.Linq;
using EFCorePgExercises.DataLayer;
using EFCorePgExercises.Utils;
using FluentAssertions;
namespace EFCorePgExercises.Exercises.StringOperations
{
[FullyQualifiedTestClass]
public class FormatNamesOfMembers
{
[FullyQualifiedTestMethod]
public void Test()
{
// https://pgexercises.com/questions/string/concat.html
// Output the names of all members, formatted as 'Surname, Firstname'
//
// select surname || ', ' || firstname as name from cd.members
EFServiceProvider.RunInContext(context =>
{
var members = context.Members
.Select(member => new { Name = member.Surname + ", " + member.FirstName })
.ToList();
/*
SELECT ([m].[Surname] + N', ') + [m].[FirstName] AS [Name]
FROM [Members] AS [m]
*/
var expectedResult = new[]
{
new { Name = "GUEST, GUEST" },
new { Name = "Smith, Darren" },
new { Name = "Smith, Tracy" },
new { Name = "Rownam, Tim" },
new { Name = "Joplette, Janice" },
new { Name = "Butters, Gerald" },
new { Name = "Tracy, Burton" },
new { Name = "Dare, Nancy" },
new { Name = "Boothe, Tim" },
new { Name = "Stibbons, Ponder" },
new { Name = "Owen, Charles" },
new { Name = "Jones, David" },
new { Name = "Baker, Anne" },
new { Name = "Farrell, Jemima" },
new { Name = "Smith, Jack" },
new { Name = "Bader, Florence" },
new { Name = "Baker, Timothy" },
new { Name = "Pinker, David" },
new { Name = "Genting, Matthew" },
new { Name = "Mackenzie, Anna" },
new { Name = "Coplin, Joan" },
new { Name = "Sarwin, Ramnaresh" },
new { Name = "Jones, Douglas" },
new { Name = "Rumney, Henrietta" },
new { Name = "Farrell, David" },
new { Name = "Worthington-Smyth, Henry" },
new { Name = "Purview, Millicent" },
new { Name = "Tupperware, Hyacinth" },
new { Name = "Hunt, John" },
new { Name = "Crumpet, Erica" },
new { Name = "Smith, Darren" }
};
members.Should().BeEquivalentTo(expectedResult);
});
}
}
}