Skip to content

Commit 81c49b5

Browse files
committed
Revert "removed duplicated code snippets"
This reverts commit c3fd4bd.
1 parent c3fd4bd commit 81c49b5

File tree

13 files changed

+182
-6
lines changed

13 files changed

+182
-6
lines changed

docs/core/tutorials/library-with-visual-studio-code.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Start by creating a .NET class library project named "StringLibrary" and an asso
5555

5656
1. Open *Class1.cs* and replace the code with the following code.
5757

58-
:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs":::
58+
:::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/StringLibrary/Class1.cs":::
5959

6060
The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a <xref:System.Boolean> value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The <xref:System.Char.IsUpper(System.Char)?displayProperty=nameWithType> method returns `true` if a character is uppercase.
6161

@@ -93,7 +93,7 @@ Add a console application that uses the class library. The app will prompt the u
9393

9494
1. Open *ShowCase/Program.cs* and replace all of the code with the following code.
9595

96-
:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/ShowCase/Program.cs":::
96+
:::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/ShowCase/Program.cs":::
9797

9898
The code uses the `row` variable to maintain a count of the number of rows of data written to the console window. Whenever it's greater than or equal to 25, the code clears the console window and displays a message to the user.
9999

docs/core/tutorials/library-with-visual-studio.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ To create the blank solution:
5959

6060
1. Replace the code in the code window for *Class1.cs* or *Class1.vb* with the following code, and save the file. If the language you want to use isn't shown, change the language selector at the top of the page.
6161

62-
:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/StringLibrary/Class1.cs":::
62+
:::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/StringLibrary/Class1.cs":::
6363
:::code language="vb" source="./snippets/library-with-visual-studio/vb/StringLibrary/Class1.vb":::
6464

6565
The class library, `UtilityLibraries.StringLibrary`, contains a method named `StartsWithUpper`. This method returns a <xref:System.Boolean> value that indicates whether the current string instance begins with an uppercase character. The Unicode standard distinguishes uppercase characters from lowercase characters. The <xref:System.Char.IsUpper(System.Char)?displayProperty=nameWithType> method returns `true` if a character is uppercase.
@@ -86,7 +86,7 @@ Add a console application that uses the class library. The app will prompt the u
8686

8787
1. In the code window for the *Program.cs* or *Program.vb* file, replace all of the code with the following code.
8888

89-
:::code language="csharp" source="./snippets/library-with-visual-studio/csharp/ShowCase/Program.cs":::
89+
:::code language="csharp" source="./snippets/library-with-visual-studio-6-0/csharp/ShowCase/Program.cs":::
9090
:::code language="vb" source="./snippets/library-with-visual-studio/vb/ShowCase/Program.vb":::
9191

9292
The code uses the `row` variable to maintain a count of the number of rows of data written to the console window. Whenever it's greater than or equal to 25, the code clears the console window and displays a message to the user.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using UtilityLibraries;
2+
3+
class Program
4+
{
5+
static void Main(string[] args)
6+
{
7+
int row = 0;
8+
9+
do
10+
{
11+
if (row == 0 || row >= 25)
12+
ResetConsole();
13+
14+
string? input = Console.ReadLine();
15+
if (string.IsNullOrEmpty(input)) break;
16+
Console.WriteLine($"Input: {input}");
17+
Console.WriteLine("Begins with uppercase? " +
18+
$"{(input.StartsWithUpper() ? "Yes" : "No")}");
19+
Console.WriteLine();
20+
row += 4;
21+
} while (true);
22+
return;
23+
24+
// Declare a ResetConsole local method
25+
void ResetConsole()
26+
{
27+
if (row > 0)
28+
{
29+
Console.WriteLine("Press any key to continue...");
30+
Console.ReadKey();
31+
}
32+
Console.Clear();
33+
Console.WriteLine($"{Environment.NewLine}Press <Enter> only to exit; otherwise, enter a string and press <Enter>:{Environment.NewLine}");
34+
row = 3;
35+
}
36+
}
37+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\StringLibrary\StringLibrary.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace UtilityLibraries;
2+
3+
public static class StringLibrary
4+
{
5+
public static bool StartsWithUpper(this string? str)
6+
{
7+
if (string.IsNullOrWhiteSpace(str))
8+
return false;
9+
10+
char ch = str[0];
11+
return char.IsUpper(ch);
12+
}
13+
}
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
13+
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
14+
<PackageReference Include="coverlet.collector" Version="6.0.2" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\StringLibrary\StringLibrary.csproj" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using UtilityLibraries;
3+
4+
namespace StringLibraryTest;
5+
6+
[TestClass]
7+
public class UnitTest1
8+
{
9+
[TestMethod]
10+
public void TestStartsWithUpper()
11+
{
12+
// Tests that we expect to return true.
13+
string[] words = { "Alphabet", "Zebra", "ABC", "Αθήνα", "Москва" };
14+
foreach (var word in words)
15+
{
16+
bool result = word.StartsWithUpper();
17+
Assert.IsTrue(result,
18+
string.Format("Expected for '{0}': true; Actual: {1}",
19+
word, result));
20+
}
21+
}
22+
23+
[TestMethod]
24+
public void TestDoesNotStartWithUpper()
25+
{
26+
// Tests that we expect to return false.
27+
string[] words = { "alphabet", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство",
28+
"1234", ".", ";", " " };
29+
foreach (var word in words)
30+
{
31+
bool result = word.StartsWithUpper();
32+
Assert.IsFalse(result,
33+
string.Format("Expected for '{0}': false; Actual: {1}",
34+
word, result));
35+
}
36+
}
37+
38+
[TestMethod]
39+
public void DirectCallWithNullOrEmpty()
40+
{
41+
// Tests that we expect to return false.
42+
string?[] words = { string.Empty, null };
43+
foreach (var word in words)
44+
{
45+
bool result = StringLibrary.StartsWithUpper(word);
46+
Assert.IsFalse(result,
47+
string.Format("Expected for '{0}': false; Actual: {1}",
48+
word == null ? "<null>" : word, result));
49+
}
50+
}
51+
}
52+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace HelloWorld;
2+
3+
public class HelloWorld
4+
{
5+
public static void Main(string[] args)
6+
{
7+
// <MainMethod>
8+
Console.WriteLine("What is your name?");
9+
var name = Console.ReadLine();
10+
var currentDate = DateTime.Now;
11+
Console.WriteLine($"{Environment.NewLine}Hello, {name}, on {currentDate:d} at {currentDate:t}!");
12+
Console.Write($"{Environment.NewLine}Press any key to exit...");
13+
Console.ReadKey(true);
14+
// </MainMethod>
15+
}
16+
}

0 commit comments

Comments
 (0)