You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/standard/microservices-architecture/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-design.md
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ ms.workload:
12
12
- "dotnet"
13
13
- "dotnetcore"
14
14
---
15
+
15
16
# Designing the infrastructure persistence layer
16
17
17
18
Data persistence components provide access to the data hosted within the boundaries of a microservice (that is, a microservice’s database). They contain the actual implementation of components such as repositories and [Unit of Work](http://martinfowler.com/eaaCatalog/unitOfWork.html) classes, like custom EF DBContexts.
@@ -103,7 +104,7 @@ We find repositories useful, but we acknowledge that they are not critical for y
Copy file name to clipboardExpand all lines: docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md
+28-36Lines changed: 28 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,11 @@ ms.workload:
10
10
- "dotnet"
11
11
- "dotnetcore"
12
12
---
13
+
13
14
# Test ASP.NET Core MVC Apps
14
15
15
-
> _"If you don't like unit testing your product, most likely your customers won't like to test it, either."_
16
-
> _- Anonymous-
16
+
> *"If you don't like unit testing your product, most likely your customers won't like to test it, either."*
17
+
> \_- Anonymous-
17
18
18
19
## Summary
19
20
@@ -100,19 +101,19 @@ Figure 9-3 Add an xUnit Test Project in Visual Studio
100
101
101
102
Youshouldnameyourtestsinaconsistentfashion, withnamesthatindicatewhateachtestdoes. OneapproachI've had great success with is to name test classes according to the class and method they are testing. This results in many small test classes, but it makes it extremely clear what each test is responsible for. With the test class name set up to identify the class and method to be tested, the test method name can be used to specify the behavior being tested. This should include the expected behavior and any inputs or assumptions that should yield this behavior. Some example test names:
Someteamsfindthesecondnamingapproachclearer, thoughslightlymoreverbose. Inanycase, trytouseanamingconventionthatprovidesinsightintotestbehavior, sothatwhenoneormoretestsfail, it's obvious from their names what cases have failed. Avoid naming you tests vaguely, such as ControllerTests.Test1, as these offer no value when you see them in test results.
118
119
@@ -167,19 +168,7 @@ The \_logger and \_imageService are both injected as dependencies. Now you can t
Totestthatthisserviceworkscorrectly, youneedtocreateaknowntestimagefileandverifythattheservicereturnsitgivenaspecificinput. Youshouldtakecarenottousemockobjectsonthebehavioryouactuallywanttotest (inthiscase, readingfromthefilesystem). However, mockobjectsmaystillbeusefultosetupintegrationtests. Inthiscase, youcanmockIHostingEnvironmentsothatitsContentRootPathpointstothefolderyou're going to use for your test image. The complete working integration test class is shown here:
171
+
TotestthataLocalFileImageServiceworkscorrectlyusinganintegraitontest, youneedtocreateaknowntestimagefileandverifythattheservicereturnsitgivenaspecificinput. Youshouldtakecarenottousemockobjectsonthebehavioryouactuallywanttotest (inthiscase, readingfromthefilesystem). However, mockobjectsmaystillbeusefultosetupintegrationtests. Inthiscase, youcanmockIHostingEnvironmentsothatitsContentRootPathpointstothefolderyou're going to use for your test image. The complete working integration test class is shown here:
183
172
184
173
```cs
185
174
publicclassLocalFileImageServiceGetImageBytesById
@@ -188,6 +177,7 @@ public class LocalFileImageServiceGetImageBytesById
ForASP.NETCoreapplications, theTestServerclassmakesfunctionaltestsfairlyeasytowrite. YouconfigureaTestServerusingaWebHostBuilder, justasyounormallydoforyourapplication. ThisWebHostBuildershouldbeconfiguredjustlikeyourapplication's real host, but you can modify any aspects of it that make testing easier. Most of the time, you'llreusethesameTestServerformanytestcases, soyoucanencapsulateitinareusablemethod (perhapsinabaseclass):
225
216
217
+
WIP: Updatefor2.1
218
+
226
219
```cs
227
220
publicabstractclassBaseWebTest
228
221
{
@@ -233,7 +226,7 @@ public abstract class BaseWebTest
0 commit comments