├── .gitattributes
├── .gitignore
├── Customer.Api.IntegrationTest
├── Customer.Api.IntegrationTest.csproj
├── CustomerControllerTests.cs
└── TestStartup.cs
├── Customer.Api.Test
├── Customer.Api.Test.csproj
└── CustomerControllerTests.cs
├── Customer.Contract
├── Customer.Contract.csproj
└── CustomerDto.cs
├── Customer.Domain.Test
├── Customer.Domain.Test.csproj
└── CustomerTests.cs
├── Customer.Domain
├── Customer.Domain.csproj
├── Customer.cs
├── Entity.cs
├── ICustomerRepository.cs
└── IGenericRepository.cs
├── Customer.Repository.Test
├── Customer.Repository.Test.csproj
└── CustomerRepositoryTests.cs
├── Customer.Repository
├── Customer.Repository.csproj
├── CustomerDbContext.cs
├── CustomerRepository.cs
├── GenericRepository.cs
└── Migrations
│ ├── 20180807050802_TableCreate.Designer.cs
│ ├── 20180807050802_TableCreate.cs
│ └── CustomerDbContextModelSnapshot.cs
├── Customer.Service.Test
├── Customer.Service.Test.csproj
├── CustomerAssemblerTests.cs
└── CustomerServiceTests.cs
├── Customer.Service
├── Customer.Service.csproj
├── CustomerAssembler.cs
├── CustomerService.cs
├── ICustomerAssembler.cs
└── ICustomerService.cs
├── Customer.sln
└── Customer
├── Controllers
└── CustomerController.cs
├── Customer.Api.csproj
├── Program.cs
├── Properties
└── launchSettings.json
├── Startup.cs
├── appsettings.Development.json
└── appsettings.json
/.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 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/Customer.Api.IntegrationTest/Customer.Api.IntegrationTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Customer.Api.IntegrationTest/CustomerControllerTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Net;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.TestHost;
7 | using Newtonsoft.Json;
8 | using System.Net.Http;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using Customer.Contract;
12 | using Xunit;
13 |
14 | namespace Customer.Api.IntegrationTest
15 | {
16 | public class CustomerControllerTests
17 | {
18 | private readonly HttpClient _client;
19 |
20 | public CustomerControllerTests()
21 | {
22 | var testServer = new TestServer(new WebHostBuilder()
23 | .UseStartup()
24 | .UseEnvironment("Development"));
25 | _client = testServer.CreateClient();
26 | }
27 |
28 | [Fact]
29 | public async Task Post_Should_Return_OK_With_Empty_Response_When_Insert_Success()
30 | {
31 | var expectedResult = string.Empty;
32 | var expectedStatusCode = HttpStatusCode.OK;
33 |
34 | // Arrange
35 | var request = new CustomerDto
36 | {
37 | FullName = "Caner Tosuner",
38 | CityCode = "Ist",
39 | BirthDate = new DateTime(1990, 1, 1)
40 | };
41 | var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
42 |
43 | // Act
44 | var response = await _client.PostAsync("/api/customer", content);
45 |
46 | var actualStatusCode = response.StatusCode;
47 | var actualResult = await response.Content.ReadAsStringAsync();
48 |
49 | // Assert
50 | Assert.Equal(expectedResult, actualResult);
51 | Assert.Equal(expectedStatusCode, actualStatusCode);
52 | }
53 |
54 | [Theory]
55 | [InlineData("/api/customer", "/api/customer")]
56 | public async Task Get_Should_Return_OK_With_Inserted_Customer_When_Insert_Success(string postUrl, string getUrl)
57 | {
58 | var expectedResult = string.Empty;
59 | var expectedStatusCode = HttpStatusCode.OK;
60 |
61 | // Arrange-1
62 | var request = new CustomerDto
63 | {
64 | FullName = "Caner Tosuner",
65 | CityCode = "Ist",
66 | BirthDate = new DateTime(1990, 1, 1)
67 | };
68 | var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
69 |
70 | // Act-1
71 | var response = await _client.PostAsync(postUrl, content);
72 |
73 | var actualStatusCode = response.StatusCode;
74 | var actualResult = await response.Content.ReadAsStringAsync();
75 |
76 | // Assert-1
77 | Assert.Equal(expectedResult, actualResult);
78 | Assert.Equal(expectedStatusCode, actualStatusCode);
79 |
80 |
81 |
82 | // Act-2
83 | var responseGet = await _client.GetAsync(getUrl);
84 |
85 | var actualGetResult = await responseGet.Content.ReadAsStringAsync();
86 | var getResultList = JsonConvert.DeserializeObject>(actualGetResult);
87 |
88 | var insertedCustomerExist = getResultList.Any(c => c.FullName == request.FullName);
89 |
90 | // Assert-2
91 | Assert.NotEmpty(getResultList);
92 | Assert.True(insertedCustomerExist);
93 | }
94 |
95 | [Theory]
96 | [InlineData("/api/customer", "/api/customer")]
97 | public async Task Insert_GetAll_Update_GetByCityCode_Should_Return_Expected_Result(string postUrl, string getUrl)
98 | {
99 | #region Insert
100 | var expectedResult = string.Empty;
101 | var expectedStatusCode = HttpStatusCode.OK;
102 |
103 | // Arrange-1
104 | var request = new CustomerDto
105 | {
106 | FullName = "Caner Tosuner",
107 | CityCode = "Ist",
108 | BirthDate = new DateTime(1990, 1, 1)
109 | };
110 | var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
111 |
112 | // Act-1
113 | var response = await _client.PostAsync(postUrl, content);
114 |
115 | var actualStatusCode = response.StatusCode;
116 | var actualResult = await response.Content.ReadAsStringAsync();
117 |
118 | // Assert-1
119 | Assert.Equal(expectedResult, actualResult);
120 | Assert.Equal(expectedStatusCode, actualStatusCode);
121 | #endregion
122 |
123 |
124 |
125 | #region GetAll
126 | // Act-2
127 | var responseGet = await _client.GetAsync(getUrl);
128 | responseGet.EnsureSuccessStatusCode();
129 |
130 | var actualGetResult = await responseGet.Content.ReadAsStringAsync();
131 | var getResultList = JsonConvert.DeserializeObject>(actualGetResult);
132 |
133 | var insertedCustomerExist = getResultList.Any(c => c.CityCode == request.CityCode);
134 |
135 | // Assert-2
136 | Assert.NotEmpty(getResultList);
137 | Assert.True(insertedCustomerExist);
138 | #endregion
139 |
140 |
141 |
142 | #region Update
143 | // Arrange-3
144 | var insertedCustomer = getResultList.Single(c => c.CityCode == request.CityCode);
145 | var requestUpdate = new CustomerDto
146 | {
147 | FullName = "Ali Tosuner",
148 | CityCode = "Ist",
149 | BirthDate = new DateTime(1994, 1, 1),
150 | Id = insertedCustomer.Id
151 | };
152 | var contentUpdate = new StringContent(JsonConvert.SerializeObject(requestUpdate), Encoding.UTF8, "application/json");
153 |
154 | // Act-3
155 | var responseUpdate = await _client.PutAsync(postUrl, contentUpdate);
156 | responseUpdate.EnsureSuccessStatusCode();
157 | var updateActualResult = await responseUpdate.Content.ReadAsAsync();
158 |
159 | // Assert-3
160 | Assert.Equal(updateActualResult.FullName, requestUpdate.FullName);
161 | #endregion
162 |
163 |
164 |
165 | #region GetByCityCode
166 | // Act-2
167 | var responseGetByCityCode = await _client.GetAsync("/api/customer/getbycitycode/"+requestUpdate.CityCode);
168 | responseGetByCityCode.EnsureSuccessStatusCode();
169 |
170 | var actualGetByCityCodeResult = await responseGetByCityCode.Content.ReadAsStringAsync();
171 | var getByCityCodeResultList = JsonConvert.DeserializeObject>(actualGetByCityCodeResult);
172 |
173 | var updatedCustomerExist = getByCityCodeResultList.Any(c => c.CityCode == request.CityCode);
174 |
175 | // Assert-2
176 | Assert.NotEmpty(getByCityCodeResultList);
177 | Assert.True(updatedCustomerExist);
178 | #endregion
179 |
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/Customer.Api.IntegrationTest/TestStartup.cs:
--------------------------------------------------------------------------------
1 | using Customer.Repository;
2 | using Microsoft.EntityFrameworkCore;
3 | using Microsoft.Extensions.Configuration;
4 | using Microsoft.Extensions.DependencyInjection;
5 |
6 | namespace Customer.Api.IntegrationTest
7 | {
8 | public class TestStartup : Startup
9 | {
10 | public TestStartup(IConfiguration configuration) : base(configuration)
11 | {
12 | }
13 |
14 | public override void ConfigureDatabase(IServiceCollection services)
15 | {
16 | services.AddDbContext(options =>
17 | options.UseInMemoryDatabase("customerDb_test"));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Customer.Api.Test/Customer.Api.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | ..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.core\2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Customer.Api.Test/CustomerControllerTests.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canertosuner/Asp.Net-Core-Entity-Framework-Integration-Test-and-Unit-Test-Using-In-Memory-Database/3b3551dfa4c96c0bb1802bc50da9775b025b2c61/Customer.Api.Test/CustomerControllerTests.cs
--------------------------------------------------------------------------------
/Customer.Contract/Customer.Contract.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Customer.Contract/CustomerDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Customer.Contract
4 | {
5 | public class CustomerDto
6 | {
7 | public Guid Id { get; set; }
8 | public string FullName { get; set; }
9 | public string CityCode { get; set; }
10 | public DateTime BirthDate { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Customer.Domain.Test/Customer.Domain.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Customer.Domain.Test/CustomerTests.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canertosuner/Asp.Net-Core-Entity-Framework-Integration-Test-and-Unit-Test-Using-In-Memory-Database/3b3551dfa4c96c0bb1802bc50da9775b025b2c61/Customer.Domain.Test/CustomerTests.cs
--------------------------------------------------------------------------------
/Customer.Domain/Customer.Domain.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Customer.Domain/Customer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Customer.Domain
4 | {
5 | public class Customer : Entity
6 | {
7 | public string FullName { get; protected set; }
8 | public string CityCode { get; protected set; }
9 | public DateTime BirthDate { get; protected set; }
10 |
11 | public Customer(string fullName, string cityCode, DateTime birthDate)
12 | {
13 | if (
14 | string.IsNullOrEmpty(fullName) ||
15 | string.IsNullOrEmpty(cityCode) ||
16 | birthDate.Date == DateTime.Today)
17 | {
18 | throw new Exception("Fields are not valid to create a new customer.");
19 | }
20 |
21 | FullName = fullName;
22 | CityCode = cityCode;
23 | BirthDate = birthDate;
24 | }
25 |
26 | protected Customer()
27 | {
28 |
29 | }
30 |
31 | public void SetFields(string fullName, string cityCode, DateTime birthDate)
32 | {
33 | if (string.IsNullOrEmpty(fullName) ||
34 | string.IsNullOrEmpty(cityCode) ||
35 | birthDate.Date == DateTime.Today)
36 | {
37 | throw new Exception("Fields are not valid to update.");
38 | }
39 |
40 | FullName = fullName;
41 | CityCode = cityCode;
42 | BirthDate = birthDate;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Customer.Domain/Entity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Customer.Domain
4 | {
5 | public abstract class Entity
6 | {
7 | public Guid Id { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Customer.Domain/ICustomerRepository.cs:
--------------------------------------------------------------------------------
1 | namespace Customer.Domain
2 | {
3 | public interface ICustomerRepository : IGenericRepository
4 | {
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Customer.Domain/IGenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Linq.Expressions;
4 |
5 | namespace Customer.Domain
6 | {
7 | public interface IGenericRepository where T : Entity
8 | {
9 | Guid Save(T entity);
10 | T Get(Guid id);
11 | void Update(T entity);
12 | void Delete(Guid id);
13 | IQueryable All();
14 | IQueryable Find(Expression> predicate);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Customer.Repository.Test/Customer.Repository.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Customer.Repository.Test/CustomerRepositoryTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using FluentAssertions;
4 | using Microsoft.EntityFrameworkCore;
5 | using Xunit;
6 |
7 | namespace Customer.Repository.Test
8 | {
9 | public class CustomerRepositoryTests
10 | {
11 | [Fact]
12 | public void Save_Should_Save_The_Customer_And_Should_Return_All_Count_As_Two()
13 | {
14 | var customer1 = new Domain.Customer("Caner Tosuner", "IST", DateTime.Today.AddYears(28));
15 | var customer2 = new Domain.Customer("Caner Tosuner", "IST", DateTime.Today.AddYears(28));
16 |
17 | var options = new DbContextOptionsBuilder()
18 | .UseInMemoryDatabase("customer_db")
19 | .Options;
20 |
21 | using (var context = new CustomerDbContext(options))
22 | {
23 | var repository = new CustomerRepository(context);
24 | repository.Save(customer1);
25 | repository.Save(customer2);
26 | context.SaveChanges();
27 | }
28 |
29 | using (var context = new CustomerDbContext(options))
30 | {
31 | var repository = new CustomerRepository(context);
32 | repository.All().Count().Should().Be(2);
33 | }
34 | }
35 |
36 | [Fact]
37 | public void Delete_Should_Delete_The_Customer_And_Should_Return_All_Count_As_One()
38 | {
39 | var customer1 = new Domain.Customer("Caner Tosuner", "IST", DateTime.Today.AddYears(28));
40 | var customer2 = new Domain.Customer("Caner Tosuner", "IST", DateTime.Today.AddYears(28));
41 |
42 | var options = new DbContextOptionsBuilder()
43 | .UseInMemoryDatabase("customer_db")
44 | .Options;
45 |
46 | using (var context = new CustomerDbContext(options))
47 | {
48 | var repository = new CustomerRepository(context);
49 | repository.Save(customer1);
50 | repository.Save(customer2);
51 | context.SaveChanges();
52 | }
53 |
54 | using (var context = new CustomerDbContext(options))
55 | {
56 | var repository = new CustomerRepository(context);
57 | repository.Delete(customer1.Id);
58 | context.SaveChanges();
59 | }
60 |
61 | using (var context = new CustomerDbContext(options))
62 | {
63 | var repository = new CustomerRepository(context);
64 | repository.All().Count().Should().Be(1);
65 | }
66 | }
67 |
68 | [Fact]
69 | public void Update_Should_Update_The_Customer()
70 | {
71 | var customer = new Domain.Customer("Caner Tosuner", "IST", DateTime.Today.AddYears(28));
72 |
73 | var options = new DbContextOptionsBuilder()
74 | .UseInMemoryDatabase("customer_db")
75 | .Options;
76 |
77 | using (var context = new CustomerDbContext(options))
78 | {
79 | var repository = new CustomerRepository(context);
80 | repository.Save(customer);
81 | context.SaveChanges();
82 | }
83 |
84 | customer.SetFields("Caner T", "IZM", customer.BirthDate);
85 |
86 | using (var context = new CustomerDbContext(options))
87 | {
88 | var repository = new CustomerRepository(context);
89 | repository.Update(customer);
90 | context.SaveChanges();
91 | }
92 |
93 | using (var context = new CustomerDbContext(options))
94 | {
95 | var repository = new CustomerRepository(context);
96 | var result = repository.Get(customer.Id);
97 |
98 | result.Should().NotBe(null);
99 | result.FullName.Should().Be(customer.FullName);
100 | result.CityCode.Should().Be(customer.CityCode);
101 | result.BirthDate.Should().Be(customer.BirthDate);
102 | }
103 | }
104 |
105 | [Fact]
106 | public void Find_Should_Fid_The_Customer_And_Should_Return_All_Count_As_One()
107 | {
108 | var customer1 = new Domain.Customer("Caner Tosuner", "IST", DateTime.Today.AddYears(28));
109 | var customer2 = new Domain.Customer("Caner Tosuner", "IZM", DateTime.Today.AddYears(28));
110 |
111 | var options = new DbContextOptionsBuilder()
112 | .UseInMemoryDatabase("customer_db")
113 | .Options;
114 |
115 | using (var context = new CustomerDbContext(options))
116 | {
117 | var repository = new CustomerRepository(context);
118 | repository.Save(customer1);
119 | repository.Save(customer2);
120 | context.SaveChanges();
121 | }
122 |
123 | using (var context = new CustomerDbContext(options))
124 | {
125 | var repository = new CustomerRepository(context);
126 | var result = repository.Find(c => c.CityCode == customer1.CityCode);
127 | result.Should().NotBeNull();
128 | result.Count().Should().Be(1);
129 | }
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/Customer.Repository/Customer.Repository.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | ..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.relational\2.1.1\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Relational.dll
18 |
19 |
20 | ..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.sqlserver\2.1.1\lib\netstandard2.0\Microsoft.EntityFrameworkCore.SqlServer.dll
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Customer.Repository/CustomerDbContext.cs:
--------------------------------------------------------------------------------
1 |
2 |
3 | using Microsoft.EntityFrameworkCore;
4 |
5 | namespace Customer.Repository
6 | {
7 | public class CustomerDbContext : DbContext
8 | {
9 | public CustomerDbContext(DbContextOptions options)
10 | : base(options)
11 | {
12 | }
13 |
14 | public DbSet Customer { get; set; }
15 |
16 | protected override void OnModelCreating(ModelBuilder builder)
17 | {
18 | base.OnModelCreating(builder);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Customer.Repository/CustomerRepository.cs:
--------------------------------------------------------------------------------
1 | using Customer.Domain;
2 |
3 | namespace Customer.Repository
4 | {
5 | public class CustomerRepository : GenericRepository, ICustomerRepository
6 | {
7 | public CustomerRepository(CustomerDbContext dbContext) : base(dbContext)
8 | {
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Customer.Repository/GenericRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Linq.Expressions;
4 | using Customer.Domain;
5 | using Microsoft.EntityFrameworkCore;
6 |
7 | namespace Customer.Repository
8 | {
9 | public abstract class GenericRepository : IGenericRepository where T : Entity
10 | {
11 | private readonly CustomerDbContext _dbContext;
12 | private readonly DbSet _dbSet;
13 |
14 | protected GenericRepository(CustomerDbContext dbContext)
15 | {
16 | this._dbContext = dbContext;
17 | this._dbSet = _dbContext.Set();
18 | }
19 |
20 | public Guid Save(T entity)
21 | {
22 | entity.Id = Guid.NewGuid();
23 | _dbSet.Add(entity);
24 |
25 | _dbContext.SaveChanges();
26 |
27 | return entity.Id;
28 | }
29 |
30 | public T Get(Guid id)
31 | {
32 | return _dbSet.Find(id);
33 | }
34 |
35 | public void Update(T entity)
36 | {
37 | _dbSet.Attach(entity);
38 | _dbContext.Entry(entity).State = EntityState.Modified;
39 |
40 | _dbContext.SaveChanges();
41 | }
42 |
43 | public void Delete(Guid id)
44 | {
45 | var entity = Get(id);
46 | _dbSet.Remove(entity);
47 | _dbContext.SaveChanges();
48 | }
49 |
50 | public IQueryable All()
51 | {
52 | return _dbSet.AsNoTracking();
53 | }
54 |
55 | public IQueryable Find(Expression> predicate)
56 | {
57 | return _dbSet.Where(predicate);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Customer.Repository/Migrations/20180807050802_TableCreate.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using Customer.Repository;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Migrations;
8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
9 |
10 | namespace Customer.Repository.Migrations
11 | {
12 | [DbContext(typeof(CustomerDbContext))]
13 | [Migration("20180807050802_TableCreate")]
14 | partial class TableCreate
15 | {
16 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
17 | {
18 | #pragma warning disable 612, 618
19 | modelBuilder
20 | .HasAnnotation("ProductVersion", "2.1.1-rtm-30846")
21 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
23 |
24 | modelBuilder.Entity("Customer.Domain.Customer", b =>
25 | {
26 | b.Property("Id")
27 | .ValueGeneratedOnAdd();
28 |
29 | b.Property("BirthDate");
30 |
31 | b.Property("CityCode");
32 |
33 | b.Property("FullName");
34 |
35 | b.HasKey("Id");
36 |
37 | b.ToTable("Customer");
38 | });
39 | #pragma warning restore 612, 618
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Customer.Repository/Migrations/20180807050802_TableCreate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.Migrations;
3 |
4 | namespace Customer.Repository.Migrations
5 | {
6 | public partial class TableCreate : Migration
7 | {
8 | protected override void Up(MigrationBuilder migrationBuilder)
9 | {
10 | migrationBuilder.CreateTable(
11 | name: "Customer",
12 | columns: table => new
13 | {
14 | Id = table.Column(nullable: false),
15 | FullName = table.Column(nullable: true),
16 | CityCode = table.Column(nullable: true),
17 | BirthDate = table.Column(nullable: false)
18 | },
19 | constraints: table =>
20 | {
21 | table.PrimaryKey("PK_Customer", x => x.Id);
22 | });
23 | }
24 |
25 | protected override void Down(MigrationBuilder migrationBuilder)
26 | {
27 | migrationBuilder.DropTable(
28 | name: "Customer");
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Customer.Repository/Migrations/CustomerDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using Customer.Repository;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace Customer.Repository.Migrations
10 | {
11 | [DbContext(typeof(CustomerDbContext))]
12 | partial class CustomerDbContextModelSnapshot : ModelSnapshot
13 | {
14 | protected override void BuildModel(ModelBuilder modelBuilder)
15 | {
16 | #pragma warning disable 612, 618
17 | modelBuilder
18 | .HasAnnotation("ProductVersion", "2.1.1-rtm-30846")
19 | .HasAnnotation("Relational:MaxIdentifierLength", 128)
20 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
21 |
22 | modelBuilder.Entity("Customer.Domain.Customer", b =>
23 | {
24 | b.Property("Id")
25 | .ValueGeneratedOnAdd();
26 |
27 | b.Property("BirthDate");
28 |
29 | b.Property("CityCode");
30 |
31 | b.Property("FullName");
32 |
33 | b.HasKey("Id");
34 |
35 | b.ToTable("Customer");
36 | });
37 | #pragma warning restore 612, 618
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Customer.Service.Test/Customer.Service.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Customer.Service.Test/CustomerAssemblerTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Customer.Contract;
3 | using FluentAssertions;
4 | using Xunit;
5 |
6 | namespace Customer.Service.Test
7 | {
8 | public class CustomerAssemblerTests
9 | {
10 | [Theory, AutoMoqData]
11 | public void ToCustomer_Should_Success(CustomerDto customerDto,CustomerAssembler sut)
12 | {
13 | Action action = () =>
14 | {
15 | var result = sut.ToCustomer(customerDto);
16 | result.CityCode.Should().Be(customerDto.CityCode);
17 | result.FullName.Should().Be(customerDto.FullName);
18 | result.BirthDate.Should().Be(customerDto.BirthDate);
19 | };
20 | action.Should().NotThrow();
21 | }
22 |
23 | [Theory, AutoMoqData]
24 | public void ToCustomerDto_Should_Success(Domain.Customer customer, CustomerAssembler sut)
25 | {
26 | Action action = () =>
27 | {
28 | var result = sut.ToCustomerDto(customer);
29 | result.Id.Should().Be(customer.Id);
30 | result.CityCode.Should().Be(customer.CityCode);
31 | result.FullName.Should().Be(customer.FullName);
32 | result.BirthDate.Should().Be(customer.BirthDate);
33 | };
34 | action.Should().NotThrow();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Customer.Service.Test/CustomerServiceTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Linq.Expressions;
5 | using AutoFixture;
6 | using AutoFixture.AutoMoq;
7 | using AutoFixture.Xunit2;
8 | using Customer.Contract;
9 | using Customer.Domain;
10 | using Customer.Repository;
11 | using FluentAssertions;
12 | using Moq;
13 | using Xunit;
14 |
15 | namespace Customer.Service.Test
16 | {
17 | public class CustomerServiceTests
18 | {
19 | [Theory, AutoMoqData]
20 | public void CreateNewCustomer_Should_Success([Frozen]Mock assembler, [Frozen]Mock repository, CustomerDto customerDto, Domain.Customer customer, CustomerService sut)
21 | {
22 | assembler.Setup(c => c.ToCustomer(customerDto)).Returns(customer);
23 | repository.Setup(c => c.Save(customer)).Returns(It.IsAny());
24 |
25 | Action action = () =>
26 | {
27 | sut.CreateNew(customerDto);
28 | };
29 | action.Should().NotThrow();
30 | }
31 |
32 | [Theory, AutoMoqData]
33 | public void UpdateCustomer_Should_Success([Frozen]Mock assembler, [Frozen]Mock repository, CustomerDto customerDto, Domain.Customer customer, CustomerService sut)
34 | {
35 | assembler.Setup(c => c.ToCustomer(customerDto)).Returns(customer);
36 | repository.Setup(c => c.Update(customer));
37 |
38 | Action action = () =>
39 | {
40 | sut.Update(customerDto);
41 | };
42 | action.Should().NotThrow();
43 | }
44 |
45 | [Theory, AutoMoqData]
46 | public void GetAll_Should_Success([Frozen]Mock assembler, [Frozen]Mock repository, List customers, List customersDtos, CustomerService sut)
47 | {
48 | repository.Setup(c => c.All()).Returns(customers.AsQueryable);
49 | assembler.Setup(c => c.ToCustomerDtoList(customers)).Returns(customersDtos);
50 |
51 | Action action = () =>
52 | {
53 | var result = sut.GetAll();
54 | result.Count.Should().Be(customersDtos.Count);
55 | };
56 | action.Should().NotThrow();
57 | }
58 |
59 |
60 | [Theory, AutoMoqData]
61 | public void GetByCityCode_Should_Success([Frozen]Mock assembler, [Frozen]Mock repository, string cityCode, List customers, List customersDtos, CustomerService sut)
62 | {
63 | assembler.Setup(c => c.ToCustomerDtoList(customers)).Returns(customersDtos);
64 | repository.Setup(x => x.Find(It.IsAny>>())).Returns(customers.AsQueryable);
65 |
66 | Action action = () =>
67 | {
68 | var result = sut.GetByCityCode(cityCode);
69 | result.Should().BeEquivalentTo(customersDtos);
70 | };
71 | action.Should().NotThrow();
72 | }
73 |
74 | [Theory, AutoMoqData]
75 | public void GetById_Should_Return_As_Expected([Frozen]Mock assembler, [Frozen]Mock repository, Guid id, CustomerDto customerDto, Domain.Customer customer, CustomerService sut)
76 | {
77 | assembler.Setup(c => c.ToCustomerDto(customer)).Returns(customerDto);
78 | repository.Setup(c => c.Get(id)).Returns(customer);
79 |
80 | Action action = () =>
81 | {
82 | var result = sut.GetById(id);
83 | result.Should().BeEquivalentTo(customerDto);
84 | };
85 | action.Should().NotThrow();
86 | }
87 | }
88 | //Method parameter olarak Automoq yapabilmek için kullanacağımız attribute
89 | public class AutoMoqDataAttribute : AutoDataAttribute
90 | {
91 | public AutoMoqDataAttribute()
92 | : base(new Fixture().Customize(new AutoMoqCustomization()))
93 | {
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Customer.Service/Customer.Service.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Customer.Service/CustomerAssembler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Customer.Contract;
3 |
4 | namespace Customer.Service
5 | {
6 | public class CustomerAssembler : ICustomerAssembler
7 | {
8 | public Domain.Customer ToCustomer(CustomerDto customerDto)
9 | {
10 | return new Domain.Customer(customerDto.FullName, customerDto.CityCode, customerDto.BirthDate);
11 | }
12 |
13 | public CustomerDto ToCustomerDto(Domain.Customer customer)
14 | {
15 | return new CustomerDto
16 | {
17 | Id = customer.Id,
18 | BirthDate = customer.BirthDate,
19 | CityCode = customer.CityCode,
20 | FullName = customer.FullName
21 | };
22 | }
23 |
24 | public List ToCustomerDtoList(List customerList)
25 | {
26 | var response = new List();
27 | foreach (var customer in customerList)
28 | {
29 | var customerDto = ToCustomerDto(customer);
30 | response.Add(customerDto);
31 | }
32 |
33 | return response;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Customer.Service/CustomerService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Customer.Contract;
5 | using Customer.Domain;
6 | using Customer.Repository;
7 |
8 | namespace Customer.Service
9 | {
10 | public class CustomerService : ICustomerService
11 | {
12 | private readonly ICustomerRepository _customerRepository;
13 | private readonly ICustomerAssembler _customerAssembler;
14 | public CustomerService(ICustomerRepository customerRepository, ICustomerAssembler customerAssembler)
15 | {
16 | _customerRepository = customerRepository;
17 | _customerAssembler = customerAssembler;
18 | }
19 |
20 | public void CreateNew(CustomerDto customerDto)
21 | {
22 | var customer = _customerAssembler.ToCustomer(customerDto);
23 |
24 | _customerRepository.Save(customer);
25 | }
26 |
27 | public CustomerDto Update(CustomerDto customer)
28 | {
29 | var existing = _customerRepository.Get(customer.Id);
30 |
31 | existing.SetFields(customer.FullName, customer.CityCode, customer.BirthDate);
32 |
33 | _customerRepository.Update(existing);
34 |
35 | var customerDto = _customerAssembler.ToCustomerDto(existing);
36 |
37 | return customerDto;
38 | }
39 |
40 | public List GetAll()
41 | {
42 | var all = _customerRepository.All().ToList();
43 | return _customerAssembler.ToCustomerDtoList(all);
44 | }
45 |
46 | public List GetByCityCode(string cityCode)
47 | {
48 | var list = _customerRepository.Find(c => c.CityCode == cityCode).ToList();
49 | return _customerAssembler.ToCustomerDtoList(list);
50 | }
51 |
52 | public CustomerDto GetById(Guid id)
53 | {
54 | var customer = _customerRepository.Get(id);
55 | if (customer == null)
56 | {
57 | throw new Exception("Customer with this id : " + id + " not found.");
58 | }
59 | var customerDto = _customerAssembler.ToCustomerDto(customer);
60 | return customerDto;
61 | }
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Customer.Service/ICustomerAssembler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Customer.Contract;
3 |
4 | namespace Customer.Service
5 | {
6 | public interface ICustomerAssembler
7 | {
8 | Domain.Customer ToCustomer(CustomerDto customerDto);
9 |
10 | CustomerDto ToCustomerDto(Domain.Customer customer);
11 | List ToCustomerDtoList(List customerList);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Customer.Service/ICustomerService.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Collections.Generic;
4 | using Customer.Contract;
5 |
6 | namespace Customer.Service
7 | {
8 | public interface ICustomerService
9 | {
10 | void CreateNew(CustomerDto customer);
11 | CustomerDto Update(CustomerDto customer);
12 | List GetAll();
13 | List GetByCityCode(string cityCode);
14 | CustomerDto GetById(Guid id);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Customer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2020
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Api", "Customer\Customer.Api.csproj", "{2BD32524-7E31-4D09-84F0-3DB6D703CA1D}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Service", "Customer.Service\Customer.Service.csproj", "{03EEA587-7D10-454C-B6CD-C125A153D7BA}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Contract", "Customer.Contract\Customer.Contract.csproj", "{18335126-6380-4BA8-AC6B-8A833BF7CEF1}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Domain", "Customer.Domain\Customer.Domain.csproj", "{F2365322-30E1-436E-9828-503A7C169C40}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Repository", "Customer.Repository\Customer.Repository.csproj", "{F0780293-4108-4918-8F0E-C9B519608A02}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4EFD93A8-5B9C-43AF-AD4F-52D8501882CF}"
17 | EndProject
18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{53D6101A-9E99-41FF-91DE-9B93D7BF44D6}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Repository.Test", "Customer.Repository.Test\Customer.Repository.Test.csproj", "{1A273745-900E-496D-99B7-08284F238609}"
21 | EndProject
22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Api.Test", "Customer.Api.Test\Customer.Api.Test.csproj", "{0CBADD96-582C-45AC-ACB3-37FE2D67E292}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Service.Test", "Customer.Service.Test\Customer.Service.Test.csproj", "{11F3FFA4-4CA4-46B0-A5CF-C8438C3A32FA}"
25 | EndProject
26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Customer.Domain.Test", "Customer.Domain.Test\Customer.Domain.Test.csproj", "{1A9B4231-0918-4257-A69D-47FD3F8266F9}"
27 | EndProject
28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Customer.Api.IntegrationTest", "Customer.Api.IntegrationTest\Customer.Api.IntegrationTest.csproj", "{A5744636-89EB-486E-A5CA-5DBB42C0CC3A}"
29 | EndProject
30 | Global
31 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
32 | Debug|Any CPU = Debug|Any CPU
33 | Release|Any CPU = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
36 | {2BD32524-7E31-4D09-84F0-3DB6D703CA1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {2BD32524-7E31-4D09-84F0-3DB6D703CA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {2BD32524-7E31-4D09-84F0-3DB6D703CA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {2BD32524-7E31-4D09-84F0-3DB6D703CA1D}.Release|Any CPU.Build.0 = Release|Any CPU
40 | {03EEA587-7D10-454C-B6CD-C125A153D7BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {03EEA587-7D10-454C-B6CD-C125A153D7BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {03EEA587-7D10-454C-B6CD-C125A153D7BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {03EEA587-7D10-454C-B6CD-C125A153D7BA}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {18335126-6380-4BA8-AC6B-8A833BF7CEF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {18335126-6380-4BA8-AC6B-8A833BF7CEF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {18335126-6380-4BA8-AC6B-8A833BF7CEF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {18335126-6380-4BA8-AC6B-8A833BF7CEF1}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {F2365322-30E1-436E-9828-503A7C169C40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {F2365322-30E1-436E-9828-503A7C169C40}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {F2365322-30E1-436E-9828-503A7C169C40}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {F2365322-30E1-436E-9828-503A7C169C40}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {F0780293-4108-4918-8F0E-C9B519608A02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {F0780293-4108-4918-8F0E-C9B519608A02}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {F0780293-4108-4918-8F0E-C9B519608A02}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {F0780293-4108-4918-8F0E-C9B519608A02}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {1A273745-900E-496D-99B7-08284F238609}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {1A273745-900E-496D-99B7-08284F238609}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {1A273745-900E-496D-99B7-08284F238609}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {1A273745-900E-496D-99B7-08284F238609}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {0CBADD96-582C-45AC-ACB3-37FE2D67E292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61 | {0CBADD96-582C-45AC-ACB3-37FE2D67E292}.Debug|Any CPU.Build.0 = Debug|Any CPU
62 | {0CBADD96-582C-45AC-ACB3-37FE2D67E292}.Release|Any CPU.ActiveCfg = Release|Any CPU
63 | {0CBADD96-582C-45AC-ACB3-37FE2D67E292}.Release|Any CPU.Build.0 = Release|Any CPU
64 | {11F3FFA4-4CA4-46B0-A5CF-C8438C3A32FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65 | {11F3FFA4-4CA4-46B0-A5CF-C8438C3A32FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
66 | {11F3FFA4-4CA4-46B0-A5CF-C8438C3A32FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
67 | {11F3FFA4-4CA4-46B0-A5CF-C8438C3A32FA}.Release|Any CPU.Build.0 = Release|Any CPU
68 | {1A9B4231-0918-4257-A69D-47FD3F8266F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69 | {1A9B4231-0918-4257-A69D-47FD3F8266F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
70 | {1A9B4231-0918-4257-A69D-47FD3F8266F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
71 | {1A9B4231-0918-4257-A69D-47FD3F8266F9}.Release|Any CPU.Build.0 = Release|Any CPU
72 | {A5744636-89EB-486E-A5CA-5DBB42C0CC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73 | {A5744636-89EB-486E-A5CA-5DBB42C0CC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
74 | {A5744636-89EB-486E-A5CA-5DBB42C0CC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
75 | {A5744636-89EB-486E-A5CA-5DBB42C0CC3A}.Release|Any CPU.Build.0 = Release|Any CPU
76 | EndGlobalSection
77 | GlobalSection(SolutionProperties) = preSolution
78 | HideSolutionNode = FALSE
79 | EndGlobalSection
80 | GlobalSection(NestedProjects) = preSolution
81 | {2BD32524-7E31-4D09-84F0-3DB6D703CA1D} = {4EFD93A8-5B9C-43AF-AD4F-52D8501882CF}
82 | {03EEA587-7D10-454C-B6CD-C125A153D7BA} = {4EFD93A8-5B9C-43AF-AD4F-52D8501882CF}
83 | {18335126-6380-4BA8-AC6B-8A833BF7CEF1} = {4EFD93A8-5B9C-43AF-AD4F-52D8501882CF}
84 | {F2365322-30E1-436E-9828-503A7C169C40} = {4EFD93A8-5B9C-43AF-AD4F-52D8501882CF}
85 | {F0780293-4108-4918-8F0E-C9B519608A02} = {4EFD93A8-5B9C-43AF-AD4F-52D8501882CF}
86 | {1A273745-900E-496D-99B7-08284F238609} = {53D6101A-9E99-41FF-91DE-9B93D7BF44D6}
87 | {0CBADD96-582C-45AC-ACB3-37FE2D67E292} = {53D6101A-9E99-41FF-91DE-9B93D7BF44D6}
88 | {11F3FFA4-4CA4-46B0-A5CF-C8438C3A32FA} = {53D6101A-9E99-41FF-91DE-9B93D7BF44D6}
89 | {1A9B4231-0918-4257-A69D-47FD3F8266F9} = {53D6101A-9E99-41FF-91DE-9B93D7BF44D6}
90 | {A5744636-89EB-486E-A5CA-5DBB42C0CC3A} = {53D6101A-9E99-41FF-91DE-9B93D7BF44D6}
91 | EndGlobalSection
92 | GlobalSection(ExtensibilityGlobals) = postSolution
93 | SolutionGuid = {ED0B8257-8D8F-4780-931F-25A99DB70772}
94 | EndGlobalSection
95 | EndGlobal
96 |
--------------------------------------------------------------------------------
/Customer/Controllers/CustomerController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Customer.Contract;
4 | using Customer.Service;
5 | using Microsoft.AspNetCore.Mvc;
6 |
7 | namespace Customer.Api.Controllers
8 | {
9 | [Route("api/[controller]")]
10 | [ApiController]
11 | public class CustomerController : ControllerBase
12 | {
13 | private readonly ICustomerService _customerService;
14 | public CustomerController(ICustomerService customerService)
15 | {
16 | _customerService = customerService;
17 | }
18 |
19 | // GET api/customer
20 | [HttpGet]
21 | public ActionResult> Get()
22 | {
23 | return Ok(_customerService.GetAll());
24 | }
25 |
26 | // GET api/customer/id
27 | [HttpGet("{id}")]
28 | public ActionResult Get(Guid id)
29 | {
30 | return Ok(_customerService.GetById(id));
31 | }
32 |
33 | // POST api/customer
34 | [HttpPost]
35 | public ActionResult Post([FromBody] CustomerDto customer)
36 | {
37 | _customerService.CreateNew(customer);
38 | return Ok();
39 | }
40 |
41 | // PUT api/customer
42 | [HttpPut]
43 | public ActionResult Put([FromBody] CustomerDto customer)
44 | {
45 | return Ok(_customerService.Update(customer));
46 | }
47 |
48 | // GET api/customer/getbycitycode/cityCode
49 | [HttpGet("getbycitycode/{cityCode}")]
50 | public ActionResult> GetByCityCode(string cityCode)
51 | {
52 | return Ok(_customerService.GetByCityCode(cityCode));
53 | }
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Customer/Customer.Api.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Customer/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore;
2 | using Microsoft.AspNetCore.Hosting;
3 |
4 | namespace Customer.Api
5 | {
6 | public class Program
7 | {
8 | public static void Main(string[] args)
9 | {
10 | CreateWebHostBuilder(args).Build().Run();
11 | }
12 |
13 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
14 | WebHost.CreateDefaultBuilder(args)
15 | .UseStartup();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Customer/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:49500",
8 | "sslPort": 44390
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "launchBrowser": true,
15 | "launchUrl": "api/customer",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "Customer": {
21 | "commandName": "Project",
22 | "launchBrowser": true,
23 | "launchUrl": "api/customer",
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Customer/Startup.cs:
--------------------------------------------------------------------------------
1 | using Customer.Domain;
2 | using Customer.Repository;
3 | using Customer.Service;
4 | using Microsoft.AspNetCore.Builder;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.Mvc;
7 | using Microsoft.EntityFrameworkCore;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.DependencyInjection;
10 |
11 | namespace Customer.Api
12 | {
13 | public class Startup
14 | {
15 | public Startup(IConfiguration configuration)
16 | {
17 | Configuration = configuration;
18 | }
19 |
20 | public IConfiguration Configuration { get; }
21 |
22 | // This method gets called by the runtime. Use this method to add services to the container.
23 | public void ConfigureServices(IServiceCollection services)
24 | {
25 | ConfigureDatabase(services);
26 | services.AddScoped();
27 | services.AddScoped();
28 |
29 | services.AddTransient();
30 | services.AddTransient();
31 |
32 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
33 | }
34 |
35 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
36 | public void Configure(IApplicationBuilder app, IHostingEnvironment env)
37 | {
38 | if (env.IsDevelopment())
39 | {
40 | app.UseDeveloperExceptionPage();
41 | }
42 | else
43 | {
44 | app.UseHsts();
45 | }
46 |
47 | app.UseMvc();
48 | }
49 |
50 | public virtual void ConfigureDatabase(IServiceCollection services)
51 | {
52 | services.AddDbContext(options =>
53 | options.UseSqlServer(Configuration.GetSection("CustomerDbConnString").Value));
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Customer/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Customer/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Warning"
5 | }
6 | },
7 | "AllowedHosts": "*",
8 | "CustomerDbConnString": "Server=.;Initial Catalog=Customerdb;Persist Security Info=False;User ID=Customeruser;Password=qwerty135-;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=True;Connection Timeout=30;"
9 | }
10 |
--------------------------------------------------------------------------------