├── .gitattributes
├── .gitignore
├── GenericLibsBase
├── App.config
├── Core
│ ├── SuccessOrErrors.Generic.cs
│ └── SuccessOrErrors.cs
├── GenericLibsBase.csproj
├── GenericLibsBaseConfig.cs
├── IGenericLogger.cs
├── ISuccessOrErrors.Generic.cs
├── ISuccessOrErrors.cs
├── NoLoggingGenericLogger.cs
├── NuGet
│ ├── AssemblyVersionPart.cs
│ ├── GenericLibsBase.nuspec
│ └── GenericLibsBaseNuGetIcon128-png8.png
├── Properties
│ └── AssemblyInfo.cs
└── SplitterExtension.cs
├── GenericServices.sln
├── GenericServices.sln.DotSettings
├── GenericServices
├── App.config
├── Core
│ ├── EfGenericDto.cs
│ ├── EfGenericDtoAsync.cs
│ ├── EfGenericDtoBase.Generic.Setup.cs
│ ├── EfGenericDtoBase.Generic.cs
│ ├── EfGenericDtoBase.cs
│ ├── IGenericDbContext.cs
│ ├── IGenericSaveChanges.cs
│ ├── InstrumentedEfGenericDto.cs
│ ├── InstrumentedEfGenericDtoAsync.cs
│ ├── InstrumentedLog.cs
│ ├── Internal
│ │ ├── BuildFilter.cs
│ │ ├── CheckComputed.cs
│ │ ├── DecodeToService.cs
│ │ ├── EfKeyFinder.cs
│ │ └── MappingHelper.cs
│ └── SecurityHelper.cs
├── DoNotCopyBackToDatabaseAttribute.cs
├── GenericServices.csproj
├── GenericServicesConfig.cs
├── ICreateService.cs
├── ICreateServiceAsync.cs
├── ICreateSetupService.cs
├── ICreateSetupServiceAsync.cs
├── IDeleteService.cs
├── IDeleteServiceAsync.cs
├── IDetailService.cs
├── IDetailServiceAsync.cs
├── IGenericServicesDbContext.cs
├── IListService.cs
├── IUpdateService.cs
├── IUpdateServiceAsync.cs
├── IUpdateSetupService.cs
├── IUpdateSetupServiceAsync.cs
├── NuGet
│ ├── AssemblyVersionPart.cs
│ ├── GenericServices.nuspec
│ ├── GenericServicesNuGetIcon128-png8.png
│ └── GenericServicesNuGetIcon128.png
├── Properties
│ └── AssemblyInfo.cs
├── SaveChangesExtensions.cs
├── Services
│ ├── Concrete
│ │ ├── CreateService.cs
│ │ ├── CreateSetupService.cs
│ │ ├── DeleteService.cs
│ │ ├── DetailService.cs
│ │ ├── ListService.cs
│ │ ├── UpdateService.cs
│ │ └── UpdateSetupService.cs
│ ├── ICreateService.cs
│ ├── ICreateSetupService.cs
│ ├── IDetailService.cs
│ ├── IListService.cs
│ ├── IUpdateService.cs
│ └── IUpdateSetupService.cs
├── ServicesAsync
│ ├── Concrete
│ │ ├── CreateServiceAsync.cs
│ │ ├── CreateSetupServiceAsync.cs
│ │ ├── DeleteServiceAsync.cs
│ │ ├── DetailServiceAsync.cs
│ │ ├── UpdateServiceAsync.cs
│ │ └── UpdateSetupServiceAsync.cs
│ ├── ICreateServiceAsync.cs
│ ├── ICreateSetupServiceAsync.cs
│ ├── IDetailServiceAsync.cs
│ ├── IUpdateServiceAsync.cs
│ └── IUpdateSetupServiceAsync.cs
├── obj
│ └── Debug
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
└── packages.config
├── ProfileApp
├── App.config
├── ProfileApp.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── README.md
├── Tests
├── App.config
├── DTOs
│ └── Concrete
│ │ ├── BadPostTagGradeMissingKeyDto.cs
│ │ ├── BadSpecialMappingDto.cs
│ │ ├── DelegateDecompileForced.cs
│ │ ├── DelegateDecompileNeededPostDto.cs
│ │ ├── DelegateDecompilePostDto.cs
│ │ ├── DelegateDecompilePostDtoAsync.cs
│ │ ├── DetailPostDto.cs
│ │ ├── DetailPostDtoAsync.cs
│ │ ├── PostSpecialMappingDto.cs
│ │ ├── SimpleBlogWithPostsDto.cs
│ │ ├── SimplePostDto.cs
│ │ ├── SimplePostDtoAsync.cs
│ │ ├── SimplePostTagGradeDto.cs
│ │ ├── SimpleTagDto.cs
│ │ ├── SimpleTagDtoAssociatedToDecompileClass.cs
│ │ ├── SimpleTagDtoAsync.cs
│ │ ├── SimpleTagPostGradeDto.cs
│ │ └── TabNeededTagAndDelegatePostDto.cs
├── DataClasses
│ ├── Concrete
│ │ ├── Blog.cs
│ │ ├── Helpers
│ │ │ └── TrackUpdate.cs
│ │ ├── Post.cs
│ │ ├── PostLink.cs
│ │ ├── PostTagGrade.cs
│ │ └── Tag.cs
│ ├── DataLayerInitialise.cs
│ ├── Internal
│ │ └── LoadDbDataFromXml.cs
│ └── SampleWebAppDb.cs
├── Helpers
│ ├── DatabaseHelpers.cs
│ ├── DbSnapShot.cs
│ ├── DummyIDbContextWithValidation.cs
│ ├── ExtendAsserts.cs
│ ├── Log4NetGenericLogger.cs
│ ├── TestFileHelpers.cs
│ ├── TimerToConsole.cs
│ └── TraceGenericLogger.cs
├── Properties
│ └── AssemblyInfo.cs
├── TestData
│ └── DbContentSimple.xml
├── Tests.csproj
├── UiHelpers
│ ├── DropDownListType.cs
│ └── MultiSelectListType.cs
├── UnitTests
│ ├── Group00GenericLibsBase
│ │ ├── Test01SuccessOrErrors.cs
│ │ ├── Test03SuccessOrErrorsT.cs
│ │ ├── Test04SplitCamel.cs
│ │ ├── Test05SetupLogger.cs
│ │ ├── Test06Log4NetGenericLogger.cs
│ │ └── Test07TraceGenericLogger.cs
│ ├── Group01Configuration
│ │ ├── Test02SqlDict.cs
│ │ ├── Test05HandleSqlException.cs
│ │ └── Test10RealiseSingleException.cs
│ ├── Group02DataClasses
│ │ ├── Tests01Setup.cs
│ │ ├── Tests02Validation.cs
│ │ ├── Tests04ReadWrite.cs
│ │ ├── Tests06DelegateDecompiler.cs
│ │ ├── Tests10CheckKeysManipulation.cs
│ │ ├── Tests12BuildFilter.cs
│ │ └── Tests90CheckDbUpdateException.cs
│ ├── Group03ServiceFlow
│ │ ├── Test01CreateService.cs
│ │ ├── Test02UpdateService.cs
│ │ └── Test03DetailService.cs
│ ├── Group04ServiceFlowAsync
│ │ ├── Test01CreateServiceAsync.cs
│ │ ├── Test02UpdateServiceAsync.cs
│ │ └── Test03DetailServiceAsync.cs
│ ├── Group08CrudServices
│ │ ├── Test01AutoMapper.cs
│ │ ├── Test01DelegateDecompiler.cs
│ │ ├── Test02PostsDirect.cs
│ │ ├── Test02aPostTagGradeDirect.cs
│ │ ├── Test03AGenericDtoSetup.cs
│ │ ├── Test03BCheckGenericDto.cs
│ │ ├── Test04PostsViaSimpleDto.cs
│ │ ├── Test05PostsViaDetailDto.cs
│ │ ├── Test07BlogsViaDetailDto.cs
│ │ └── Test08PostTagGradeViaDto.cs
│ ├── Group09CrudServicesAsync
│ │ ├── Test02PostsDirectAsync.cs
│ │ ├── Test03CheckGenericDtoAsync.cs
│ │ ├── Test04PostsViaSimpleDtoAsync.cs
│ │ └── Test05PostsViaDetailDtoAsync.cs
│ ├── Group15CrudServiceFinder
│ │ ├── Test02DecodeToService.cs
│ │ ├── Test04CreateServices.cs
│ │ └── Test05CreateServicesAsync.cs
│ └── Group80Performance
│ │ ├── Perf01CheckHelpers.cs
│ │ ├── Perf03EfPost.cs
│ │ ├── Perf04EfPostAsync.cs
│ │ ├── Perf05PostsViaSimpleDto.cs
│ │ ├── Perf06PostsViaSimpleDtoAsync.cs
│ │ ├── Perf07PostsViaDetailDto.cs
│ │ ├── Perf08PostsViaDetailDtoAsync.cs
│ │ └── Perf10PostPerformance.cs
└── packages.config
├── licence.txt
└── packages
├── .gitignore
└── repositories.config
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 |
11 | [Dd]ebug/
12 | [Rr]elease/
13 | x64/
14 | build/
15 | [Bb]in/
16 | [Oo]bj/
17 |
18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
19 | !packages/*/build/
20 |
21 | # MSTest test Results
22 | [Tt]est[Rr]esult*/
23 | [Bb]uild[Ll]og.*
24 |
25 | *_i.c
26 | *_p.c
27 | *.ilk
28 | *.meta
29 | *.obj
30 | *.pch
31 | *.pdb
32 | *.pgc
33 | *.pgd
34 | *.rsp
35 | *.sbr
36 | *.tlb
37 | *.tli
38 | *.tlh
39 | *.tmp
40 | *.tmp_proj
41 | *.log
42 | *.vspscc
43 | *.vssscc
44 | .builds
45 | *.pidb
46 | *.log
47 | *.scc
48 |
49 | # Visual C++ cache files
50 | ipch/
51 | *.aps
52 | *.ncb
53 | *.opensdf
54 | *.sdf
55 | *.cachefile
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 | *.vspx
61 |
62 | # Guidance Automation Toolkit
63 | *.gpState
64 |
65 | # ReSharper is a .NET coding add-in
66 | _ReSharper*/
67 | *.[Rr]e[Ss]harper
68 |
69 | # TeamCity is a build add-in
70 | _TeamCity*
71 |
72 | # DotCover is a Code Coverage Tool
73 | *.dotCover
74 |
75 | # NCrunch
76 | *.ncrunch*
77 | .*crunch*.local.xml
78 |
79 | # Installshield output folder
80 | [Ee]xpress/
81 |
82 | # DocProject is a documentation generator add-in
83 | DocProject/buildhelp/
84 | DocProject/Help/*.HxT
85 | DocProject/Help/*.HxC
86 | DocProject/Help/*.hhc
87 | DocProject/Help/*.hhk
88 | DocProject/Help/*.hhp
89 | DocProject/Help/Html2
90 | DocProject/Help/html
91 |
92 | # Click-Once directory
93 | publish/
94 |
95 | # Publish Web Output
96 | *.Publish.xml
97 |
98 | # NuGet Packages Directory
99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
100 | #packages/
101 |
102 | # Windows Azure Build Output
103 | csx
104 | *.build.csdef
105 |
106 | # Windows Store app package directory
107 | AppPackages/
108 |
109 | # Others
110 | sql/
111 | *.Cache
112 | ClientBin/
113 | [Ss]tyle[Cc]op.*
114 | ~$*
115 | *~
116 | *.dbmdl
117 | *.[Pp]ublish.xml
118 | *.pfx
119 | *.publishsettings
120 |
121 | # RIA/Silverlight projects
122 | Generated_Code/
123 |
124 | # Backup & report files from converting an old project file to a newer
125 | # Visual Studio version. Backup files are not needed, because we have git ;-)
126 | _UpgradeReport_Files/
127 | Backup*/
128 | UpgradeLog*.XML
129 | UpgradeLog*.htm
130 |
131 | # SQL Server files
132 | App_Data/*.mdf
133 | App_Data/*.ldf
134 |
135 |
136 | #LightSwitch generated files
137 | GeneratedArtifacts/
138 | _Pvt_Extensions/
139 | ModelManifest.xml
140 |
141 | # =========================
142 | # Windows detritus
143 | # =========================
144 |
145 | # Windows image file caches
146 | Thumbs.db
147 | ehthumbs.db
148 |
149 | # Folder config file
150 | Desktop.ini
151 |
152 | # Recycle Bin used on file shares
153 | $RECYCLE.BIN/
154 |
155 | # Mac desktop service store files
156 | .DS_Store
157 | /Tests/DataClasses/CutDownValidation.cs
158 | /GenericServices/NuGet/GenericServices.1.0.0-beta4.nupkg
159 | /GenericServices/NuGet/GenericServices.1.0.0-beta5.nupkg
160 | *.nupkg
161 |
--------------------------------------------------------------------------------
/GenericLibsBase/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/GenericLibsBase/GenericLibsBase.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {40D13D8E-7FF8-4097-A46B-B32DC997F1EE}
8 | Library
9 | Properties
10 | GenericLibsBase
11 | GenericLibsBase
12 | v4.5.1
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 | bin\Release\GenericLibsBase.XML
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 |
70 |
--------------------------------------------------------------------------------
/GenericLibsBase/GenericLibsBaseConfig.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: GenericLibsBaseConfig.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 |
30 | namespace GenericLibsBase
31 | {
32 | ///
33 | /// This static class holds the GenericLibsBase configuration
34 | ///
35 | public static class GenericLibsBaseConfig
36 | {
37 | ///
38 | /// This is a constant noLogger. Used when no logging is needed.
39 | ///
40 | public static readonly IGenericLogger NoLoggerInstance = new NoLoggingGenericLogger();
41 |
42 | ///
43 | /// This should be given a method that takes a string, to have the logger, and returns an IGenericLogger instance.
44 | ///
45 | public static Func SetLoggerMethod { private get; set; }
46 |
47 | ///
48 | /// This returns the logger set in the Generic Service package
49 | ///
50 | ///
51 | ///
52 | public static IGenericLogger GetLogger( string name)
53 | {
54 | return SetLoggerMethod(name);
55 | }
56 |
57 | static GenericLibsBaseConfig()
58 | {
59 | SetLoggerMethod = name => NoLoggerInstance;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/GenericLibsBase/IGenericLogger.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IGenericLogger.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 |
30 | namespace GenericLibsBase
31 | {
32 |
33 | public interface IGenericLogger
34 | {
35 | void Verbose(object message);
36 | void VerboseFormat(string format, params object[] args);
37 | void Info(object message);
38 | void InfoFormat(string format, params object[] args);
39 | void Warn(object message);
40 | void WarnFormat(string format, params object[] args);
41 | void Error(object message);
42 | void ErrorFormat(string format, params object[] args);
43 | void Critical(object message);
44 | void Critical(object message, Exception ex); //this is for logging exceptions
45 | void CriticalFormat(string format, params object[] args);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/GenericLibsBase/NoLoggingGenericLogger.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: NoLoggingGenericLogger.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 |
30 | namespace GenericLibsBase
31 | {
32 | ///
33 | /// This is the default Generic Logger, which does no logging
34 | ///
35 | public class NoLoggingGenericLogger : IGenericLogger
36 | {
37 | public void Verbose(object message) { }
38 | public void VerboseFormat(string format, params object[] args) { }
39 | public void Info(object message) { }
40 | public void InfoFormat(string format, params object[] args) { }
41 | public void Warn(object message) { }
42 | public void WarnFormat(string format, params object[] args) { }
43 | public void Error(object message) { }
44 | public void ErrorFormat(string format, params object[] args) { }
45 | public void Critical(object message) { }
46 | public void Critical(object message, Exception ex) { }
47 | public void CriticalFormat(string format, params object[] args) { }
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/GenericLibsBase/NuGet/AssemblyVersionPart.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: AssemblyVersionPart.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Reflection;
29 |
30 | // THIS HOLDS THE VERSION PART OF THE ASSEMBLY
31 | // Alter this before building for Nuget pack
32 |
33 | // Version information for an assembly consists of the following four values:
34 | //
35 | // Major Version
36 | // Minor Version
37 | // Build Number
38 | // Revision
39 | //
40 | // You can specify all the values or you can default the Build and Revision Numbers
41 | // by using the '*' as shown below:
42 | // [assembly: AssemblyVersion("1.0.*")]
43 |
44 | [assembly: AssemblyVersion("1.0.0.0")]
45 | [assembly: AssemblyFileVersion("1.0.0.0")]
46 | [assembly: AssemblyInformationalVersion("1.0.0")]
47 |
--------------------------------------------------------------------------------
/GenericLibsBase/NuGet/GenericLibsBase.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
44 |
45 | GenericLibsBase
46 | 1.0.1
47 | GenericLibsBase
48 | Jon Smith
49 | Jon Smith
50 | https://github.com/JonPSmith/GenericServices/blob/master/licence.txt
51 | https://github.com/JonPSmith/GenericServices
52 | https://raw.githubusercontent.com/JonPSmith/GenericServices/master/GenericLibsBase/NuGet/GenericLibsBaseNuGetIcon128-png8.png
53 | false
54 |
55 | GenericLibsBase is a very small .NET class library holds common items used by GenericServices and other GenericXXX libraries.
56 |
57 | Added HasErrors, Combine() and GetAllErrors() to SuccessOrErrors/SuccessOrErrors.Generic to make working with nested methods returning a status easier to work with.
58 | Copyright 2015
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/GenericLibsBase/NuGet/GenericLibsBaseNuGetIcon128-png8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericLibsBase/NuGet/GenericLibsBaseNuGetIcon128-png8.png
--------------------------------------------------------------------------------
/GenericLibsBase/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: AssemblyInfo.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Reflection;
29 | using System.Resources;
30 | using System.Runtime.InteropServices;
31 |
32 | // General Information about an assembly is controlled through the following
33 | // set of attributes. Change these attribute values to modify the information
34 | // associated with an assembly.
35 | [assembly: AssemblyTitle("GenericLibsBase")]
36 | [assembly: AssemblyDescription("Base library for GenericServices and other GenericXXX libraries")]
37 | [assembly: AssemblyConfiguration("")]
38 | [assembly: AssemblyCompany("Selective Analytics")]
39 | [assembly: AssemblyProduct("GenericLibsBase")]
40 | [assembly: AssemblyCopyright("Copyright © Jon Smith 2014")]
41 | [assembly: AssemblyTrademark("")]
42 | [assembly: AssemblyCulture("")]
43 |
44 | // Setting ComVisible to false makes the types in this assembly not visible
45 | // to COM components. If you need to access a type in this assembly from
46 | // COM, set the ComVisible attribute to true on that type.
47 | [assembly: ComVisible(false)]
48 |
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM
50 | [assembly: Guid("08d7adff-4971-47c4-a403-3a79a5d0722e")]
51 |
52 | [assembly: NeutralResourcesLanguage("en")]
53 |
--------------------------------------------------------------------------------
/GenericLibsBase/SplitterExtension.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SplitterExtension.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Text.RegularExpressions;
29 |
30 | namespace GenericLibsBase
31 | {
32 | public static class SplitterExtension
33 | {
34 | private static readonly Regex Reg = new Regex("([a-z,0-9](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", RegexOptions.Compiled);
35 |
36 | ///
37 | /// This splits up a string based on capital letters
38 | /// e.g. "MyAction" would become "My Action" and "My10Action" would become "My10 Action"
39 | ///
40 | ///
41 | ///
42 | public static string SplitCamelCase(this string str)
43 | {
44 | return Reg.Replace(str, "$1 ");
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/GenericServices.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericServices", "GenericServices\GenericServices.csproj", "{92F121B3-2F0D-48C3-B150-7DCA84B7F8E1}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{EDCF4F2B-3C6F-4A5A-9D46-BAD85C85254B}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{340C8783-D265-43DB-9396-A901648843B2}"
11 | ProjectSection(SolutionItems) = preProject
12 | licence.txt = licence.txt
13 | README.md = README.md
14 | EndProjectSection
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericLibsBase", "GenericLibsBase\GenericLibsBase.csproj", "{40D13D8E-7FF8-4097-A46B-B32DC997F1EE}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProfileApp", "ProfileApp\ProfileApp.csproj", "{C4E55EB2-6175-49EE-82EB-F9812255F63F}"
19 | EndProject
20 | Global
21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 | Debug|Any CPU = Debug|Any CPU
23 | Release|Any CPU = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {92F121B3-2F0D-48C3-B150-7DCA84B7F8E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {92F121B3-2F0D-48C3-B150-7DCA84B7F8E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {92F121B3-2F0D-48C3-B150-7DCA84B7F8E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {92F121B3-2F0D-48C3-B150-7DCA84B7F8E1}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {EDCF4F2B-3C6F-4A5A-9D46-BAD85C85254B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {EDCF4F2B-3C6F-4A5A-9D46-BAD85C85254B}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {EDCF4F2B-3C6F-4A5A-9D46-BAD85C85254B}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {EDCF4F2B-3C6F-4A5A-9D46-BAD85C85254B}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {40D13D8E-7FF8-4097-A46B-B32DC997F1EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {40D13D8E-7FF8-4097-A46B-B32DC997F1EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {40D13D8E-7FF8-4097-A46B-B32DC997F1EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {40D13D8E-7FF8-4097-A46B-B32DC997F1EE}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {C4E55EB2-6175-49EE-82EB-F9812255F63F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {C4E55EB2-6175-49EE-82EB-F9812255F63F}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {C4E55EB2-6175-49EE-82EB-F9812255F63F}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {C4E55EB2-6175-49EE-82EB-F9812255F63F}.Release|Any CPU.Build.0 = Release|Any CPU
42 | EndGlobalSection
43 | GlobalSection(SolutionProperties) = preSolution
44 | HideSolutionNode = FALSE
45 | EndGlobalSection
46 | EndGlobal
47 |
--------------------------------------------------------------------------------
/GenericServices.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | licence
3 | The MIT License (MIT)
4 |
5 | Filename: $FILENAME$
6 | Date Created: $CREATED_YEAR$/$CREATED_MONTH$/$CREATED_DAY$
7 |
8 | Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
9 |
10 | Permission is hereby granted, free of charge, to any person obtaining a copy
11 | of this software and associated documentation files (the "Software"), to deal
12 | in the Software without restriction, including without limitation the rights
13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | copies of the Software, and to permit persons to whom the Software is
15 | furnished to do so, subject to the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be included in all
18 | copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 | SOFTWARE.
--------------------------------------------------------------------------------
/GenericServices/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/GenericServices/Core/IGenericDbContext.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IGenericDbContext.cs
5 | // Date Created: 2015/02/02
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Collections.Generic;
30 | using System.Data.Entity;
31 | using System.Data.Entity.Infrastructure;
32 | using System.Data.Entity.Validation;
33 |
34 | namespace GenericServices.Core
35 | {
36 | ///
37 | /// This is the core Generic DbContext that all GenericXXXDbContexts reference, but should not be used by a user of this library
38 | /// Anyone using GenericServices should use GenericServicesDbContexts
39 | /// This interface is used in all the commands so that they can be used by other GenericXXX libraries
40 | ///
41 | public interface IGenericDbContext : IDisposable
42 | {
43 |
44 | IEnumerable GetValidationErrors();
45 |
46 | DbSet Set() where TEntity : class;
47 | DbSet Set(Type entityType);
48 |
49 | DbEntityEntry Entry(TEntity entity) where TEntity : class;
50 | DbEntityEntry Entry(object entity);
51 | }
52 | }
--------------------------------------------------------------------------------
/GenericServices/Core/IGenericSaveChanges.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SaveChangesExtensions.cs
5 | // Date Created: 2014/09/25
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Threading.Tasks;
29 |
30 | namespace GenericServices.Core
31 | {
32 | ///
33 | /// This interface is used by the SaveChangesWithChecking extensions.
34 | /// Uses of the GenericServices library should not need to use this as IGenericSaveChanges is included in the IGenericSericesDbContext already
35 | ///
36 | public interface IGenericSaveChanges
37 | {
38 | int SaveChanges();
39 | Task SaveChangesAsync();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/GenericServices/Core/InstrumentedLog.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: InstrumentedLog.cs
5 | // Date Created: 2014/06/24
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | namespace GenericServices.Core
28 | {
29 | public enum CallTypes { Point, Start, End }
30 |
31 | public class InstrumentedLog
32 | {
33 | private readonly long _elapsedMilisecondsSoFar;
34 |
35 | public string CallPoint { get; private set; }
36 |
37 | public CallTypes CallType { get; private set; }
38 |
39 |
40 | public InstrumentedLog(string callPoint, CallTypes callType, long elapsedMilisecondsSoFar)
41 | {
42 | CallPoint = callPoint;
43 | CallType = callType;
44 | _elapsedMilisecondsSoFar = elapsedMilisecondsSoFar;
45 | }
46 |
47 | public override string ToString()
48 | {
49 | return string.Format("CallPoint: {0}, CallType: {1}, MilisecondsSoFar: {2}", CallPoint, CallType, _elapsedMilisecondsSoFar);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/GenericServices/Core/Internal/BuildFilter.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: BuildFilter.cs
5 | // Date Created: 2014/07/21
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System;
28 | using System.Collections.Generic;
29 | using System.Linq;
30 | using System.Linq.Expressions;
31 | using System.Reflection;
32 | using System.Runtime.CompilerServices;
33 |
34 | [assembly: InternalsVisibleTo("Tests")]
35 |
36 | namespace GenericServices.Core.Internal
37 | {
38 | internal static class BuildFilter
39 | {
40 |
41 | public static Expression> CreateFilter(IReadOnlyCollection keyProperties, object[] keyValues)
42 | {
43 | if (keyProperties.Count != keyValues.Length)
44 | throw new ArgumentException("The number of keys values provided does not match the number of keys in the entity class.");
45 |
46 | var x = Expression.Parameter(typeof(T), "x");
47 | var filterParts = keyProperties.Select((t, i) => BuildEqual(x, t, keyValues[i])).ToList();
48 | var combinedFilter = CombineFilters(filterParts);
49 |
50 | return Expression.Lambda>(combinedFilter, x);
51 | }
52 |
53 | private static Expression CombineFilters(List filterParts)
54 | {
55 | var result = filterParts.First();
56 | for (int i = 1; i < filterParts.Count; i++)
57 | result = Expression.AndAlso(result, filterParts[i]);
58 |
59 | return result;
60 | }
61 |
62 | private static BinaryExpression BuildEqual(ParameterExpression p, PropertyInfo prop, object expectedValue)
63 | {
64 | var m = Expression.Property(p, prop);
65 | var c = Expression.Constant(expectedValue);
66 | var ex = Expression.Equal(m, c);
67 | return ex;
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/GenericServices/Core/Internal/CheckComputed.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: CheckDecompile.cs
5 | // Date Created: 2015/1/12
6 | //
7 | // Copyright (c) 2015 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Collections.Concurrent;
30 | using System.Linq;
31 | using System.Reflection;
32 | using DelegateDecompiler;
33 |
34 | namespace GenericServices.Core.Internal
35 | {
36 | internal static class CheckComputed
37 | {
38 |
39 | ///
40 | /// This is the cache used to hold info on if the type contains the DelegateDecompiler [Computed] attribute
41 | ///
42 | private static readonly ConcurrentDictionary EntityHasComputed = new ConcurrentDictionary();
43 |
44 | private static bool CheckIfClassNeedsDecompile(Type type)
45 | {
46 | return (type.GetProperties().Any(x => x.GetCustomAttribute() != null));
47 | }
48 |
49 | ///
50 | /// This returns true if the config says we are using DelegateDecompiler and the class contains the DelegateDecompiler [Computed] attribute
51 | ///
52 | ///
53 | ///
54 | public static bool ClassNeedsDecompile(Type classToCheck)
55 | {
56 | return GenericServicesConfig.UseDelegateDecompilerWhereNeeded
57 | && EntityHasComputed.GetOrAdd(classToCheck, setup => CheckIfClassNeedsDecompile(classToCheck));
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/GenericServices/Core/Internal/MappingHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using AutoMapper;
3 |
4 | namespace GenericServices.Core.Internal
5 | {
6 | internal static class MappingHelper
7 | {
8 | ///
9 | /// This is used to filter out all properties that have a [DoNotCopyBackToDatabase] attribute.
10 | ///
11 | ///
12 | ///
13 | public static IMappingExpression IgnoreMarkedProperties
14 | (this IMappingExpression mappingExpression)
15 | {
16 | mappingExpression.ForAllMembers(x => x.Condition(mapContext => mapContext.PropertyMap.SourceMember != null &&
17 | mapContext.PropertyMap.SourceMember.GetCustomAttribute() == null));
18 | return mappingExpression;
19 | }
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/GenericServices/DoNotCopyBackToDatabaseAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace GenericServices
4 | {
5 | ///
6 | /// Place this on a property to stop it being copied back to the TEntity
7 | ///
8 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
9 | public class DoNotCopyBackToDatabaseAttribute : Attribute
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/GenericServices/ICreateService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateService.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface ICreateService
33 | {
34 | ///
35 | /// This adds a new entity class to the database with error checking
36 | ///
37 | /// The type of the data to output.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// either entity class or dto to create the data item with
40 | /// status
41 | ISuccessOrErrors Create(T newItem) where T : class;
42 |
43 | ///
44 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
45 | /// you need to display the view again with errors
46 | ///
47 | /// Must be a dto inherited from EfGenericDto
48 | ///
49 | T ResetDto(T dto) where T : class;
50 | }
51 | }
--------------------------------------------------------------------------------
/GenericServices/ICreateServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface ICreateServiceAsync
33 | {
34 | ///
35 | /// This adds a new entity class to the database with error checking
36 | ///
37 | /// The type of the data to output.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// either entity class or dto to create the data item with
40 | /// status
41 | Task CreateAsync(T newItem) where T : class;
42 |
43 | ///
44 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
45 | /// you need to display the view again with errors
46 | ///
47 | /// Must be a dto inherited from EfGenericDtoAsync
48 | ///
49 | Task ResetDtoAsync(T dto) where T : class;
50 | }
51 | }
--------------------------------------------------------------------------------
/GenericServices/ICreateSetupService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateSetupService.cs
5 | // Date Created: 2014/05/20
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | namespace GenericServices
28 | {
29 | public interface ICreateSetupService
30 | {
31 | ///
32 | /// This returns the dto with any data that is needs for the view setup in it
33 | ///
34 | /// The type of the data to output. This must be EfGeneric Dto
35 | /// The dto with any secondary data filled in
36 | TDto GetDto() where TDto : class;
37 | }
38 | }
--------------------------------------------------------------------------------
/GenericServices/ICreateSetupServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateSetupServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 |
29 | namespace GenericServices
30 | {
31 | public interface ICreateSetupServiceAsync
32 | {
33 | ///
34 | /// This returns the dto with any data that is needs for the view setup in it
35 | ///
36 | /// The type of the data to output. This must be EfGeneric Dto
37 | /// The dto with any secondary data filled in
38 | Task GetDtoAsync() where TDto : class;
39 | }
40 | }
--------------------------------------------------------------------------------
/GenericServices/IDeleteService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IDeleteService.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using GenericLibsBase;
30 |
31 | namespace GenericServices
32 | {
33 | public interface IDeleteService
34 | {
35 | ///
36 | /// This will delete an item from the database
37 | ///
38 | /// The keys must be given in the same order as entity framework has them
39 | ///
40 | ISuccessOrErrors Delete(params object[] keys) where TEntity : class;
41 |
42 | ///
43 | /// This allows a developer to delete an entity plus any of its relationships.
44 | /// The first part of the method finds the given entity using the provided keys.
45 | /// It then calls the deleteRelationships method which should remove the extra relationships
46 | ///
47 | /// method which is handed the DbContext and the found entity.
48 | /// It should then remove any relationships on this entity that it wants to.
49 | /// It returns a status, if IsValid then calls SaveChangesWithChecking
50 | /// The keys must be given in the same order as entity framework has them
51 | ///
52 | ISuccessOrErrors DeleteWithRelationships(
53 | Func removeRelationships,
54 | params object[] keys) where TEntity : class;
55 | }
56 | }
--------------------------------------------------------------------------------
/GenericServices/IDeleteServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IDeleteServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Threading.Tasks;
30 | using GenericLibsBase;
31 |
32 | namespace GenericServices
33 | {
34 | public interface IDeleteServiceAsync
35 | {
36 | ///
37 | /// This will delete an item from the database
38 | ///
39 | /// The keys must be given in the same order as entity framework has them
40 | ///
41 | Task DeleteAsync(params object[] keys) where TEntity : class;
42 |
43 | ///
44 | /// This allows a developer to delete an entity plus any of its relationships.
45 | /// The first part of the method finds the given entity using the provided keys.
46 | /// It then calls the deleteRelationships method which should remove the extra relationships
47 | ///
48 | /// method which is handed the DbContext and the found entity.
49 | /// It should then remove any relationships on this entity that it wants to.
50 | /// It returns a status, if IsValid then calls SaveChangesWithChecking
51 | /// The keys must be given in the same order as entity framework has them
52 | ///
53 | Task DeleteWithRelationshipsAsync(
54 | Func> removeRelationshipsAsync,
55 | params object[] keys) where TEntity : class;
56 | }
57 | }
--------------------------------------------------------------------------------
/GenericServices/IDetailService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IDetailService.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface IDetailService
33 | {
34 | ///
35 | /// This returns a status which, if Valid, contains a single entry found using its primary keys.
36 | ///
37 | /// The type of the data to output.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// The keys must be given in the same order as entity framework has them
40 | /// Status. If valid Result holds data (not tracked), otherwise null
41 | ISuccessOrErrors GetDetail(params object[] keys) where T : class, new();
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/GenericServices/IDetailServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IDetailServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface IDetailServiceAsync
33 | {
34 | ///
35 | /// This returns a status which, if Valid, contains a single entry found using its primary keys.
36 | ///
37 | /// The type of the data to output.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// The keys must be given in the same order as entity framework has them
40 | /// Status. If valid Result holds data (not tracked), otherwise null
41 | Task> GetDetailAsync(params object[] keys) where T : class, new();
42 | }
43 | }
--------------------------------------------------------------------------------
/GenericServices/IGenericServicesDbContext.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IGenericServicesDbContext.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericServices.Core;
29 |
30 | namespace GenericServices
31 | {
32 | ///
33 | /// This is the interface that developers should placed on the DbContext in there project
34 | /// It will allow the GenericServices commands to woek with your context
35 | /// Also useful for dependency injection.
36 | ///
37 | public interface IGenericServicesDbContext : IGenericDbContext, IGenericSaveChanges
38 | {
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/GenericServices/IListService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IListService.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Linq;
28 |
29 | namespace GenericServices
30 | {
31 |
32 | public interface IListService
33 | {
34 | ///
35 | /// This works out what sort of service is needed from the type provided
36 | /// and returns an IQueryable list of all items of the given type
37 | ///
38 | /// The type of the data to output.
39 | /// Type must be a type either an EF data class or a class inherited from the EfGenericDto or EfGenericDtoAsync
40 | /// note: the list items are not tracked
41 | IQueryable GetAll() where T : class, new();
42 | }
43 | }
--------------------------------------------------------------------------------
/GenericServices/IUpdateService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IUpdateService.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 |
33 | public interface IUpdateService
34 | {
35 | ///
36 | /// This updates the data in the database using the input data
37 | ///
38 | /// The type of input data.
39 | /// Type must be a type either an EF data class or one of the EfGenericDto's
40 | /// data to update the class. If Dto then copied over to data class
41 | ///
42 | ISuccessOrErrors Update(T data) where T : class;
43 |
44 | ///
45 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
46 | /// you need to display the view again with errors
47 | ///
48 | /// Must be a dto inherited from EfGenericDtoAsync
49 | ///
50 | T ResetDto(T dto) where T : class;
51 | }
52 | }
--------------------------------------------------------------------------------
/GenericServices/IUpdateServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IUpdateServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface IUpdateServiceAsync
33 | {
34 | ///
35 | /// This updates the data in the database using the input data
36 | ///
37 | /// The type of input data.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// data to update the class. If Dto then copied over to data class
40 | ///
41 | Task UpdateAsync(T data) where T : class;
42 |
43 | ///
44 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
45 | /// you need to display the view again with errors
46 | ///
47 | /// Must be a dto inherited from EfGenericDtoAsync
48 | ///
49 | Task ResetDtoAsync(T dto) where T : class;
50 | }
51 | }
--------------------------------------------------------------------------------
/GenericServices/IUpdateSetupService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IUpdateSetupService.cs
5 | // Date Created: 2014/05/20
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface IUpdateSetupService
33 | {
34 | ///
35 | /// This returns a status which, if Valid, has single entry using the primary keys to find it.
36 | ///
37 | /// The type of the data to output.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// The keys must be given in the same order as entity framework has them
40 | /// Status. If valid Result holds data (not tracked), otherwise null
41 | ISuccessOrErrors GetOriginal(params object[] keys) where T : class;
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/GenericServices/IUpdateSetupServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IUpdateSetupServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericLibsBase;
29 |
30 | namespace GenericServices
31 | {
32 | public interface IUpdateSetupServiceAsync
33 | {
34 | ///
35 | /// This returns a status which, if Valid, has single entry using the primary keys to find it.
36 | ///
37 | /// The type of the data to output.
38 | /// Type must be a type either an EF data class or one of the EfGenericDto's
39 | /// The keys must be given in the same order as entity framework has them
40 | /// Task with Status. If valid Result holds data (not tracked), otherwise null
41 | Task> GetOriginalAsync(params object[] keys) where T : class;
42 | }
43 | }
--------------------------------------------------------------------------------
/GenericServices/NuGet/AssemblyVersionPart.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: AssemblyVersionPart.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Reflection;
28 |
29 | // THIS HOLDS THE VERSION PART OF THE ASSEMBLY
30 | // Alter this before building for Nuget pack
31 |
32 | // Version information for an assembly consists of the following four values:
33 | //
34 | // Major Version
35 | // Minor Version
36 | // Build Number
37 | // Revision
38 | //
39 | // You can specify all the values or you can default the Build and Revision Numbers
40 | // by using the '*' as shown below:
41 | // [assembly: AssemblyVersion("1.0.*")]
42 |
43 | [assembly: AssemblyVersion("1.0.10.0")]
44 | [assembly: AssemblyFileVersion("1.0.10.0")]
45 | [assembly: AssemblyInformationalVersion("1.0.10")]
46 |
--------------------------------------------------------------------------------
/GenericServices/NuGet/GenericServices.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
44 |
45 | GenericServices
46 | 1.0.10
47 | GenericServices
48 | Jon Smith
49 | Jon Smith
50 | https://github.com/JonPSmith/GenericServices/blob/master/licence.txt
51 | https://github.com/JonPSmith/GenericServices
52 | https://raw.githubusercontent.com/JonPSmith/GenericServices/master/GenericServices/NuGet/GenericServicesNuGetIcon128.png
53 | false
54 |
55 | Generic Services is a .NET class library to help build a service layer, i.e. a layer that acts as a facard/adapter between your data layers containing an Entity Framework database and your User Interface or HTTP service.
56 |
57 | Added GenericServicesConfig.HandleSqlExceptionOnSave to allow developer to handle SqlExection in SaveChangesWithChecking (sync and async)
58 | Copyright 2015
59 | EntityFramework EF ASP.NET MVC DTO Validation Library
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/GenericServices/NuGet/GenericServicesNuGetIcon128-png8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericServices/NuGet/GenericServicesNuGetIcon128-png8.png
--------------------------------------------------------------------------------
/GenericServices/NuGet/GenericServicesNuGetIcon128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericServices/NuGet/GenericServicesNuGetIcon128.png
--------------------------------------------------------------------------------
/GenericServices/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: AssemblyInfo.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Reflection;
28 | using System.Runtime.InteropServices;
29 | using System.Resources;
30 |
31 | // General Information about an assembly is controlled through the following
32 | // set of attributes. Change these attribute values to modify the information
33 | // associated with an assembly.
34 | [assembly: AssemblyTitle("GenericServices")]
35 | [assembly: AssemblyDescription("A library to provide a service layer using Entity Framework for database accesses")]
36 | [assembly: AssemblyConfiguration("")]
37 | [assembly: AssemblyCompany("Selective Analytics")]
38 | [assembly: AssemblyProduct("GenericServices")]
39 | [assembly: AssemblyCopyright("Copyright © Jon Smith 2014")]
40 | [assembly: AssemblyTrademark("")]
41 | [assembly: AssemblyCulture("")]
42 |
43 | // Setting ComVisible to false makes the types in this assembly not visible
44 | // to COM components. If you need to access a type in this assembly from
45 | // COM, set the ComVisible attribute to true on that type.
46 | [assembly: ComVisible(false)]
47 |
48 | // The following GUID is for the ID of the typelib if this project is exposed to COM
49 | [assembly: Guid("00ad5e77-c2e6-4cbd-b891-4e04fd11b036")]
50 |
51 | [assembly: NeutralResourcesLanguageAttribute("en")]
52 |
--------------------------------------------------------------------------------
/GenericServices/Services/Concrete/CreateSetupService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: CreateSetupService.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using GenericServices.Core;
28 | using GenericServices.Core.Internal;
29 |
30 | namespace GenericServices.Services.Concrete
31 | {
32 |
33 | public class CreateSetupService : ICreateSetupService
34 | {
35 |
36 | private readonly IGenericServicesDbContext _db;
37 |
38 | public CreateSetupService(IGenericServicesDbContext db)
39 | {
40 | _db = db;
41 | }
42 |
43 | ///
44 | /// This returns the dto with any data that is needs for the view setup in it
45 | ///
46 | /// The type of the data to output. This must be EfGeneric Dto
47 | /// The dto with any secondary data filled in
48 | public TDto GetDto() where TDto : class
49 | {
50 | var service = DecodeToService.CreateCorrectService(WhatItShouldBe.SyncSpecificDto, _db);
51 | return service.GetDto();
52 | }
53 | }
54 |
55 | public class CreateSetupService : ICreateSetupService
56 | where TEntity : class, new()
57 | where TDto : EfGenericDto, new()
58 | {
59 | private readonly IGenericServicesDbContext _db;
60 |
61 | public CreateSetupService(IGenericServicesDbContext db)
62 | {
63 | _db = db;
64 | }
65 |
66 | ///
67 | /// This returns the dto with any data that is needs for the view setup in it
68 | ///
69 | /// A TDto which has had the SetupSecondaryData method called on it
70 | public TDto GetDto()
71 | {
72 | var dto = new TDto();
73 | if (!dto.SupportedFunctions.HasFlag(CrudFunctions.DoesNotNeedSetup))
74 | dto.SetupSecondaryData(_db, dto);
75 |
76 | return dto;
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/GenericServices/Services/ICreateService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateService.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 | using GenericServices.Core;
30 |
31 | namespace GenericServices.Services
32 | {
33 |
34 | public interface ICreateService where TEntity : class
35 | {
36 |
37 | ///
38 | /// This adds a new entity class to the database with error checking
39 | ///
40 | ///
41 | /// status
42 | ISuccessOrErrors Create(TEntity newItem);
43 | }
44 |
45 | public interface ICreateService
46 | where TEntity : class, new()
47 | where TDto : EfGenericDto, new()
48 | {
49 | ///
50 | /// This uses a dto to create a data class which it writes to the database with error checking
51 | ///
52 | /// If an error then its resets any secondary data so that you can reshow the dto
53 | /// status
54 | ISuccessOrErrors Create(TDto dto);
55 |
56 | ///
57 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
58 | /// you need to display the view again with errors
59 | ///
60 | ///
61 | ///
62 | TDto ResetDto(TDto dto);
63 | }
64 | }
--------------------------------------------------------------------------------
/GenericServices/Services/ICreateSetupService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateSetupService.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using GenericServices.Core;
28 |
29 | namespace GenericServices.Services
30 | {
31 |
32 | public interface ICreateSetupService
33 | where TEntity : class, new()
34 | where TDto : EfGenericDto, new()
35 | {
36 | ///
37 | /// This returns the dto with any data that is needs for the view setup in it
38 | ///
39 | /// A TDto which, if required, will have SetupSecondaryData method called on it
40 | TDto GetDto();
41 | }
42 | }
--------------------------------------------------------------------------------
/GenericServices/Services/IDetailService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IDetailService.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System;
28 | using System.Linq.Expressions;
29 | using GenericLibsBase;
30 | using GenericServices.Core;
31 |
32 | namespace GenericServices.Services
33 | {
34 |
35 | public interface IDetailService where TEntity : class, new()
36 | {
37 | ///
38 | /// This gets a single entry using the lambda expression as a where part
39 | ///
40 | /// Should be a 'where' expression that returns one item
41 | /// Status. If valid Result is data as read from database (not tracked), otherwise null
42 | ISuccessOrErrors GetDetailUsingWhere(Expression> whereExpression);
43 |
44 | ///
45 | /// This finds an entry using the primary key(s) in the data
46 | ///
47 | /// The keys must be given in the same order as entity framework has them
48 | /// Status. If valid Result is data as read from database (not tracked), otherwise null
49 | ISuccessOrErrors GetDetail(params object[] keys);
50 | }
51 |
52 | public interface IDetailService
53 | where TEntity : class, new()
54 | where TDto : EfGenericDto, new()
55 | {
56 | ///
57 | /// This gets a single entry using the lambda expression as a where part
58 | ///
59 | /// Should be a 'where' expression that returns one item
60 | /// Status. If Valid then TDto type with properties copyed over, else null
61 | ISuccessOrErrors GetDetailUsingWhere(Expression> whereExpression);
62 |
63 | ///
64 | /// This finds an entry using the primary key(s) in the data
65 | ///
66 | /// The keys must be given in the same order as entity framework has them
67 | /// Status. If Valid then TDto type with properties copyed over, else null
68 | ISuccessOrErrors GetDetail(params object[] keys);
69 | }
70 |
71 | }
--------------------------------------------------------------------------------
/GenericServices/Services/IListService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IListService.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Linq;
28 | using GenericServices.Core;
29 |
30 | namespace GenericServices.Services
31 | {
32 |
33 | public interface IListService where TEntity : class
34 | {
35 | ///
36 | /// This returns an IQueryable list of all items of the given type
37 | ///
38 | /// note: the list items are not tracked
39 | IQueryable GetAll();
40 | }
41 |
42 | public interface IListService
43 | where TEntity : class
44 | where TDto : EfGenericDtoBase
45 | {
46 | ///
47 | /// This returns an IQueryable list of all items of the given type
48 | ///
49 | /// note: the list items are not tracked
50 | IQueryable GetAll();
51 | }
52 | }
--------------------------------------------------------------------------------
/GenericServices/Services/IUpdateService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IUpdateService.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 | using GenericServices.Core;
30 |
31 | namespace GenericServices.Services
32 | {
33 |
34 | public interface IUpdateService where TEntity : class
35 | {
36 | ///
37 | /// This updates the entity data class directly
38 | ///
39 | ///
40 | /// status
41 | ISuccessOrErrors Update(TEntity itemToUpdate);
42 | }
43 |
44 | public interface IUpdateService
45 | where TEntity : class, new()
46 | where TDto : EfGenericDto, new()
47 | {
48 | ///
49 | /// This updates the entity data by copying over the relevant dto data.
50 | /// If it fails it resets the dto in case it is going to be shown again
51 | ///
52 | /// If an error then its resets any secondary data so that you can reshow the dto
53 | /// status
54 | ISuccessOrErrors Update(TDto dto);
55 |
56 | ///
57 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
58 | /// you need to display the view again with errors
59 | ///
60 | ///
61 | ///
62 | TDto ResetDto(TDto dto);
63 | }
64 | }
--------------------------------------------------------------------------------
/GenericServices/ServicesAsync/Concrete/CreateSetupServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: CreateSetupServiceAsync.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericServices.Core;
29 | using GenericServices.Core.Internal;
30 |
31 | namespace GenericServices.ServicesAsync.Concrete
32 | {
33 |
34 | public class CreateSetupServiceAsync : ICreateSetupServiceAsync
35 | {
36 | private readonly IGenericServicesDbContext _db;
37 |
38 | public CreateSetupServiceAsync(IGenericServicesDbContext db)
39 | {
40 | _db = db;
41 | }
42 |
43 | ///
44 | /// This returns the dto with any data that is needs for the view setup in it
45 | ///
46 | /// The type of the data to output. This must be EfGeneric Dto
47 | /// The dto with any secondary data filled in
48 | public async Task GetDtoAsync() where TDto : class
49 | {
50 | var service = DecodeToService.CreateCorrectService(WhatItShouldBe.AsyncSpecificDto, _db);
51 | return await service.GetDtoAsync().ConfigureAwait(false);
52 | }
53 | }
54 |
55 |
56 | public class CreateSetupServiceAsync : ICreateSetupServiceAsync
57 | where TEntity : class, new()
58 | where TDto : EfGenericDtoAsync, new()
59 | {
60 | private readonly IGenericServicesDbContext _db;
61 |
62 | public CreateSetupServiceAsync(IGenericServicesDbContext db)
63 | {
64 | _db = db;
65 | }
66 |
67 | ///
68 | /// This returns the dto with any data that is needs for the view setup in it
69 | ///
70 | /// A TDto which has had the SetupSecondaryData method called on it
71 | public async Task GetDtoAsync()
72 | {
73 | var dto = new TDto();
74 | if (!dto.SupportedFunctions.HasFlag(CrudFunctions.DoesNotNeedSetup))
75 | await dto.SetupSecondaryDataAsync(_db, dto).ConfigureAwait(false);
76 |
77 | return dto;
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/GenericServices/ServicesAsync/ICreateServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateServiceAsync.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericLibsBase;
29 | using GenericServices.Core;
30 |
31 | namespace GenericServices.ServicesAsync
32 | {
33 |
34 | public interface ICreateServiceAsync where TEntity : class
35 | {
36 | ///
37 | /// This adds a new entity class to the database with error checking
38 | ///
39 | ///
40 | /// status
41 | Task CreateAsync(TEntity newItem);
42 | }
43 |
44 | public interface ICreateServiceAsync
45 | where TEntity : class, new()
46 | where TDto : EfGenericDtoAsync, new()
47 | {
48 |
49 | ///
50 | /// This uses a dto to create a data class which it writes to the database with error checking
51 | ///
52 | /// If an error then its resets any secondary data so that you can reshow the dto
53 | /// status
54 | Task CreateAsync(TDto dto);
55 |
56 | ///
57 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
58 | /// you need to display the view again with errors
59 | ///
60 | ///
61 | ///
62 | Task ResetDtoAsync(TDto dto);
63 | }
64 | }
--------------------------------------------------------------------------------
/GenericServices/ServicesAsync/ICreateSetupServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: ICreateSetupServiceAsync.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericServices.Core;
29 |
30 | namespace GenericServices.ServicesAsync
31 | {
32 |
33 | public interface ICreateSetupServiceAsync
34 | where TEntity : class, new()
35 | where TDto : EfGenericDtoAsync, new()
36 | {
37 | ///
38 | /// This returns the dto with any data that is needs for the view setup in it
39 | ///
40 | /// An async Task TDto which has had the SetupSecondaryData method called on it
41 | Task GetDtoAsync();
42 | }
43 | }
--------------------------------------------------------------------------------
/GenericServices/ServicesAsync/IDetailServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IDetailServiceAsync.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System;
28 | using System.Linq.Expressions;
29 | using System.Threading.Tasks;
30 | using GenericLibsBase;
31 | using GenericServices.Core;
32 |
33 | namespace GenericServices.ServicesAsync
34 | {
35 |
36 | public interface IDetailServiceAsync
37 | where TEntity : class, new()
38 | {
39 | ///
40 | /// This gets a single entry using the lambda expression as a where part
41 | ///
42 | /// Should be a 'where' expression that returns one item
43 | /// Task with Status. If valid Result is data as read from database (not tracked), otherwise null
44 | Task> GetDetailUsingWhereAsync(Expression> whereExpression);
45 |
46 | ///
47 | /// This finds an entry using the primary key(s) in the data
48 | ///
49 | /// The keys must be given in the same order as entity framework has them
50 | /// Task with Status. If valid Result is data as read from database (not tracked), otherwise null
51 | Task> GetDetailAsync(params object[] keys);
52 | }
53 |
54 | public interface IDetailServiceAsync
55 | where TEntity : class, new()
56 | where TDto : EfGenericDtoAsync, new()
57 | {
58 | ///
59 | /// This gets a single entry using the lambda expression as a where part
60 | ///
61 | /// Should be a 'where' expression that returns one item
62 | /// Task with Status. If valid Result is data as read from database (not tracked), otherwise null
63 | Task> GetDetailUsingWhereAsync(Expression> whereExpression);
64 |
65 |
66 | ///
67 | /// This finds an entry using the primary key(s) in the data
68 | ///
69 | /// The keys must be given in the same order as entity framework has them
70 | /// Task with Status. If valid Result is data as read from database (not tracked), otherwise null
71 | Task> GetDetailAsync(params object[] keys);
72 |
73 | }
74 | }
--------------------------------------------------------------------------------
/GenericServices/ServicesAsync/IUpdateServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: IUpdateServiceAsync.cs
5 | // Date Created: 2014/07/22
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 | using System.Threading.Tasks;
28 | using GenericLibsBase;
29 | using GenericServices.Core;
30 |
31 | namespace GenericServices.ServicesAsync
32 | {
33 |
34 | public interface IUpdateServiceAsync where TEntity : class
35 | {
36 | ///
37 | /// This updates the entity data class directly
38 | ///
39 | ///
40 | /// status
41 | Task UpdateAsync(TEntity itemToUpdate);
42 | }
43 |
44 | public interface IUpdateServiceAsync
45 | where TEntity : class, new()
46 | where TDto : EfGenericDtoAsync, new()
47 | {
48 | ///
49 | /// This updates the entity data by copying over the relevant dto data.
50 | /// If it fails it resets the dto in case it is going to be shown again
51 | ///
52 | /// If an error then its resets any secondary data so that you can reshow the dto
53 | /// status
54 | Task UpdateAsync(TDto dto);
55 |
56 | ///
57 | /// This is available to reset any secondary data in the dto. Call this if the ModelState was invalid and
58 | /// you need to display the view again with errors
59 | ///
60 | ///
61 | ///
62 | Task ResetDtoAsync(TDto dto);
63 | }
64 | }
--------------------------------------------------------------------------------
/GenericServices/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericServices/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/GenericServices/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericServices/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/GenericServices/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericServices/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/GenericServices/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JonPSmith/GenericServices/0b59f77936b687fa85ea8dc14418d96cb0d8d1a3/GenericServices/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/GenericServices/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ProfileApp/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/ProfileApp/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using GenericServices;
7 | using GenericServices.Services.Concrete;
8 | using Tests.DataClasses;
9 | using Tests.DataClasses.Concrete;
10 | using Tests.DTOs.Concrete;
11 |
12 | namespace ProfileApp
13 | {
14 | class Program
15 | {
16 | static void Main(string[] args)
17 | {
18 | using (var db = new SampleWebAppDb())
19 | {
20 | var firstId = db.Posts.First().PostId;
21 | RunCommand1(db);
22 | RunCommand2(db);
23 | }
24 |
25 | }
26 |
27 | private static void RunCommand1(IGenericServicesDbContext db)
28 | {
29 | var service = new ListService(db);
30 | var list = service.GetAll().ToList();
31 | }
32 |
33 | private static void RunCommand2(IGenericServicesDbContext db)
34 | {
35 | var service = new ListService(db);
36 | var list = service.GetAll().ToList();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ProfileApp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("ProfileApp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ProfileApp")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ec41ad32-29bb-49a4-a4fd-8fbf8e218c62")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ProfileApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | GenericServices
2 | ===============
3 |
4 | GenericServices is a .NET class library to help build a
5 | [service layer](http://martinfowler.com/eaaCatalog/serviceLayer.html),
6 | i.e. a layer that acts as a facade/adapter between your database in the Data Layer
7 | and your User Interface or HTTP service in your Presentation Layer.
8 | It makes heavy use of
9 | [Entity Framework 6 - EF6](http://msdn.microsoft.com/en-us/data/ee712907)
10 | and .NET 4.5's [async/await](http://msdn.microsoft.com/en-gb/library/hh191443.aspx)
11 | commands. Its aim is to make the creation of the service layer simple while
12 | providing robust implementations of standard database access commands.
13 | GenericServices is an Open Source project under the
14 | [MIT licence](https://github.com/JonPSmith/GenericServices/blob/master/licence.txt)
15 |
16 | **GenericServices is now available on NuGet.**
17 | See [NuGet Package Page](https://www.nuget.org/packages/GenericServices/) for more details.
18 |
19 | ## The best documentation is a worked example
20 | I have created two working examples that show how GenericServices can be used to produce a
21 | ASP.NET MVC web application with a html/razor front end.
22 |
23 | #### 1. [SampleMvcWebApp](http://samplemvcwebapp.net/) web site
24 | This is an introductory/basic web site using GenericServices based on an database
25 | containing blog post.
26 | It is an open-source project with
27 | [source code](https://github.com/JonPSmith/SampleMvcWebApp) available.
28 |
29 | Read the [site's introduction](http://samplemvcwebapp.net/) and the
30 | [source code README page](https://github.com/JonPSmith/SampleMvcWebApp) for more information.
31 |
32 | #### 2. [SampleMvcWebAppComplex](http://complex.samplemvcwebapp.net/) web site
33 | This is an Advanced/Complex web site using GenericServices to provide a user interface
34 | to the AdventureWorks Lite 2012 database. This is NOT an open-source project,
35 | mainly because it uses the proprietary, paid-for library
36 | [Kendo UI MVC](http://www.telerik.com/kendo-ui).
37 | However the source is made available as it is a good reference source.
38 |
39 | Read the [site's introduction](http://complex.samplemvcwebapp.net/) and the
40 | [source code README page](https://github.com/JonPSmith/SampleMvcWebAppComplex)
41 | for more information.
42 |
43 | ## Full documentation exists in the Wiki
44 | The [GenericServices Wiki](https://github.com/JonPSmith/GenericServices/wiki)
45 | has extensive information - see the Wiki sidebar for an index to the various parts.
46 |
47 | The wiki documentation covers things the software doesn't explain, like
48 | [Why GenericServices?](https://github.com/JonPSmith/GenericServices/wiki/Why-GenericServices%3F)
49 | and [Architecture Overview](https://github.com/JonPSmith/GenericServices/wiki/Architecture-Overview).
50 | Well worth a look.
51 |
52 | ## Other information
53 |
54 | I have written a number of articles for the
55 | [Simple-Talk web site](https://www.simple-talk.com/author/jon-smith/),
56 | all of which are relevant to GenericServices as the code in all four
57 | articles came from the two demo sites.
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/Tests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/BadPostTagGradeMissingKeyDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: BadPostTagGradeMissingKeyDto.cs
5 | // Date Created: 2015/06/10
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations;
29 | using System.ComponentModel.DataAnnotations.Schema;
30 | using GenericServices.Core;
31 | using Tests.DataClasses.Concrete;
32 |
33 | namespace Tests.DTOs.Concrete
34 | {
35 | public class BadPostTagGradeMissingKeyDto : EfGenericDto
36 | {
37 |
38 | public int PostId { get; set; }
39 | [ForeignKey("PostId")]
40 | public Post PostPart { get; set; }
41 |
42 | //Left out second part of key!
43 | //public int TagId { get; set; }
44 | //[ForeignKey("TagId")]
45 | //public Tag TagPart { get; set; }
46 |
47 | public int Grade { get; set; }
48 |
49 | protected internal override CrudFunctions SupportedFunctions
50 | {
51 | get { return CrudFunctions.AllCrud | CrudFunctions.DoesNotNeedSetup; }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/BadSpecialMappingDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimplePostDto.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Runtime.CompilerServices;
30 | using GenericServices.Core;
31 | using Tests.DataClasses.Concrete;
32 |
33 | [assembly: InternalsVisibleTo("Tests")]
34 |
35 | namespace Tests.DTOs.Concrete
36 | {
37 | internal class BadSpecialMappingDto : InstrumentedEfGenericDto
38 | {
39 |
40 | //----------------------------------------------
41 | //overridden properties or methods
42 |
43 | internal protected override CrudFunctions SupportedFunctions
44 | {
45 | get { return CrudFunctions.AllCrudButCreate | CrudFunctions.DoesNotNeedSetup; }
46 | }
47 |
48 | protected override Type AssociatedDtoMapping
49 | {
50 | get { return typeof (DateTime); } //bad type, not a EfGenericDto
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/DelegateDecompileForced.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 | using GenericServices.Core;
3 | using Tests.DataClasses.Concrete;
4 |
5 | namespace Tests.DTOs.Concrete
6 | {
7 | class DelegateDecompileForced : EfGenericDto
8 | {
9 |
10 | [Key]
11 | public int TagId { get; set; }
12 |
13 | [MaxLength(64)]
14 | [Required]
15 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
16 | public string Slug { get; set; }
17 |
18 | [MaxLength(128)]
19 | [Required]
20 | public string Name { get; set; }
21 |
22 | protected internal override CrudFunctions SupportedFunctions
23 | {
24 | get { return CrudFunctions.List ; }
25 | }
26 |
27 | protected override bool ForceNeedDecompile
28 | {
29 | get { return true; }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/DelegateDecompileNeededPostDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.DataAnnotations;
4 | using GenericServices.Core;
5 | using Tests.DataClasses.Concrete;
6 |
7 | namespace Tests.DTOs.Concrete
8 | {
9 | class DelegateDecompileNeededPostDto : EfGenericDto
10 | {
11 |
12 | [Key]
13 | public int TagId { get; set; }
14 |
15 | [MaxLength(64)]
16 | [Required]
17 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
18 | public string Slug { get; set; }
19 |
20 | [MaxLength(128)]
21 | [Required]
22 | public string Name { get; set; }
23 |
24 | ///
25 | /// This requires DelegateDecompiler
26 | ///
27 | public IEnumerable Posts { get; set; }
28 |
29 | protected internal override CrudFunctions SupportedFunctions
30 | {
31 | get { return CrudFunctions.List ; }
32 | }
33 |
34 | protected override Type AssociatedDtoMapping
35 | {
36 | get { return typeof(DelegateDecompilePostDto); }
37 | }
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/DelegateDecompilePostDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: DetailPostDto.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Collections.Generic;
29 | using System.ComponentModel.DataAnnotations;
30 | using System.Runtime.CompilerServices;
31 | using GenericServices.Core;
32 | using Tests.DataClasses.Concrete;
33 |
34 | [assembly: InternalsVisibleTo("Tests")]
35 |
36 | namespace Tests.DTOs.Concrete
37 | {
38 | public class DelegateDecompilePostDto : InstrumentedEfGenericDto
39 | {
40 |
41 | [UIHint("HiddenInput")]
42 | [Key]
43 | public int PostId { get; set; }
44 |
45 | public string Title { get; set; }
46 |
47 | public string Content { get; set; }
48 |
49 | //public ICollection Tags { get; set; }
50 |
51 | //------------------------------------------------------
52 | //now the computed properties to read
53 |
54 | public string BloggerNameAndEmail { get; set; }
55 |
56 | public IEnumerable TagNames { get; set; }
57 |
58 | protected internal override CrudFunctions SupportedFunctions
59 | {
60 | get { return CrudFunctions.AllCrud | CrudFunctions.DoesNotNeedSetup ; }
61 | }
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/DelegateDecompilePostDtoAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: DetailPostDto.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Collections.Generic;
29 | using System.ComponentModel.DataAnnotations;
30 | using System.Runtime.CompilerServices;
31 | using GenericServices.Core;
32 | using Tests.DataClasses.Concrete;
33 |
34 | [assembly: InternalsVisibleTo("Tests")]
35 |
36 | namespace Tests.DTOs.Concrete
37 | {
38 | public class DelegateDecompilePostDtoAsync : InstrumentedEfGenericDtoAsync
39 | {
40 |
41 | [UIHint("HiddenInput")]
42 | [Key]
43 | public int PostId { get; set; }
44 |
45 | public string Title { get; set; }
46 |
47 | public string Content { get; set; }
48 |
49 | //public ICollection Tags { get; set; }
50 |
51 | //------------------------------------------------------
52 | //now the computed properties to read
53 |
54 | public string BloggerNameAndEmail { get; set; }
55 |
56 | public IEnumerable TagNames { get; set; }
57 |
58 | protected internal override CrudFunctions SupportedFunctions
59 | {
60 | get { return CrudFunctions.AllCrud | CrudFunctions.DoesNotNeedSetup ; }
61 | }
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/PostSpecialMappingDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimplePostDto.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Collections.Generic;
30 | using System.ComponentModel.DataAnnotations;
31 | using System.Runtime.CompilerServices;
32 | using AutoMapper;
33 | using GenericServices;
34 | using GenericServices.Core;
35 | using Tests.DataClasses.Concrete;
36 |
37 | [assembly: InternalsVisibleTo("Tests")]
38 |
39 | namespace Tests.DTOs.Concrete
40 | {
41 | internal class PostSpecialMappingDto : InstrumentedEfGenericDto
42 | {
43 |
44 | [UIHint("HiddenInput")]
45 | [DoNotCopyBackToDatabase]
46 | public int PostId { get; set; }
47 |
48 | [MinLength(2), MaxLength(128)]
49 | public string Title { get; set; } //Title can be updated
50 |
51 | [DataType(DataType.MultilineText)]
52 | public string Content { get; set; } //Content can be updated
53 |
54 | //------------------------------------------
55 | //properties that are going to be specifically mapped
56 |
57 | [DoNotCopyBackToDatabase]
58 | public string BloggerInfo { get; set; }
59 |
60 | [DoNotCopyBackToDatabase]
61 | public int CountOfTags { get; set; }
62 |
63 | //-------------------------------------------
64 | //dtos for mapping relationships
65 |
66 | [DoNotCopyBackToDatabase]
67 | public ICollection Tags { get; set; }
68 |
69 | //----------------------------------------------
70 | //overridden properties or methods
71 |
72 | protected internal override CrudFunctions SupportedFunctions
73 | {
74 | get { return CrudFunctions.AllCrudButCreate | CrudFunctions.DoesNotNeedSetup; }
75 | }
76 |
77 | protected override Action> AddedDatabaseToDtoMapping
78 | {
79 | get { return m => m.ForMember(p => p.BloggerInfo, opt => opt.MapFrom(x => x.Blogger.Name + " " + x.Blogger.EmailAddress))
80 | .ForMember(p => p.CountOfTags, opt => opt.MapFrom(x => x.Tags.Count)); }
81 | }
82 |
83 | protected override Type AssociatedDtoMapping
84 | {
85 | get { return typeof (SimpleTagDto); }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimpleBlogWithPostsDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimpleBlogWithPostsDto.cs
5 | // Date Created: 2014/05/20
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Collections.Generic;
29 | using System.ComponentModel.DataAnnotations;
30 | using System.Data.Entity;
31 | using System.Linq;
32 | using GenericServices;
33 | using GenericServices.Core;
34 | using Tests.DataClasses.Concrete;
35 |
36 | namespace Tests.DTOs.Concrete
37 | {
38 | public class SimpleBlogWithPostsDto : InstrumentedEfGenericDto
39 | {
40 | [Key]
41 | public int BlogId { get; set; }
42 |
43 | [MinLength(2)]
44 | [MaxLength(64)]
45 | [Required]
46 | public string Name { get; set; }
47 |
48 | [MaxLength(256)]
49 | [Required]
50 | public string EmailAddress { get; set; }
51 |
52 | public ICollection Posts { get; protected set; }
53 |
54 | protected internal override CrudFunctions SupportedFunctions
55 | {
56 | get { return CrudFunctions.List | CrudFunctions.DoesNotNeedSetup; }
57 | }
58 |
59 | protected override IQueryable GetDataUntracked(IGenericServicesDbContext context)
60 | {
61 | return base.GetDataUntracked(context).Include(x => x.Posts);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimplePostDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimplePostDto.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Collections.Generic;
30 | using System.ComponentModel.DataAnnotations;
31 | using System.Linq;
32 | using System.Runtime.CompilerServices;
33 | using GenericServices;
34 | using GenericServices.Core;
35 | using Tests.DataClasses.Concrete;
36 |
37 | [assembly: InternalsVisibleTo("Tests")]
38 |
39 | namespace Tests.DTOs.Concrete
40 | {
41 | public class SimplePostDto : InstrumentedEfGenericDto
42 | {
43 |
44 | [UIHint("HiddenInput")]
45 | [Key]
46 | public int PostId { get; set; }
47 |
48 | public string BloggerName { get; set; }
49 |
50 | [MinLength(2), MaxLength(128)]
51 | public string Title { get; set; } //only the Title can be updated
52 |
53 | [DoNotCopyBackToDatabase]
54 | public ICollection Tags { get; set; }
55 |
56 | [DoNotCopyBackToDatabase]
57 | public DateTime LastUpdated { get; set; }
58 |
59 | ///
60 | /// When it was last updated in DateTime format
61 | ///
62 | public DateTime LastUpdatedUtc { get { return DateTime.SpecifyKind(LastUpdated, DateTimeKind.Utc); } }
63 |
64 | public string TagNames { get { return string.Join(", ", Tags.Select(x => x.Name)); } }
65 |
66 | //----------------------------------------------
67 | //overridden properties or methods
68 |
69 | internal protected override CrudFunctions SupportedFunctions
70 | {
71 | get { return CrudFunctions.AllCrudButCreate | CrudFunctions.DoesNotNeedSetup; }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimplePostDtoAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimplePostDtoAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Collections.Generic;
30 | using System.ComponentModel.DataAnnotations;
31 | using System.Linq;
32 | using System.Runtime.CompilerServices;
33 | using GenericServices;
34 | using GenericServices.Core;
35 | using Tests.DataClasses.Concrete;
36 |
37 | [assembly: InternalsVisibleTo("Tests")]
38 |
39 | namespace Tests.DTOs.Concrete
40 | {
41 | public class SimplePostDtoAsync : InstrumentedEfGenericDtoAsync
42 | {
43 |
44 | [UIHint("HiddenInput")]
45 | [Key]
46 | public int PostId { get; set; }
47 |
48 | public string BloggerName { get; internal set; }
49 |
50 | [MinLength(2), MaxLength(128)]
51 | public string Title { get; set; } //only the Title can be updated
52 |
53 | [DoNotCopyBackToDatabase]
54 | public ICollection Tags { get; set; }
55 |
56 | [DoNotCopyBackToDatabase]
57 | public DateTime LastUpdated { get; set; }
58 |
59 | ///
60 | /// When it was last updated in DateTime format
61 | ///
62 | public DateTime LastUpdatedUtc { get { return DateTime.SpecifyKind(LastUpdated, DateTimeKind.Utc); } }
63 |
64 | public string TagNames { get { return string.Join(", ", Tags.Select(x => x.Name)); } }
65 |
66 | //----------------------------------------------
67 | //overridden properties or methods
68 |
69 | internal protected override CrudFunctions SupportedFunctions
70 | {
71 | get { return CrudFunctions.AllCrudButCreate | CrudFunctions.DoesNotNeedSetup; }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimplePostTagGradeDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimplePostTagGradeDto.cs
5 | // Date Created: 2014/05/27
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations;
29 | using System.ComponentModel.DataAnnotations.Schema;
30 | using GenericServices;
31 | using GenericServices.Core;
32 | using Tests.DataClasses.Concrete;
33 |
34 | namespace Tests.DTOs.Concrete
35 | {
36 | class SimplePostTagGradeDto : InstrumentedEfGenericDto
37 | {
38 |
39 | [Key]
40 | [Column(Order = 1)]
41 | [DoNotCopyBackToDatabase]
42 | public int PostId { get; set; }
43 | [DoNotCopyBackToDatabase]
44 | [ForeignKey("PostId")]
45 | public Post PostPart { get; set; }
46 |
47 | [Key]
48 | [Column(Order = 2)]
49 | [DoNotCopyBackToDatabase]
50 | public int TagId { get; set; }
51 | [ForeignKey("TagId")]
52 | [DoNotCopyBackToDatabase]
53 | public Tag TagPart { get; set; }
54 |
55 | public int Grade { get; set; }
56 |
57 | //--------------------------------
58 | //now the extra bits
59 |
60 | public string TagPartName { get; set; }
61 |
62 | public string PostPartTitle { get; set; }
63 |
64 | protected internal override CrudFunctions SupportedFunctions
65 | {
66 | get { return CrudFunctions.AllCrudButCreate | CrudFunctions.DoesNotNeedSetup; }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimpleTagDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimpleTagDto.cs
5 | // Date Created: 2014/05/26
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations;
29 | using GenericServices.Core;
30 | using Tests.DataClasses.Concrete;
31 |
32 | namespace Tests.DTOs.Concrete
33 | {
34 | class SimpleTagDto : InstrumentedEfGenericDto
35 | {
36 |
37 | private CrudFunctions _supportedFunctionsToUse = CrudFunctions.AllCrud;
38 |
39 | public SimpleTagDto()
40 | {
41 | }
42 |
43 | public SimpleTagDto(InstrumentedOpFlags whereToFail) : base(whereToFail)
44 | {
45 | }
46 |
47 |
48 | [Key]
49 | public int TagId { get; set; }
50 |
51 | [MaxLength(64)]
52 | [Required]
53 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
54 | public string Slug { get; set; }
55 |
56 | [MaxLength(128)]
57 | [Required]
58 | public string Name { get; set; }
59 |
60 |
61 | //--------------------------------------
62 |
63 |
64 | protected internal override CrudFunctions SupportedFunctions
65 | {
66 | get { return _supportedFunctionsToUse; }
67 | }
68 |
69 | public void SetSupportedFunctions(CrudFunctions allowedFunctions)
70 | {
71 | _supportedFunctionsToUse = allowedFunctions;
72 | }
73 |
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimpleTagDtoAssociatedToDecompileClass.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimpleTagDto.cs
5 | // Date Created: 2014/05/26
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.ComponentModel.DataAnnotations;
30 | using GenericServices.Core;
31 | using Tests.DataClasses.Concrete;
32 |
33 | namespace Tests.DTOs.Concrete
34 | {
35 | public class SimpleTagDtoAssociatedToDecompileClass : InstrumentedEfGenericDto
36 | {
37 |
38 | [Key]
39 | public int TagId { get; set; }
40 |
41 | [MaxLength(64)]
42 | [Required]
43 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
44 | public string Slug { get; set; }
45 |
46 | [MaxLength(128)]
47 | [Required]
48 | public string Name { get; set; }
49 |
50 |
51 | //--------------------------------------
52 |
53 | protected override Type AssociatedDtoMapping
54 | {
55 | get { return typeof (DelegateDecompilePostDto); }
56 | }
57 |
58 | protected internal override CrudFunctions SupportedFunctions
59 | {
60 | get { return CrudFunctions.List; }
61 | }
62 |
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimpleTagDtoAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimpleTagDtoAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations;
29 | using GenericServices.Core;
30 | using Tests.DataClasses.Concrete;
31 |
32 | namespace Tests.DTOs.Concrete
33 | {
34 | class SimpleTagDtoAsync : InstrumentedEfGenericDtoAsync
35 | {
36 |
37 | private CrudFunctions _supportedFunctionsToUse = CrudFunctions.AllCrud;
38 |
39 | public SimpleTagDtoAsync()
40 | {
41 | }
42 |
43 | public SimpleTagDtoAsync(InstrumentedOpFlags whereToFail)
44 | : base(whereToFail)
45 | {
46 | }
47 |
48 |
49 | [Key]
50 | public int TagId { get; set; }
51 |
52 | [MaxLength(64)]
53 | [Required]
54 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
55 | public string Slug { get; set; }
56 |
57 | [MaxLength(128)]
58 | [Required]
59 | public string Name { get; set; }
60 |
61 |
62 | //--------------------------------------
63 |
64 |
65 | protected internal override CrudFunctions SupportedFunctions
66 | {
67 | get { return _supportedFunctionsToUse; }
68 | }
69 |
70 | public void SetSupportedFunctions(CrudFunctions allowedFunctions)
71 | {
72 | _supportedFunctionsToUse = allowedFunctions;
73 | }
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/SimpleTagPostGradeDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: SimplePostTagGradeDto.cs
5 | // Date Created: 2014/05/27
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations;
29 | using System.ComponentModel.DataAnnotations.Schema;
30 | using GenericServices;
31 | using GenericServices.Core;
32 | using Tests.DataClasses.Concrete;
33 |
34 | namespace Tests.DTOs.Concrete
35 | {
36 | class SimpleTagPostGradeDto : InstrumentedEfGenericDto
37 | {
38 | [DoNotCopyBackToDatabase]
39 | public int TagId { get; set; }
40 | [ForeignKey("TagId")]
41 | [DoNotCopyBackToDatabase]
42 | public Tag TagPart { get; set; }
43 |
44 | [DoNotCopyBackToDatabase]
45 | public int PostId { get; set; }
46 | [DoNotCopyBackToDatabase]
47 | [ForeignKey("PostId")]
48 | public Post PostPart { get; set; }
49 |
50 | public int Grade { get; set; }
51 |
52 | //--------------------------------
53 | //now the extra bits
54 |
55 | public string TagPartName { get; set; }
56 |
57 | public string PostPartTitle { get; set; }
58 |
59 | protected internal override CrudFunctions SupportedFunctions
60 | {
61 | get { return CrudFunctions.AllCrudButCreate | CrudFunctions.DoesNotNeedSetup; }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Tests/DTOs/Concrete/TabNeededTagAndDelegatePostDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.DataAnnotations;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using AutoMapper;
8 | using GenericServices;
9 | using GenericServices.Core;
10 | using Tests.DataClasses.Concrete;
11 |
12 | namespace Tests.DTOs.Concrete
13 | {
14 | class TabNeededTagAndDelegatePostDto : EfGenericDto
15 | {
16 |
17 | [Key]
18 | public int TagId { get; set; }
19 |
20 | [MaxLength(64)]
21 | [Required]
22 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
23 | public string Slug { get; set; }
24 |
25 | [MaxLength(128)]
26 | [Required]
27 | public string Name { get; set; }
28 |
29 | ///
30 | /// This requires DelegateDecompiler
31 | ///
32 | public IEnumerable Posts { get; set; }
33 |
34 | protected internal override CrudFunctions SupportedFunctions
35 | {
36 | get { return CrudFunctions.List ; }
37 | }
38 |
39 | protected override Type [] AssociatedDtoMappings
40 | {
41 | get { return new []{ typeof(SimpleTagDto), typeof(DelegateDecompilePostDto)}; }
42 | }
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Tests/DataClasses/Concrete/Blog.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Blog.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Collections.Generic;
29 | using System.ComponentModel.DataAnnotations;
30 |
31 | namespace Tests.DataClasses.Concrete
32 | {
33 | public class Blog
34 | {
35 | public int BlogId { get; set; }
36 | [MinLength(2)]
37 | [MaxLength(64)]
38 | [Required]
39 | public string Name { get; set; }
40 |
41 | [MaxLength(256)]
42 | [Required]
43 | public string EmailAddress { get; set; }
44 |
45 | public ICollection Posts { get; set; }
46 |
47 | public override string ToString()
48 | {
49 | return string.Format("BlogId: {0}, Name: {1}, EmailAddress: {2}, NumPosts: {3}",
50 | BlogId, Name, EmailAddress, Posts == null ? "null" : Posts.Count.ToString());
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Tests/DataClasses/Concrete/Helpers/TrackUpdate.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: TrackUpdate.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 |
30 | namespace Tests.DataClasses.Concrete.Helpers
31 | {
32 | public abstract class TrackUpdate
33 | {
34 | public DateTime LastUpdated { get; protected set; }
35 |
36 | internal void UpdateTrackingInfo()
37 | {
38 | LastUpdated = DateTime.UtcNow;
39 | }
40 |
41 | protected TrackUpdate()
42 | {
43 | UpdateTrackingInfo(); //on creation then set date
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Tests/DataClasses/Concrete/PostLink.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: PostLink.cs
5 | // Date Created: 2014/07/23
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations.Schema;
29 |
30 | namespace Tests.DataClasses.Concrete
31 | {
32 | ///
33 | /// This class is purely used to test the SqlException thrown when we try to delete a Post
34 | /// that has a PostLink entry that points to the Post
35 | ///
36 | public class PostLink
37 | {
38 |
39 | public int PostLinkId { get; set; }
40 |
41 | public int PostId { get; set; }
42 | [ForeignKey("PostId")]
43 | public Post PostPart { get; set; }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Tests/DataClasses/Concrete/PostTagGrade.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: PostTagGrade.cs
5 | // Date Created: 2014/05/26
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.ComponentModel.DataAnnotations;
29 | using System.ComponentModel.DataAnnotations.Schema;
30 |
31 | namespace Tests.DataClasses.Concrete
32 | {
33 | public class PostTagGrade
34 | {
35 | [Key]
36 | [Column(Order = 1)]
37 | public int PostId { get; set; }
38 | [ForeignKey("PostId")]
39 | public Post PostPart { get; set; }
40 |
41 | [Key]
42 | [Column(Order = 2)]
43 | public int TagId { get; set; }
44 | [ForeignKey("TagId")]
45 | public Tag TagPart { get; set; }
46 |
47 | public int Grade { get; set; }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Tests/DataClasses/Concrete/Tag.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Tag.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Collections.Generic;
29 | using System.ComponentModel.DataAnnotations;
30 | using System.ComponentModel.DataAnnotations.Schema;
31 | using GenericServices;
32 |
33 | namespace Tests.DataClasses.Concrete
34 | {
35 | public class Tag
36 | {
37 | public int TagId { get; set; }
38 |
39 | [MaxLength(64)]
40 | [Required]
41 | [RegularExpression(@"\w*", ErrorMessage = "The slug must not contain spaces or non-alphanumeric characters.")]
42 | [Index(IsClustered = false, IsUnique = true)]
43 | public string Slug { get; set; }
44 |
45 | [MaxLength(128)]
46 | [Required]
47 | public string Name { get; set; }
48 |
49 | public ICollection Posts { get; set; }
50 |
51 | public override string ToString()
52 | {
53 | return string.Format("TagId: {0}, Name: {1}, Slug: {2}", TagId, Name, Slug);
54 | }
55 |
56 | public Tag()
57 | {
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Tests/DataClasses/DataLayerInitialise.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: DataLayerInitialise.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Data.Entity;
29 | using Tests.DataClasses.Internal;
30 |
31 | namespace Tests.DataClasses
32 | {
33 |
34 | public static class DataLayerInitialise
35 | {
36 |
37 |
38 | ///
39 | /// This should be called at Startup
40 | ///
41 | public static void InitialiseThis()
42 | {
43 | //Initialise the database
44 | Database.SetInitializer(new DropCreateDatabaseIfModelChanges());
45 | }
46 |
47 | public static void ResetDatabaseToTestData(SampleWebAppDb context, string filepathOfXmlFile)
48 | {
49 | context.Posts.RemoveRange( context.Posts);
50 | context.Tags.RemoveRange( context.Tags);
51 | context.Blogs.RemoveRange( context.Blogs);
52 | context.PostTagGrades.RemoveRange(context.PostTagGrades);
53 | context.PostLinks.RemoveRange(context.PostLinks);
54 | context.SaveChanges();
55 |
56 | var loader = new LoadDbDataFromXml(filepathOfXmlFile);
57 |
58 | context.Blogs.AddRange(loader.Bloggers); //note: The order things appear in the database are not obvious
59 | //have to add these by hand
60 | context.PostTagGrades.AddRange(loader.PostTagGrades);
61 | context.SaveChanges();
62 | }
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/Tests/Helpers/DbSnapShot.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: DbSnapShot.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Linq;
29 | using Tests.DataClasses;
30 |
31 | namespace Tests.Helpers
32 | {
33 | public class DbSnapShot
34 | {
35 |
36 | public int NumPosts { get; private set; }
37 |
38 | public int NumPostTagLinks { get; private set; }
39 |
40 | public int NumBlogs { get; private set; }
41 |
42 | public int NumTags { get; private set; }
43 |
44 | public int NumPostTagGrades { get; private set; }
45 |
46 | public DbSnapShot(SampleWebAppDb db)
47 | {
48 | NumBlogs = db.Blogs.Count();
49 | NumPostTagLinks = db.Database.SqlQuery("SELECT COUNT(*) FROM dbo.TagPosts").First();
50 | NumPosts = db.Posts.Count();
51 | NumTags = db.Tags.Count();
52 | NumPostTagGrades = db.PostTagGrades.Count();
53 | }
54 |
55 | //creates snapshot setting zero on everything
56 | public DbSnapShot() { }
57 |
58 | public void CheckSnapShot(SampleWebAppDb db, int postsChange = 0, int postTagLinkChange = 0, int blogsChange = 0, int tagsChange = 0, int postTagGradesChange = 0)
59 | {
60 | var newSnap = new DbSnapShot(db);
61 |
62 | newSnap.NumPosts.ShouldEqual( NumPosts + postsChange, "posts wrong");
63 | newSnap.NumPostTagLinks.ShouldEqual(NumPostTagLinks + postTagLinkChange, "posttaglinks wrong");
64 | newSnap.NumBlogs.ShouldEqual(NumBlogs + blogsChange, "blogs wrong");
65 | newSnap.NumTags.ShouldEqual(NumTags + tagsChange, "tags wrong");
66 | newSnap.NumPostTagGrades.ShouldEqual(NumPostTagGrades + postTagGradesChange, "postTagGrades wrong");
67 | }
68 |
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Tests/Helpers/DummyIDbContextWithValidation.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: DummyIDbContextWithValidation.cs
5 | // Date Created: 2014/05/24
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Collections.Generic;
30 | using System.Data.Entity;
31 | using System.Data.Entity.Infrastructure;
32 | using System.Data.Entity.Validation;
33 | using System.Threading.Tasks;
34 | using GenericServices;
35 |
36 | namespace Tests.Helpers
37 | {
38 | public class DummyIDbContextWithValidation : IGenericServicesDbContext
39 | {
40 |
41 | public bool SaveChangesCalled { get; private set; }
42 |
43 | public DbSet Set() where TEntity : class
44 | {
45 | throw new NotImplementedException();
46 | }
47 |
48 | public DbSet Set(Type entityType)
49 | {
50 | throw new NotImplementedException();
51 | }
52 |
53 | public int SaveChanges()
54 | {
55 | SaveChangesCalled = true;
56 | return 1;
57 | }
58 |
59 | public async Task SaveChangesAsync()
60 | {
61 | SaveChangesCalled = true;
62 | return 1;
63 | }
64 |
65 | public IEnumerable GetValidationErrors()
66 | {
67 | throw new NotImplementedException();
68 | }
69 |
70 | public DbEntityEntry Entry(TEntity entity) where TEntity : class
71 | {
72 | throw new NotImplementedException();
73 | }
74 |
75 | public DbEntityEntry Entry(object entity)
76 | {
77 | throw new NotImplementedException();
78 | }
79 |
80 | public void Dispose()
81 | {
82 |
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/Tests/Helpers/Log4NetGenericLogger.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Log4NetGenericLogger.cs
5 | // Date Created: 2014/07/03
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using GenericLibsBase;
30 |
31 | namespace Tests.Helpers
32 | {
33 |
34 | public class Log4NetGenericLogger : IGenericLogger
35 | {
36 |
37 | private readonly log4net.ILog _logger;
38 |
39 | public Log4NetGenericLogger(string name)
40 | {
41 | _logger = log4net.LogManager.GetLogger(name);
42 | }
43 |
44 | public void Verbose(object message)
45 | {
46 | _logger.Debug(message);
47 | }
48 |
49 | public void VerboseFormat(string format, params object[] args)
50 | {
51 | _logger.DebugFormat(format, args);
52 | }
53 |
54 | public void Info(object message)
55 | {
56 | _logger.Info(message);
57 | }
58 |
59 | public void InfoFormat(string format, params object[] args)
60 | {
61 | _logger.InfoFormat(format, args);
62 | }
63 |
64 | public void Warn(object message)
65 | {
66 | _logger.Warn(message);
67 | }
68 |
69 | public void WarnFormat(string format, params object[] args)
70 | {
71 | _logger.WarnFormat(format, args);
72 | }
73 |
74 | public void Error(object message)
75 | {
76 | _logger.Error(message);
77 | }
78 |
79 | public void ErrorFormat(string format, params object[] args)
80 | {
81 | _logger.ErrorFormat(format, args);
82 | }
83 |
84 | public void Critical(object message)
85 | {
86 | _logger.Fatal(message);
87 | }
88 |
89 | public void Critical(object message, Exception ex)
90 | {
91 | _logger.Fatal(message, ex);
92 | }
93 |
94 | public void CriticalFormat(string format, params object[] args)
95 | {
96 | _logger.FatalFormat(format, args);
97 | }
98 |
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/Tests/Helpers/TimerToConsole.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: TimerToConsole.cs
5 | // Date Created: 2014/07/21
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System;
29 | using System.Diagnostics;
30 |
31 | namespace Tests.Helpers
32 | {
33 | class TimerToConsole : IDisposable
34 | {
35 |
36 | private readonly Stopwatch _timer;
37 |
38 | private readonly string _message;
39 |
40 | public TimerToConsole(string message)
41 | {
42 | _message = message;
43 | _timer = new Stopwatch();
44 | _timer.Start();
45 | }
46 |
47 | public void Dispose()
48 | {
49 | Console.WriteLine("{0} took {1:f2} ms", _message, 1000.0 * _timer.ElapsedTicks / Stopwatch.Frequency);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: AssemblyInfo.cs
5 | // Date Created: 2014/05/19
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Reflection;
29 | using System.Runtime.InteropServices;
30 |
31 | // General Information about an assembly is controlled through the following
32 | // set of attributes. Change these attribute values to modify the information
33 | // associated with an assembly.
34 | [assembly: AssemblyTitle("Tests")]
35 | [assembly: AssemblyDescription("")]
36 | [assembly: AssemblyConfiguration("")]
37 | [assembly: AssemblyCompany("")]
38 | [assembly: AssemblyProduct("Tests")]
39 | [assembly: AssemblyCopyright("Copyright © 2014")]
40 | [assembly: AssemblyTrademark("")]
41 | [assembly: AssemblyCulture("")]
42 |
43 | // Setting ComVisible to false makes the types in this assembly not visible
44 | // to COM components. If you need to access a type in this assembly from
45 | // COM, set the ComVisible attribute to true on that type.
46 | [assembly: ComVisible(false)]
47 |
48 | // The following GUID is for the ID of the typelib if this project is exposed to COM
49 | [assembly: Guid("53cac227-9b32-409e-ae7b-05dbcd6045b7")]
50 |
51 | // Version information for an assembly consists of the following four values:
52 | //
53 | // Major Version
54 | // Minor Version
55 | // Build Number
56 | // Revision
57 | //
58 | // You can specify all the values or you can default the Build and Revision Numbers
59 | // by using the '*' as shown below:
60 | // [assembly: AssemblyVersion("1.0.*")]
61 | [assembly: AssemblyVersion("1.0.0.0")]
62 | [assembly: AssemblyFileVersion("1.0.0.0")]
63 |
--------------------------------------------------------------------------------
/Tests/TestData/DbContentSimple.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Good post
6 | good
7 |
8 |
9 | Bad post
10 | bad
11 |
12 |
13 | Ugly post
14 | ugly
15 |
16 |
17 |
18 |
19 | Jon Smith
20 | jon.smith@nospam.com
21 |
22 |
23 | First great post
24 | A fine set of words.
25 | In two lines.
26 | good,ugly
27 |
28 |
29 | Second post, which isn't bad
30 | Another fine set of words.
31 | With this line
32 | and another line, making three lines.
33 | bad
34 |
35 |
36 |
37 |
38 | Fred Bloggs
39 | fred.bloggs@nospam.com
40 |
41 |
42 | Freds good post
43 | He hasn't got much to say.
44 | ugly,bad
45 |
46 | bad
47 | 5
48 |
49 |
50 | ugly
51 | 10
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group00GenericLibsBase/Test04SplitCamel.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test04SplitCamel.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 | using NUnit.Framework;
30 | using Tests.Helpers;
31 |
32 | namespace Tests.UnitTests.Group00GenericLibsBase
33 | {
34 | class Test04SplitCamel
35 | {
36 |
37 | [Test]
38 | public void Test01SplitNoNumberOk()
39 | {
40 | //SETUP
41 |
42 | //ATTEMPT
43 | var result = "UnitTest".SplitCamelCase();
44 |
45 | //VERIFY
46 | result.ShouldEqual("Unit Test");
47 | }
48 |
49 | [Test]
50 | public void Test02SplitNumberOk()
51 | {
52 | //SETUP
53 |
54 | //ATTEMPT
55 | var result = "Unit4Test".SplitCamelCase();
56 |
57 | //VERIFY
58 | result.ShouldEqual("Unit4 Test");
59 | }
60 |
61 | [Test]
62 | public void Test05NoSplitOk()
63 | {
64 | //SETUP
65 |
66 | //ATTEMPT
67 | var result = "Unittest".SplitCamelCase();
68 |
69 | //VERIFY
70 | result.ShouldEqual("Unittest");
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group00GenericLibsBase/Test05SetupLogger.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test05SetupLogger.cs
5 | // Date Created: 2014/10/28
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using GenericLibsBase;
29 | using NUnit.Framework;
30 | using Tests.Helpers;
31 |
32 | namespace Tests.UnitTests.Group00GenericLibsBase
33 | {
34 |
35 | class Test05SetupLogger
36 | {
37 | class FirstClass
38 | {
39 | public static readonly IGenericLogger Logger;
40 |
41 | static FirstClass()
42 | {
43 | Logger = GenericLibsBaseConfig.GetLogger("hello");
44 | }
45 | }
46 |
47 | class SecondClass
48 | {
49 | public static readonly IGenericLogger Logger;
50 |
51 | static SecondClass()
52 | {
53 | Logger = GenericLibsBaseConfig.GetLogger("test");
54 | }
55 | }
56 |
57 | [Test]
58 | public void Check01DefaultLoggerSetupOk()
59 | {
60 |
61 | //SETUP
62 | GenericLibsBaseConfig.SetLoggerMethod = name => new NoLoggingGenericLogger();
63 |
64 | //ATTEMPT
65 | var classWithLogger = new FirstClass();
66 |
67 | //VERIFY
68 | FirstClass.Logger.IsA();
69 |
70 | }
71 |
72 | [Test]
73 | public void Check02ChangedLoggerSetupOk()
74 | {
75 |
76 | //SETUP
77 | GenericLibsBaseConfig.SetLoggerMethod = name => new Log4NetGenericLogger(name);
78 |
79 | //ATTEMPT
80 | var classWithLogger = new SecondClass();
81 |
82 | //VERIFY
83 | SecondClass.Logger.IsA();
84 |
85 | }
86 |
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group03ServiceFlow/Test03DetailService.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test03DetailService.cs
5 | // Date Created: 2014/05/24
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Linq;
29 | using GenericServices.Services.Concrete;
30 | using NUnit.Framework;
31 | using Tests.DataClasses;
32 | using Tests.DataClasses.Concrete;
33 | using Tests.DTOs.Concrete;
34 | using Tests.Helpers;
35 |
36 | namespace Tests.UnitTests.Group03ServiceFlow
37 | {
38 | class Test03DetailService
39 | {
40 |
41 | [TestFixtureSetUp]
42 | public void SetUpFixture()
43 | {
44 | using (var db = new SampleWebAppDb())
45 | {
46 | DataLayerInitialise.InitialiseThis();
47 | var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
48 | DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
49 | }
50 | }
51 |
52 | [Test]
53 | public void Check01DetailFlowOk()
54 | {
55 | using (var db = new SampleWebAppDb())
56 | {
57 | //SETUP
58 | var service = new DetailService(db);
59 | var firstTag = db.Tags.First();
60 |
61 | //ATTEMPT
62 | var status = service.GetDetailUsingWhere(x => x.TagId == firstTag.TagId);
63 |
64 | //VERIFY
65 | status.IsValid.ShouldEqual(true, status.Errors);
66 | status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataIn");
67 | }
68 | }
69 |
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group04ServiceFlowAsync/Test03DetailServiceAsync.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test03DetailServiceAsync.cs
5 | // Date Created: 2014/06/17
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Linq;
29 | using GenericServices.ServicesAsync.Concrete;
30 | using NUnit.Framework;
31 | using Tests.DataClasses;
32 | using Tests.DataClasses.Concrete;
33 | using Tests.DTOs.Concrete;
34 | using Tests.Helpers;
35 |
36 | namespace Tests.UnitTests.Group04ServiceFlowAsync
37 | {
38 | class Test03DetailServiceAsync
39 | {
40 |
41 | [TestFixtureSetUp]
42 | public void SetUpFixture()
43 | {
44 | using (var db = new SampleWebAppDb())
45 | {
46 | DataLayerInitialise.InitialiseThis();
47 | var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
48 | DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
49 | }
50 | }
51 |
52 | [Test]
53 | public async void Check01DetailFlowOk()
54 | {
55 | using (var db = new SampleWebAppDb())
56 | {
57 | //SETUP
58 | var service = new DetailServiceAsync(db);
59 | var firstTag = db.Tags.First();
60 |
61 | //ATTEMPT
62 | var status = await service.GetDetailAsync(firstTag.TagId);
63 |
64 | //VERIFY
65 | status.IsValid.ShouldEqual(true, status.Errors);
66 | status.Result.FunctionsCalledCommaDelimited.ShouldEqual("DetailDtoFromDataInAsync");
67 | }
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group08CrudServices/Test01AutoMapper.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test01AutoMapper.cs
5 | // Date Created: 2014/05/20
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Linq;
29 | using AutoMapper;
30 | using NUnit.Framework;
31 | using Tests.Helpers;
32 |
33 | namespace Tests.UnitTests.Group08CrudServices
34 | {
35 | class Test01AutoMapper
36 | {
37 | private class Data
38 | {
39 | public int [] Ints { get; set; }
40 |
41 | public int GetSum { get { return Ints.Sum(); } }
42 | }
43 |
44 | private class DtoAggregate
45 | {
46 | public int IntsCount { get; set; }
47 | public bool IntsAny { get; set; }
48 | public int IntsSum { get; set; } //This does not work!
49 | public int IntsMax { get; set; }
50 | public int Sum { get; set; }
51 | }
52 |
53 | [Test]
54 | public void Check01MappingAggregatesOk()
55 | {
56 |
57 | //SETUP
58 | var data = new Data {Ints = new[] {1, 2, 3}};
59 |
60 | //ATTEMPT
61 | Mapper.CreateMap();
62 | var dto = Mapper.Map(data);
63 |
64 | //VERIFY
65 | dto.IntsCount.ShouldEqual(3);
66 | dto.IntsAny.ShouldEqual(true);
67 | dto.IntsMax.ShouldEqual(3);
68 | }
69 |
70 | [Test]
71 | public void Check02MappingGetSumOk()
72 | {
73 |
74 | //SETUP
75 | var data = new Data { Ints = new[] { 1, 2, 3 } };
76 |
77 | //ATTEMPT
78 | Mapper.CreateMap();
79 | var dto = Mapper.Map(data);
80 |
81 | //VERIFY
82 | dto.Sum.ShouldEqual(6);
83 | }
84 |
85 | [Test]
86 | public void Check05AggregatesSumBad()
87 | {
88 |
89 | //SETUP
90 | var data = new Data { Ints = new[] { 1, 2, 3 } };
91 |
92 | //ATTEMPT
93 | Mapper.CreateMap();
94 | var dto = Mapper.Map(data);
95 |
96 | //VERIFY
97 | dto.IntsSum.ShouldEqual(0);
98 | dto.Sum.ShouldEqual(6);
99 | }
100 |
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group08CrudServices/Test02aPostTagGradeDirect.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test02aPostTagGradeDirect.cs
5 | // Date Created: 2014/05/26
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Linq;
29 | using GenericServices.Services.Concrete;
30 | using NUnit.Framework;
31 | using Tests.DataClasses;
32 | using Tests.DataClasses.Concrete;
33 | using Tests.Helpers;
34 |
35 | namespace Tests.UnitTests.Group08CrudServices
36 | {
37 | class Test02APostTagGradeDirect
38 | {
39 |
40 | [TestFixtureSetUp]
41 | public void SetUpFixture()
42 | {
43 | using (var db = new SampleWebAppDb())
44 | {
45 | DataLayerInitialise.InitialiseThis();
46 | var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
47 | DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
48 | }
49 | }
50 |
51 | [Test]
52 | public void Check01PostTagGradeDeleteOk()
53 | {
54 | using (var db = new SampleWebAppDb())
55 | {
56 | //SETUP
57 | var snap = new DbSnapShot(db);
58 | var service = new DeleteService(db);
59 | var firstPtgUntracked = db.PostTagGrades.AsNoTracking().First();
60 |
61 | //ATTEMPT
62 | var status = service.Delete(firstPtgUntracked.PostId, firstPtgUntracked.TagId);
63 |
64 | //VERIFY
65 | status.IsValid.ShouldEqual(true, status.Errors);
66 | snap.CheckSnapShot(db, 0,0,0,0,-1);
67 |
68 | }
69 | }
70 |
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Tests/UnitTests/Group08CrudServices/Test07BlogsViaDetailDto.cs:
--------------------------------------------------------------------------------
1 | #region licence
2 | // The MIT License (MIT)
3 | //
4 | // Filename: Test07BlogsViaDetailDto.cs
5 | // Date Created: 2014/05/20
6 | //
7 | // Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in all
17 | // copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | // SOFTWARE.
26 | #endregion
27 |
28 | using System.Data.Entity;
29 | using System.Linq;
30 | using GenericServices.Services;
31 | using GenericServices.Services.Concrete;
32 | using NUnit.Framework;
33 | using Tests.DataClasses;
34 | using Tests.DataClasses.Concrete;
35 | using Tests.DTOs.Concrete;
36 | using Tests.Helpers;
37 |
38 | namespace Tests.UnitTests.Group08CrudServices
39 | {
40 | class Test07BlogsViaDetailDto
41 | {
42 |
43 | [TestFixtureSetUp]
44 | public void SetUpFixture()
45 | {
46 | new SimpleBlogWithPostsDto(); //sets up the mapping
47 | }
48 |
49 | [SetUp]
50 | public void SetUp()
51 | {
52 | using (var db = new SampleWebAppDb())
53 | {
54 | DataLayerInitialise.InitialiseThis();
55 | var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
56 | DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
57 | }
58 | }
59 |
60 |
61 | [Test]
62 | public void Check01ReferencesOk()
63 | {
64 |
65 | //SETUP
66 |
67 | //ATTEMPT
68 | IListService listService = new ListService(null);
69 |
70 | //VERIFY
71 | (listService is ListService).ShouldEqual(true);
72 | }
73 |
74 | [Test]
75 | public void Check02ListBlogsCheckIncludesPostsOk()
76 | {
77 | using (var db = new SampleWebAppDb())
78 | {
79 | //SETUP
80 | var service = new ListService(db);
81 |
82 | //ATTEMPT
83 | var list = service.GetAll().ToList();
84 |
85 | //VERIFY
86 | list.Count().ShouldEqual(2);
87 | var firstBlog = db.Blogs.Include(x => x.Posts).AsNoTracking().First();
88 | list.First().Name.ShouldEqual(firstBlog.Name);
89 | list.First().EmailAddress.ShouldEqual(firstBlog.EmailAddress);
90 | list.First().Posts.ShouldNotEqualNull();
91 | CollectionAssert.AreEquivalent(firstBlog.Posts.Select(x => x.PostId), list.First().Posts.Select(x => x.PostId));
92 | }
93 | }
94 |
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/licence.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Jon Smith (www.selectiveanalytics.com & www.thereformedprogrammer.net)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/packages/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !repositories.config
3 | !.gitignore
4 |
--------------------------------------------------------------------------------
/packages/repositories.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------