Skip to content

Commit 92af15c

Browse files
Fix error when session timeout is not specified at CloudServices.dev.config (#610)
* Fix error introduced at #442 when session timeout is not specified at CloudServices.dev.config. * Isolate test for Redis and CloudServices.dev.config so it does not affect the rest of the tests. * Remove unneeded project properties at DotNetRedisTest.csproj.
1 parent 5e97036 commit 92af15c

File tree

6 files changed

+87
-5
lines changed

6 files changed

+87
-5
lines changed

dotnet/DotNetStandardClasses.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneXus.Programs.Common", "
202202
EndProject
203203
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "apiattractions", "src\extensions\Azure\test\apiattractions\apiattractions.csproj", "{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}"
204204
EndProject
205+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetRedisTest", "test\DotNetRedisTest\DotNetRedisTest.csproj", "{48430E50-043A-47A2-8278-B86A4420758A}"
206+
EndProject
205207
Global
206208
GlobalSection(SolutionConfigurationPlatforms) = preSolution
207209
Debug|Any CPU = Debug|Any CPU
@@ -492,6 +494,10 @@ Global
492494
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
493495
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
494496
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Release|Any CPU.Build.0 = Release|Any CPU
497+
{48430E50-043A-47A2-8278-B86A4420758A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
498+
{48430E50-043A-47A2-8278-B86A4420758A}.Debug|Any CPU.Build.0 = Debug|Any CPU
499+
{48430E50-043A-47A2-8278-B86A4420758A}.Release|Any CPU.ActiveCfg = Release|Any CPU
500+
{48430E50-043A-47A2-8278-B86A4420758A}.Release|Any CPU.Build.0 = Release|Any CPU
495501
EndGlobalSection
496502
GlobalSection(SolutionProperties) = preSolution
497503
HideSolutionNode = FALSE
@@ -589,6 +595,7 @@ Global
589595
{B01A243D-C012-4BEB-BAA9-E1D9AC1468C8} = {C16BD5A9-4412-4B91-BB70-5C88B7AAE675}
590596
{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163} = {7BA5A2CE-7992-4F87-9D84-91AE4D046F5A}
591597
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3} = {7BA5A2CE-7992-4F87-9D84-91AE4D046F5A}
598+
{48430E50-043A-47A2-8278-B86A4420758A} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
592599
EndGlobalSection
593600
GlobalSection(ExtensibilityGlobals) = postSolution
594601
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}

dotnet/src/dotnetcore/GxClasses/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
[assembly: InternalsVisibleTo("GxClasses.Web")]
55
[assembly: InternalsVisibleTo("GxSearch")]
6-
[assembly: InternalsVisibleTo("GxNetCoreStartup")]
6+
[assembly: InternalsVisibleTo("GxNetCoreStartup")]
7+

dotnet/src/dotnetcore/GxClasses/Services/Session/GXSessionFactory.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,32 @@ public class GXSessionServiceFactory
1818
static string SESSION_TIMEOUT = "SESSION_PROVIDER_SESSION_TIMEOUT";
1919
public static ISessionService GetProvider()
2020
{
21-
var instance = GXServices.Instance?.Get(GXServices.SESSION_SERVICE);
21+
GXService instance = GXServices.Instance?.Get(GXServices.SESSION_SERVICE);
2222
if (instance != null)
2323
{
24+
string password = instance.Properties.Get(SESSION_PASSWORD);
25+
if (!string.IsNullOrEmpty(password))
26+
{
27+
password = CryptoImpl.Decrypt(password);
28+
}
2429
if (instance.Name.Equals(REDIS, StringComparison.OrdinalIgnoreCase))
2530
{
26-
return new GxRedisSession(instance.Properties.Get(SESSION_ADDRESS), CryptoImpl.Decrypt(instance.Properties.Get(SESSION_PASSWORD)), instance.Properties.Get(SESSION_INSTANCE), int.Parse(instance.Properties.Get(SESSION_TIMEOUT)));
31+
string sessionTimeout = instance.Properties.Get(SESSION_TIMEOUT);
32+
int timeout=0;
33+
if (!string.IsNullOrEmpty(sessionTimeout))
34+
int.TryParse(sessionTimeout, out timeout);
35+
36+
return new GxRedisSession(instance.Properties.Get(SESSION_ADDRESS),
37+
password,
38+
instance.Properties.Get(SESSION_INSTANCE),
39+
timeout);
2740
}
2841
else if (instance.Name.Equals(DATABASE, StringComparison.OrdinalIgnoreCase))
2942
{
30-
return new GxDatabaseSession(instance.Properties.Get(SESSION_ADDRESS), CryptoImpl.Decrypt(instance.Properties.Get(SESSION_PASSWORD))
31-
,instance.Properties.Get(SESSION_SCHEMA), instance.Properties.Get(SESSION_TABLE_NAME));
43+
return new GxDatabaseSession(instance.Properties.Get(SESSION_ADDRESS),
44+
password,
45+
instance.Properties.Get(SESSION_SCHEMA),
46+
instance.Properties.Get(SESSION_TABLE_NAME));
3247
}
3348
}
3449
return null;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Services>
2+
<Service>
3+
<Name>REDIS</Name>
4+
<Type>Session</Type>
5+
<ClassName></ClassName>
6+
<Properties>
7+
<Property>
8+
<Name>SESSION_PROVIDER_ADDRESS</Name>
9+
<Value>localhost:6379</Value>
10+
</Property>
11+
</Properties>
12+
</Service>
13+
</Services>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
9+
<PackageReference Include="xunit" Version="2.4.1" />
10+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
<PrivateAssets>all</PrivateAssets>
13+
</PackageReference>
14+
<PackageReference Include="coverlet.collector" Version="3.1.0">
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\src\dotnetcore\GxClasses\GxClasses.csproj" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<None Update="CloudServices.dev.config">
26+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27+
</None>
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using GeneXus.Services;
2+
using Xunit;
3+
4+
namespace xUnitTesting
5+
{
6+
public class RedisTest
7+
{
8+
[Fact]
9+
public void TestRedisFromCloudServicesDevConfig()
10+
{
11+
ISessionService session = GXSessionServiceFactory.GetProvider();
12+
Assert.NotNull(session);
13+
Assert.True(session is GxRedisSession);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)