From 601d1837616492197edf4b561bb0639242a9b5c7 Mon Sep 17 00:00:00 2001 From: Joe Sewell Date: Tue, 12 Jun 2018 14:02:15 -0400 Subject: [PATCH 1/5] Remove paragraph about ambiguous grammar (#5905) --- docs/csharp/language-reference/operators/invocation-operator.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/csharp/language-reference/operators/invocation-operator.md b/docs/csharp/language-reference/operators/invocation-operator.md index c3c47212b89b4..b625b7efd3a6b 100644 --- a/docs/csharp/language-reference/operators/invocation-operator.md +++ b/docs/csharp/language-reference/operators/invocation-operator.md @@ -27,8 +27,6 @@ In addition to being used to specify the order of operations in an expression, p For more information, see [Casting and Type Conversions](../../../csharp/programming-guide/types/casting-and-type-conversions.md). - A cast expression could lead to ambiguous syntax. For example, the expression `(x)–y` could be either interpreted as a cast expression (a cast of –y to type x) or as an additive expression combined with a parenthesized expression, which computes the value x – y. - For more information about method invocation, see [Methods](../../../csharp/programming-guide/classes-and-structs/methods.md). ## C# Language Specification From c338c4e0654755979401d6240f0518cdb74722f2 Mon Sep 17 00:00:00 2001 From: factormystic Date: Tue, 12 Jun 2018 14:16:40 -0400 Subject: [PATCH 2/5] Reword opening sentence for readability (#5921) --- docs/standard/security/vulnerabilities-cbc-mode.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/standard/security/vulnerabilities-cbc-mode.md b/docs/standard/security/vulnerabilities-cbc-mode.md index 9fd2aa824f8c2..9a9e6d3e06dc5 100644 --- a/docs/standard/security/vulnerabilities-cbc-mode.md +++ b/docs/standard/security/vulnerabilities-cbc-mode.md @@ -7,8 +7,7 @@ ms.author: "mairaw" --- # Timing vulnerabilities with CBC-mode symmetric decryption using padding -Microsoft, based on currently known cryptographic research, believes that, except for very specific circumstances, it's no longer safe to -decrypt data encrypted with the Cipher-Block-Chaining (CBC) mode of symmetric encryption when verifiable padding has been applied without first ensuring the integrity of the ciphertext. +Microsoft believes that it's no longer safe to decrypt data encrypted with the Cipher-Block-Chaining (CBC) mode of symmetric encryption when verifiable padding has been applied without first ensuring the integrity of the ciphertext, except for very specific circumstances. This judgement is based on currently known cryptographic research. ## Introduction From 19884895892d4e382283fbdf1e887858a2719491 Mon Sep 17 00:00:00 2001 From: Roman Pavlov Date: Tue, 12 Jun 2018 23:44:14 +0300 Subject: [PATCH 3/5] Fix code blocks (#5907) * fixed code block * replaced HTML entities --- .../test-asp-net-core-mvc-apps.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md b/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md index 09b8859b1bba5..e146648e5f6d5 100644 --- a/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md +++ b/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md @@ -47,6 +47,13 @@ public class LocalFileImageService : IImageService var contentRoot = _env.ContentRootPath + "//Pics"; var path = Path.Combine(contentRoot, id + ".png"); return File.ReadAllBytes(path); + } + catch (FileNotFoundException ex) + { + throw new CatalogImageMissingException(ex); + } + } +} ``` ### Functional Tests @@ -162,16 +169,6 @@ The \_logger and \_imageService are both injected as dependencies. Now you can t ## Integration Testing ASP.NET Core Apps -```cs - } - catch (FileNotFoundException ex) - { - throw new CatalogImageMissingException(ex); - } - } -} -``` - This service uses the IHostingEnvironment, just as the CatalogController code did before it was refactored into a separate service. Since this was the only code in the controller that used IHostingEnvironment, that dependency was removed from CatalogController's constructor. To test that this service works correctly, you need to create a known test image file and verify that the service returns it given a specific input. You should take care not to use mock objects on the behavior you actually want to test (in this case, reading from the file system). However, mock objects may still be useful to set up integration tests. In this case, you can mock IHostingEnvironment so that its ContentRootPath points to the folder you're going to use for your test image. The complete working integration test class is shown here: @@ -235,7 +232,7 @@ public abstract class BaseWebTest _contentRoot = GetProjectPath("src", startupAssembly); var builder = new WebHostBuilder() .UseContentRoot(_contentRoot) - .UseStartup<Startup>(); + .UseStartup(); var server = new TestServer(builder); var client = server.CreateClient(); return client; From 1dc68e2d957b78e95fdf46ad29d26efc9171628b Mon Sep 17 00:00:00 2001 From: Maira Wenzel Date: Tue, 12 Jun 2018 14:34:46 -0700 Subject: [PATCH 4/5] fix formatting (#5909) --- .../test-asp-net-core-mvc-apps.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md b/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md index e146648e5f6d5..dfac8a43ad93a 100644 --- a/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md +++ b/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md @@ -8,7 +8,7 @@ ms.date: 10/08/2017 # Test ASP.NET Core MVC Apps > _"If you don't like unit testing your product, most likely your customers won't like to test it, either."_ -> _- Anonymous- +> _- Anonymous-_ ## Summary @@ -32,7 +32,7 @@ Integration tests will often have more complex setup and teardown procedures tha The LocalFileImageService implementation class implements the logic for fetching and returning the bytes of an image file from a particular folder given an id: -```cs +```csharp public class LocalFileImageService : IImageService { private readonly IHostingEnvironment _env; @@ -102,19 +102,19 @@ Figure 9-3 Add an xUnit Test Project in Visual Studio You should name your tests in a consistent fashion, with names that indicate what each test does. One approach I'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: -- CatalogControllerGetImage.CallsImageServiceWithId +- CatalogControllerGetImage.CallsImageServiceWithId -- CatalogControllerGetImage.LogsWarningGivenImageMissingException +- CatalogControllerGetImage.LogsWarningGivenImageMissingException -- CatalogControllerGetImage.ReturnsFileResultWithBytesGivenSuccess +- CatalogControllerGetImage.ReturnsFileResultWithBytesGivenSuccess -- CatalogControllerGetImage.ReturnsNotFoundResultGivenImageMissingException +- CatalogControllerGetImage.ReturnsNotFoundResultGivenImageMissingException A variation of this approach ends each test class name with "Should" and modifies the tense slightly: -- CatalogControllerGetImage**Should**.**Call**ImageServiceWithId +- CatalogControllerGetImage**Should**.**Call**ImageServiceWithId -- CatalogControllerGetImage**Should**.**Log**WarningGivenImageMissingException +- CatalogControllerGetImage**Should**.**Log**WarningGivenImageMissingException Some teams find the second naming approach clearer, though slightly more verbose. In any case, try to use a naming convention that provides insight into test behavior, so that when one or more tests fail, 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. @@ -132,7 +132,7 @@ In a well-designed ASP.NET Core application, most of the complexity and business Sometimes you'll need to refactor your code in order to unit test it. Frequently this involves identifying abstractions and using dependency injection to access the abstraction in the code you'd like to test, rather than coding directly against infrastructure. For example, consider this simple action method for displaying images: -```cs +```csharp [HttpGet("[controller]/pic/{id}")] public IActionResult GetImage(int id) { @@ -147,7 +147,7 @@ Unit testing this method is made difficult by its direct dependency on System.IO If you can't unit test the file system behavior directly, and you can't test the route, what is there to test? Well, after refactoring to make unit testing possible, you may discover some test cases and missing behavior, such as error handling. What does the method do when a file isn't found? What should it do? In this example, the refactored method looks like this: -```cs +```csharp [HttpGet("[controller]/pic/{id}")\] public IActionResult GetImage(int id) { @@ -173,7 +173,7 @@ This service uses the IHostingEnvironment, just as the CatalogController code di To test that this service works correctly, you need to create a known test image file and verify that the service returns it given a specific input. You should take care not to use mock objects on the behavior you actually want to test (in this case, reading from the file system). However, mock objects may still be useful to set up integration tests. In this case, you can mock IHostingEnvironment so that its ContentRootPath points to the folder you're going to use for your test image. The complete working integration test class is shown here: -```cs +```csharp public class LocalFileImageServiceGetImageBytesById { private byte[] _testBytes = new byte[] { 0x01, 0x02, 0x03 }; @@ -215,7 +215,7 @@ public class LocalFileImageServiceGetImageBytesById For ASP.NET Core applications, the TestServer class makes functional tests fairly easy to write. You configure a TestServer using a WebHostBuilder, just as you normally do for your application. This WebHostBuilder should be configured just like your application's real host, but you can modify any aspects of it that make testing easier. Most of the time, you'll reuse the same TestServer for many test cases, so you can encapsulate it in a reusable method (perhaps in a base class): -```cs +```csharp public abstract class BaseWebTest { protected readonly HttpClient _client; @@ -225,7 +225,7 @@ public abstract class BaseWebTest { _client = GetClient(); } - + protected HttpClient GetClient() { var startupAssembly = typeof(Startup).GetTypeInfo().Assembly; @@ -242,7 +242,7 @@ public abstract class BaseWebTest The GetProjectPath method simply returns the physical path to the web project (download sample solution). The WebHostBuilder in this case simply specifies where the content root for the web application is, and references the same Startup class the real web application uses. To work with the TestServer, you use the standard System.Net.HttpClient type to make requests to it. TestServer exposes a helpful CreateClient method that provides a pre-configured client that is ready to make requests to the application running on the TestServer. You use this client (set to the protected \_client member on the base test above) when writing functional tests for your ASP.NET Core application: -```cs +```csharp public class CatalogControllerGetImage : BaseWebTest { [Fact] From 39a49c63acb9d5756cd24619b38bdac70510a2fc Mon Sep 17 00:00:00 2001 From: Roman Pavlov Date: Wed, 13 Jun 2018 00:37:12 +0300 Subject: [PATCH 5/5] fixed misplaced curly brace (#5925) --- .../test-asp-net-core-mvc-apps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md b/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md index dfac8a43ad93a..a440eb6883d39 100644 --- a/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md +++ b/docs/standard/modern-web-apps-azure-architecture/test-asp-net-core-mvc-apps.md @@ -47,7 +47,7 @@ public class LocalFileImageService : IImageService var contentRoot = _env.ContentRootPath + "//Pics"; var path = Path.Combine(contentRoot, id + ".png"); return File.ReadAllBytes(path); - } + } catch (FileNotFoundException ex) { throw new CatalogImageMissingException(ex);