Skip to content

Commit 3509ad0

Browse files
authored
Merge pull request #291 from microsoftgraph/po/multiThreadSessionSupport
Multi-thread GraphSession support
2 parents fecfaf3 + e4eefa3 commit 3509ad0

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/Authentication/Authentication.Test/Helpers/GraphSessionTests.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,24 @@ public void ShouldNotOverwriteExistingGraphSession()
3838
GraphSession.Initialize(() => new GraphSession());
3939
Guid originalSessionId = GraphSession.Instance._graphSessionId;
4040

41-
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => GraphSession.Initialize(() => new GraphSession()));
41+
GraphSession.Initialize(() => new GraphSession());
4242

43-
Assert.Equal("An instance of GraphSession already exists. Call Initialize(Func<GraphSession>, bool) to overwrite it.", exception.Message);
4443
Assert.NotNull(GraphSession.Instance);
4544
Assert.Equal(originalSessionId, GraphSession.Instance._graphSessionId);
4645

4746
// reset static instance.
4847
GraphSession.Reset();
4948
}
49+
50+
[Fact]
51+
public void ShouldThrowExceptionWhenSessionIsNotInitialized()
52+
{
53+
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => GraphSession.Instance);
54+
55+
Assert.Equal(ErrorConstants.Codes.SessionNotInitialized, exception.Message);
56+
57+
// reset static instance.
58+
GraphSession.Reset();
59+
}
5060
}
5161
}

src/Authentication/Authentication/Common/GraphSession.cs

-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ public static void Initialize(Func<GraphSession> instanceCreator, bool overwrite
9393
_instance = instanceCreator();
9494
_initialized = true;
9595
}
96-
else
97-
{
98-
throw new InvalidOperationException(string.Format(ErrorConstants.Message.InstanceExists, nameof(GraphSession), "Initialize(Func<GraphSession>, bool)"));
99-
}
10096
}
10197
finally
10298
{

src/Authentication/Authentication/ErrorConstants.cs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ internal static class Message
1919
{
2020
internal const string InvalidJWT = "Invalid JWT access token.";
2121
internal const string MissingAuthContext = "Authentication needed, call Connect-Graph.";
22-
internal const string InstanceExists = "An instance of {0} already exists. Call {1} to overwrite it.";
2322
internal const string NullOrEmptyParameter = "Parameter '{0}' cannot be null or empty.";
2423
internal const string MacKeyChainFailed = "{0} failed with result code {1}.";
2524
}

0 commit comments

Comments
 (0)