Skip to content

Commit 962b7bd

Browse files
authored
Merge pull request #7993 from v-thpra/update-code-ref-7
Moving sample files and updating code references (part 1) - 7
2 parents 1efbfcf + 6f38418 commit 962b7bd

File tree

50 files changed

+333
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+333
-240
lines changed

docs/test/live-unit-testing-start.md

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,41 @@ Now that you've created the solution, you'll create a class library named String
7676

7777
5. Replace all of the existing code in the code editor with the following code:
7878

79-
[!code-csharp[StringLibrary source code](samples/csharp/utilitylibraries/stringlibrary/class1.cs)]
79+
```csharp
80+
using System;
81+
82+
namespace UtilityLibraries
83+
{
84+
public static class StringLibrary
85+
{
86+
public static bool StartsWithUpper(this string s)
87+
{
88+
if (String.IsNullOrWhiteSpace(s))
89+
return false;
90+
91+
return Char.IsUpper(s[0]);
92+
}
93+
94+
public static bool StartsWithLower(this string s)
95+
{
96+
if (String.IsNullOrWhiteSpace(s))
97+
return false;
98+
99+
return Char.IsLower(s[0]);
100+
}
101+
102+
public static bool HasEmbeddedSpaces(this string s)
103+
{
104+
foreach (var ch in s.Trim())
105+
{
106+
if (ch == ' ')
107+
return true;
108+
}
109+
return false;
110+
}
111+
}
112+
}
113+
```
80114

81115
StringLibrary has three static methods:
82116

@@ -134,7 +168,59 @@ The next step is to create the unit test project to test the StringLibrary libra
134168

135169
6. Replace the boilerplate unit test code provided by the template with the following code:
136170

137-
[!code-csharp[StringLibraryTest source code](samples/snippets/csharp/lut-start/unittest1.cs)]
171+
```csharp
172+
using System;
173+
using Microsoft.VisualStudio.TestTools.UnitTesting;
174+
using UtilityLibraries;
175+
176+
namespace StringLibraryTest
177+
{
178+
[TestClass]
179+
public class UnitTest1
180+
{
181+
[TestMethod]
182+
public void TestStartsWithUpper()
183+
{
184+
// Tests that we expect to return true.
185+
string[] words = { "Alphabet", "Zebra", "ABC", "Αθήνα", "Москва" };
186+
foreach (var word in words)
187+
{
188+
bool result = word.StartsWithUpper();
189+
Assert.IsTrue(result,
190+
$"Expected for '{word}': true; Actual: {result}");
191+
}
192+
}
193+
194+
[TestMethod]
195+
public void TestDoesNotStartWithUpper()
196+
{
197+
// Tests that we expect to return false.
198+
string[] words = { "alphabet", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство",
199+
"1234", ".", ";", " " };
200+
foreach (var word in words)
201+
{
202+
bool result = word.StartsWithUpper();
203+
Assert.IsFalse(result,
204+
$"Expected for '{word}': false; Actual: {result}");
205+
}
206+
}
207+
208+
[TestMethod]
209+
public void DirectCallWithNullOrEmpty()
210+
{
211+
// Tests that we expect to return false.
212+
string[] words = { String.Empty, null };
213+
foreach (var word in words)
214+
{
215+
bool result = StringLibrary.StartsWithUpper(word);
216+
Assert.IsFalse(result,
217+
$"Expected for '{(word == null ? "<null>" : word)}': " +
218+
$"false; Actual: {result}");
219+
}
220+
}
221+
}
222+
}
223+
```
138224

139225
7. Save your project by selecting the **Save** icon on the toolbar.
140226

@@ -193,11 +279,11 @@ To extend code coverage to the `StartsWithLower` method, do the following:
193279

194280
1. Add the following `TestStartsWithLower` and `TestDoesNotStartWithLower` methods to your project's test source code file:
195281

