Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit 8b8dd3d

Browse files
author
Iain Scott
committed
Magically use one collection for multiple entity types.
1 parent 9615211 commit 8b8dd3d

18 files changed

Lines changed: 1250 additions & 0 deletions

.gitignore

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
*.swp
2+
*~
3+
4+
.vs/
5+
6+
.idea/
7+
8+
## Ignore Visual Studio temporary files, build results, and
9+
## files generated by popular Visual Studio add-ons.
10+
11+
# User-specific files
12+
*.suo
13+
*.user
14+
*.sln.docstates
15+
16+
# Build results
17+
[Dd]ebug/
18+
[Dd]ebugPublic/
19+
[Rr]elease/
20+
x64/
21+
build/
22+
bld/
23+
[Bb]in/
24+
[Oo]bj/
25+
26+
# MSTest test Results
27+
[Tt]est[Rr]esult*/
28+
[Bb]uild[Ll]og.*
29+
30+
#NUNIT
31+
*.VisualState.xml
32+
TestResult.xml
33+
34+
# Visual C++ cache files
35+
ipch/
36+
*.aps
37+
*.ncb
38+
*.opensdf
39+
*.sdf
40+
*.cachefile
41+
42+
# Visual Studio profiler
43+
*.psess
44+
*.vsp
45+
*.vspx
46+
47+
# ReSharper is a .NET coding add-in
48+
_ReSharper*/
49+
*.[Rr]e[Ss]harper
50+
*.DotSettings.user
51+
52+
# TeamCity is a build add-in
53+
_TeamCity*
54+
55+
# DotCover is a Code Coverage Tool
56+
*.dotCover
57+
58+
# Click-Once directory
59+
publish/
60+
61+
# Publish Web Output
62+
*.[Pp]ublish.xml
63+
*.azurePubxml
64+
*.pubxml
65+
66+
# NuGet Packages Directory
67+
packages/*
68+
## TODO: If the tool you use requires repositories.config
69+
## uncomment the next line
70+
#!packages/repositories.config
71+
72+
# Enable "build/" folder in the NuGet Packages folder since
73+
# NuGet packages use it for MSBuild targets.
74+
# This line needs to be after the ignore of the build folder
75+
# (and the packages folder if the line above has been uncommented)
76+
!packages/build/
77+
78+
# Others
79+
*.Cache
80+
ClientBin/
81+
~$*
82+
*~
83+
*.dbmdl
84+
*.dbproj.schemaview
85+
*.pfx
86+
*.publishsettings
87+
node_modules/
88+
89+
# Backup & report files from converting an old project file
90+
# to a newer Visual Studio version. Backup files are not needed,
91+
# because we have git ;-)
92+
_UpgradeReport_Files/
93+
Backup*/
94+
UpgradeLog*.XML
95+
UpgradeLog*.htm
96+
97+
# SQL Server files
98+
*.mdf
99+
*.ldf
100+
101+
## Certificates
102+
*.pem
103+
104+
logs/
105+
*.log
106+
*.sln.DotSettings

GitVersionConfig.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
assembly-versioning-scheme: MajorMinorPatch
2+
mode: ContinuousDeployment
3+
4+
# It would be better to use smarter regexes instead of duplicating everything for local and remote cases.
5+
# However, GitVersion has some built-in patterns which cannot be removed and these would cause clashes.
6+
branches:
7+
8+
# These branch patterns cover all local cases
9+
master:
10+
regex: master
11+
tag: master
12+
increment: Minor
13+
prevent-increment-of-merged-branch-version: true
14+
feature:
15+
regex: feature[/-]
16+
tag: a{BranchName}
17+
increment: Minor
18+
prevent-increment-of-merged-branch-version: false
19+
patch:
20+
regex: patch[/-]
21+
tag: useBranchName
22+
increment: Patch
23+
prevent-increment-of-merged-branch-version: false
24+
release:
25+
regex: release[/-]
26+
tag: rc
27+
increment: None
28+
prevent-increment-of-merged-branch-version: false
29+
30+
# These branch patterns cover all remote cases
31+
origin/master:
32+
regex: origin/master
33+
tag: master
34+
increment: Minor
35+
prevent-increment-of-merged-branch-version: true
36+
origin/feature:
37+
regex: origin/feature[/-]
38+
tag: a{BranchName}
39+
increment: Minor
40+
prevent-increment-of-merged-branch-version: false
41+
origin/patch:
42+
regex: origin/patch[/-]
43+
tag: useBranchName
44+
increment: Patch
45+
prevent-increment-of-merged-branch-version: false
46+
origin/release:
47+
regex: origin/release[/-]
48+
tag: rc
49+
increment: None
50+
prevent-increment-of-merged-branch-version: false

Jenkinsfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!groovy
2+
3+
node {
4+
step([$class: 'StashNotifier'])
5+
try {
6+
stage("Clone") {
7+
checkout scm
8+
}
9+
10+
stage("Restore") {
11+
bat "dotnet restore --source https://packages/repository/nuget-group-libs/"
12+
}
13+
14+
stage("Build") {
15+
bat("\"${tool 'MSBuild15'}\" /p:Configuration=Release")
16+
}
17+
18+
stage("Test") {
19+
dir("test\\Winton.DomainModelling.DocumentDb.Tests") {
20+
bat("dotnet test Winton.DomainModelling.DocumentDb.Tests.csproj --configuration Release --no-restore --no-build")
21+
}
22+
}
23+
24+
stage("Publish") {
25+
dir("src\\Winton.DomainModelling.DocumentDb\\bin") {
26+
bat("dotnet nuget push **\\*.nupkg --source https://packages/repository/nuget-hosted-libs/")
27+
}
28+
}
29+
30+
stage("Archive") {
31+
archive "**\\*.nupkg"
32+
}
33+
34+
currentBuild.result = "SUCCESS"
35+
}
36+
catch (err) {
37+
currentBuild.result = "FAILURE"
38+
throw err
39+
}
40+
finally{
41+
step([$class: 'StashNotifier'])
42+
}
43+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2026
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B70E1756-208C-4D97-9C84-CFE1625977FF}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8BDE761F-4C37-4AE9-93C5-482FB9F533AD}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Winton.DomainModelling.DocumentDb", "src\Winton.DomainModelling.DocumentDb\Winton.DomainModelling.DocumentDb.csproj", "{23C5B1FF-7F50-4C40-BA2D-3177B14F46DD}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Winton.DomainModelling.DocumentDb.Tests", "test\Winton.DomainModelling.DocumentDb.Tests\Winton.DomainModelling.DocumentDb.Tests.csproj", "{25F76BEB-C750-48AD-A94B-E6D3ECBD64F8}"
13+
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Winton.DomainModelling.DocumentDb.Tests.Integration", "test\Winton.DomainModelling.DocumentDb.Tests.Integration\Winton.DomainModelling.DocumentDb.Tests.Integration.csproj", "{56469B0B-2BF2-4961-9511-9D89A08DD9C6}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{90869527-D332-48C8-9D75-FF16E8E72973}"
17+
ProjectSection(SolutionItems) = preProject
18+
.gitignore = .gitignore
19+
GitVersionConfig.yaml = GitVersionConfig.yaml
20+
Jenkinsfile = Jenkinsfile
21+
README.md = README.md
22+
stylecop.json = stylecop.json
23+
EndProjectSection
24+
EndProject
25+
Global
26+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
27+
Debug|Any CPU = Debug|Any CPU
28+
Release|Any CPU = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
31+
{23C5B1FF-7F50-4C40-BA2D-3177B14F46DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{23C5B1FF-7F50-4C40-BA2D-3177B14F46DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{23C5B1FF-7F50-4C40-BA2D-3177B14F46DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{23C5B1FF-7F50-4C40-BA2D-3177B14F46DD}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{25F76BEB-C750-48AD-A94B-E6D3ECBD64F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{25F76BEB-C750-48AD-A94B-E6D3ECBD64F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{25F76BEB-C750-48AD-A94B-E6D3ECBD64F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{25F76BEB-C750-48AD-A94B-E6D3ECBD64F8}.Release|Any CPU.Build.0 = Release|Any CPU
39+
{56469B0B-2BF2-4961-9511-9D89A08DD9C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{56469B0B-2BF2-4961-9511-9D89A08DD9C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{56469B0B-2BF2-4961-9511-9D89A08DD9C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{56469B0B-2BF2-4961-9511-9D89A08DD9C6}.Release|Any CPU.Build.0 = Release|Any CPU
43+
EndGlobalSection
44+
GlobalSection(SolutionProperties) = preSolution
45+
HideSolutionNode = FALSE
46+
EndGlobalSection
47+
GlobalSection(NestedProjects) = preSolution
48+
{23C5B1FF-7F50-4C40-BA2D-3177B14F46DD} = {B70E1756-208C-4D97-9C84-CFE1625977FF}
49+
{25F76BEB-C750-48AD-A94B-E6D3ECBD64F8} = {8BDE761F-4C37-4AE9-93C5-482FB9F533AD}
50+
{56469B0B-2BF2-4961-9511-9D89A08DD9C6} = {8BDE761F-4C37-4AE9-93C5-482FB9F533AD}
51+
EndGlobalSection
52+
GlobalSection(ExtensibilityGlobals) = postSolution
53+
SolutionGuid = {F39C7D3E-5DF8-4F40-86E7-6C14FD9F6067}
54+
EndGlobalSection
55+
EndGlobal
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace Winton.DomainModelling.DocumentDb
5+
{
6+
internal sealed class EntityDocument<TEntity, TEntityId>
7+
where TEntity : Entity<TEntityId>
8+
where TEntityId : IEquatable<TEntityId>
9+
{
10+
public EntityDocument(TEntity entity)
11+
{
12+
Entity = entity;
13+
}
14+
15+
public TEntity Entity { get; }
16+
17+
[JsonProperty(PropertyName = "id")]
18+
public string Id => GetDocumentId(Entity.Id);
19+
20+
public string Type => GetDocumentType();
21+
22+
public static string GetDocumentId(TEntityId id)
23+
{
24+
return $"{GetDocumentType()}_{JsonConvert.SerializeObject(id)}";
25+
}
26+
27+
public static string GetDocumentType()
28+
{
29+
return typeof(TEntity).Name;
30+
}
31+
}
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using Newtonsoft.Json.Linq;
3+
4+
namespace Winton.DomainModelling.DocumentDb
5+
{
6+
internal static class EntityExtensions
7+
{
8+
public static TEntity WithId<TEntity, TEntityId>(this TEntity entity)
9+
where TEntity : Entity<TEntityId>
10+
where TEntityId : IEquatable<TEntityId>
11+
{
12+
if (!Equals(entity.Id, default(TEntityId)))
13+
{
14+
return entity;
15+
}
16+
17+
JObject jObject = JObject.FromObject(entity);
18+
jObject[nameof(Entity<TEntityId>.Id)] = Guid.NewGuid();
19+
20+
try
21+
{
22+
return jObject.ToObject<TEntity>();
23+
}
24+
catch (Exception)
25+
{
26+
throw new NotSupportedException($"Automatic generation of {typeof(TEntityId).Name} ID not supported.");
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)