Skip to content

Commit b936840

Browse files
Simple documentation examples as test cases (#114)
* Added a test project for documentation examples * Added a gitignore file. * add TargetFrameworks to Doc.csproj * add <LangVersion>latest</LangVersion> --------- Co-authored-by: David Maier <[email protected]> Co-authored-by: shacharPash <[email protected]> Co-authored-by: shacharPash <[email protected]>
1 parent ccae59f commit b936840

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

NRedisStack.sln

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRedisStack", "src\NRedisSt
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRedisStack.Tests", "tests\NRedisStack.Tests\NRedisStack.Tests.csproj", "{73B56C35-BC92-4ACD-B077-7D55CD67B95F}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Doc", "tests\Doc\Doc.csproj", "{F14F6342-14A0-4DDD-AB05-C425B1AD8001}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -24,5 +26,9 @@ Global
2426
{73B56C35-BC92-4ACD-B077-7D55CD67B95F}.Debug|Any CPU.Build.0 = Debug|Any CPU
2527
{73B56C35-BC92-4ACD-B077-7D55CD67B95F}.Release|Any CPU.ActiveCfg = Release|Any CPU
2628
{73B56C35-BC92-4ACD-B077-7D55CD67B95F}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{F14F6342-14A0-4DDD-AB05-C425B1AD8001}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{F14F6342-14A0-4DDD-AB05-C425B1AD8001}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{F14F6342-14A0-4DDD-AB05-C425B1AD8001}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{F14F6342-14A0-4DDD-AB05-C425B1AD8001}.Release|Any CPU.Build.0 = Release|Any CPU
2733
EndGlobalSection
2834
EndGlobal

tests/Doc/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin/
2+
obj/
3+
Doc.sln
4+
.DS_Store

tests/Doc/Doc.csproj

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsWindows>$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_Windows())))</IsWindows>
5+
<TargetFrameworks Condition=" '$(IsWindows)' == 'true'">net6.0;net7.0;net481</TargetFrameworks>
6+
<TargetFrameworks Condition=" '$(IsWindows)' != 'true'">net6.0;net7.0</TargetFrameworks>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<LangVersion>latest</LangVersion>
10+
11+
12+
<IsPackable>false</IsPackable>
13+
<OutputType>Module</OutputType>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
18+
<PackageReference Include="xunit" Version="2.4.2" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
<PrivateAssets>all</PrivateAssets>
22+
</PackageReference>
23+
<PackageReference Include="StackExchange.Redis" Version="2.6.104" />
24+
</ItemGroup>
25+
26+
</Project>

tests/Doc/SetGetExample.cs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// EXAMPLE: set_and_get
2+
// HIDE_START
3+
using System;
4+
using StackExchange.Redis;
5+
6+
namespace NRedisStack.Doc;
7+
8+
public class SetGetExample
9+
{
10+
[Fact]
11+
public void run()
12+
{
13+
var redis = ConnectionMultiplexer.Connect("localhost:6379");
14+
var db = redis.GetDatabase();
15+
16+
//HIDE_END
17+
bool status = db.StringSet("bike:1", "Process 134");
18+
19+
if (status)
20+
Console.WriteLine("Successfully added a bike.");
21+
22+
var value = db.StringGet("bike:1");
23+
24+
if (value.HasValue)
25+
Console.WriteLine("The name of the bike is: " + value + ".");
26+
27+
//REMOVE_START
28+
Assert.True(status);
29+
Assert.Equal("Process 134", value.ToString());
30+
//REMOVE_END
31+
//HIDE_START
32+
}
33+
}
34+
//HIDE_END

tests/Doc/Usings.cs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global using Xunit;
2+
global using Xunit.Abstractions;
3+

0 commit comments

Comments
 (0)