196-
[!code-csharp[StringLibraryTest source code](samples/snippets/csharp/lut-start/unittest2.cs#1)]
282+
:::code language="csharp" source="../test/samples/snippets/csharp/lut-start/unittest2.cs" id="Snippet1":::
197283

198284
1. Modify the `DirectCallWithNullOrEmpty` method by adding the following code immediately after the call to the [`Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse`](/dotnet/api/microsoft.visualstudio.testtools.unittesting.assert.isfalse) method.
199285

200-
[!code-csharp[StringLibraryTest source code](samples/snippets/csharp/lut-start/unittest2.cs#2)]
286+
:::code language="csharp" source="../test/samples/snippets/csharp/lut-start/unittest2.cs" id="Snippet2":::
201287

202288
1. Live Unit Testing automatically executes new and modified tests when you modify your source code. As the following illustration shows, all of the tests, including the two you've added and the one you've modified, have succeeded.
203289

@@ -222,7 +308,7 @@ In this section, you'll explore how you can use Live Unit Testing to identify, t
222308

223309
1. Add the following method to your test file:
224310

225-
[!code-csharp[The TestHasEmbeddedSpaces test method](samples/snippets/csharp/lut-start/unittest2.cs#3)]
311+
:::code language="csharp" source="../test/samples/snippets/csharp/lut-start/unittest2.cs" id="Snippet3":::
226312

227313
1. When the test executes, Live Unit Testing indicates that the `TestHasEmbeddedSpaces` method has failed, as the following illustration shows:
228314

@@ -269,7 +355,7 @@ This provides enough information for a preliminary investigation of the bug. Eit
269355

270356
1. Replace the equality comparison with a call to the <xref:System.Char.IsWhiteSpace%2A?displayProperty=fullName> method:
271357

272-
[!code-csharp[The TestHasEmbeddedSpaces test method](samples/snippets/csharp/lut-start/program2.cs#1)]
358+
:::code language="csharp" source="../test/samples/snippets/csharp/lut-start/program2.cs" id="Snippet1":::
273359

274360
1. Live Unit Testing automatically reruns the failed test method.
275361

docs/vsto/accessing-a-form-region-at-run-time.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ ms.workload:
3232

3333
The following example gets the collection of form regions that appear in the Inspector that currently has focus. This example then accesses a form region in the collection named `formRegion1` and sets the text that appears in a text box to `Hello World`.
3434

35-
[!code-vb[Trin_Outlook_FR_Access#2](../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb#2)]
36-
[!code-csharp[Trin_Outlook_FR_Access#2](../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs#2)]
35+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb" id="Snippet2":::
36+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs" id="Snippet2":::
3737

3838
## Access form regions that appear in a specific Outlook Explorer window
3939
To access all form regions that appear in a specific Outlook Explorer, call the `FormRegions` property of the `Globals` class and pass in an <xref:Microsoft.Office.Interop.Outlook.Explorer> object that represents the Explorer.
4040

4141
The following example gets the collection of form regions that appear in the Explorer that currently has focus. This example then accesses a form region in the collection named `formRegion1` and sets the text that appears in a text box to `Hello World`.
4242

43-
[!code-vb[Trin_Outlook_FR_Access#3](../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb#3)]
44-
[!code-csharp[Trin_Outlook_FR_Access#3](../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs#3)]
43+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb" id="Snippet3":::
44+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs" id="Snippet3":::
4545

4646
## Access all form regions
4747
To access all form regions that appear in all Explorers and all Inspectors, call the `FormRegions` property of the `Globals` class.
4848

4949
The following example gets the collection of form regions that appear in all Explorers and all Inspectors. This example then accesses a form region named `formRegion1` and sets the text that appears in a text box to `Hello World`.
5050

51-
[!code-vb[Trin_Outlook_FR_Access#1](../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb#1)]
52-
[!code-csharp[Trin_Outlook_FR_Access#1](../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs#1)]
51+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb" id="Snippet1":::
52+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs" id="Snippet1":::
5353

5454
## Access controls on a form region
5555
To access controls on a form region by using the `Globals` class, you must make the controls accessible to code outside of the form region code file.

docs/vsto/accessing-data-in-documents-on-the-server.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ ms.workload:
3939

4040
The following code example demonstrates how to access a cached string in the `Sheet1` class of an Excel workbook project. This example is part of a larger example that is provided for the <xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Save%2A> method.
4141

42-
[!code-csharp[Trin_ServerDocument#12](../vsto/codesnippet/CSharp/Trin_ServerDocument/Form1.cs#12)]
43-
[!code-vb[Trin_ServerDocument#12](../vsto/codesnippet/VisualBasic/Trin_ServerDocument/Form1.vb#12)]
42+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_ServerDocument/Form1.cs" id="Snippet12":::
43+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_ServerDocument/Form1.vb" id="Snippet12":::
4444

4545
## Modify data in the cache
4646
To modify a cached data object, you typically perform the following steps:
@@ -60,8 +60,8 @@ ms.workload:
6060

6161
The following code example demonstrates how to change the value of a cached string in the `Sheet1` class of an Excel workbook project. This example is part of a larger example that is provided for the <xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Save%2A> method.
6262

63-
[!code-csharp[Trin_ServerDocument#11](../vsto/codesnippet/CSharp/Trin_ServerDocument/Form1.cs#11)]
64-
[!code-vb[Trin_ServerDocument#11](../vsto/codesnippet/VisualBasic/Trin_ServerDocument/Form1.vb#11)]
63+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_ServerDocument/Form1.cs" id="Snippet11":::
64+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_ServerDocument/Form1.vb" id="Snippet11":::
6565

6666
### Modify null values in the data cache
6767
The data cache does not store objects that have the value **null** when the document is saved and closed. This limitation has several consequences when you modify cached data:

docs/vsto/accessing-the-ribbon-at-run-time.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ ms.workload:
3131

3232
The following example uses the `Globals` class to access a custom Ribbon named `Ribbon1` and set the text that appears on a combo box on the Ribbon to `Hello World`.
3333

34-
[!code-vb[Trin_Outlook_FR_Access#4](../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb#4)]
35-
[!code-csharp[Trin_Outlook_FR_Access#4](../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs#4)]
34+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb" id="Snippet4":::
35+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs" id="Snippet4":::
3636

3737
## Access a collection of Ribbons that appear in a specific Outlook Inspector window
3838
You can access a collection of Ribbons that appear in Outlook *Inspectors*. An Inspector is a window that opens in Outlook when users perform certain tasks, such as creating e-mail messages. To access the Ribbon of an Inspector window, call the `Ribbons` property of the `Globals` class and pass in an <xref:Microsoft.Office.Interop.Outlook.Inspector> object that represents the Inspector.
3939

4040
The following example gets the Ribbon collection of the Inspector that currently has focus. This example then accesses a Ribbon named `Ribbon1` and sets the text that appears on a combo box on the Ribbon to `Hello World`.
4141

42-
[!code-vb[Trin_Outlook_FR_Access#5](../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb#5)]
43-
[!code-csharp[Trin_Outlook_FR_Access#5](../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs#5)]
42+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb" id="Snippet5":::
43+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs" id="Snippet5":::
4444

4545
## Access a collection of Ribbons that appear for a specific Outlook Explorer
4646
You can access a collection of Ribbons that appear in an Outlook *Explorer*. An Explorer is the main application user interface (UI) for an instance of Outlook. To access the Ribbon of an Explorer window, call the `Ribbons` property of the `Globals` class and pass in an <xref:Microsoft.Office.Interop.Outlook.Explorer> object that represents the Explorer.
4747

4848
The following example gets the Ribbon collection of the Explorer that currently has focus. This example then accesses a Ribbon named `Ribbon1` and sets the text that appears on a combo box on the Ribbon to `Hello World`.
4949

50-
[!code-vb[Trin_Outlook_FR_Access#6](../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb#6)]
51-
[!code-csharp[Trin_Outlook_FR_Access#6](../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs#6)]
50+
:::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_Outlook_FR_Access_O12/ThisAddIn.vb" id="Snippet6":::
51+
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_Outlook_FR_Access_O12/ThisAddIn.cs" id="Snippet6":::
5252

5353
## See also
5454
- [Ribbon overview](../vsto/ribbon-overview.md)

0 commit comments

Comments
 (0)