diff --git a/src/Authentication/Authentication.Test/Helpers/GraphSessionTests.cs b/src/Authentication/Authentication.Test/Helpers/GraphSessionTests.cs index 6f165d9d568..2bb665e8ee8 100644 --- a/src/Authentication/Authentication.Test/Helpers/GraphSessionTests.cs +++ b/src/Authentication/Authentication.Test/Helpers/GraphSessionTests.cs @@ -38,14 +38,24 @@ public void ShouldNotOverwriteExistingGraphSession() GraphSession.Initialize(() => new GraphSession()); Guid originalSessionId = GraphSession.Instance._graphSessionId; - InvalidOperationException exception = Assert.Throws(() => GraphSession.Initialize(() => new GraphSession())); + GraphSession.Initialize(() => new GraphSession()); - Assert.Equal("An instance of GraphSession already exists. Call Initialize(Func, bool) to overwrite it.", exception.Message); Assert.NotNull(GraphSession.Instance); Assert.Equal(originalSessionId, GraphSession.Instance._graphSessionId); // reset static instance. GraphSession.Reset(); } + + [Fact] + public void ShouldThrowExceptionWhenSessionIsNotInitialized() + { + InvalidOperationException exception = Assert.Throws(() => GraphSession.Instance); + + Assert.Equal(ErrorConstants.Codes.SessionNotInitialized, exception.Message); + + // reset static instance. + GraphSession.Reset(); + } } } diff --git a/src/Authentication/Authentication/Common/GraphSession.cs b/src/Authentication/Authentication/Common/GraphSession.cs index e86d7157f5f..26a77ba2d42 100644 --- a/src/Authentication/Authentication/Common/GraphSession.cs +++ b/src/Authentication/Authentication/Common/GraphSession.cs @@ -93,10 +93,6 @@ public static void Initialize(Func instanceCreator, bool overwrite _instance = instanceCreator(); _initialized = true; } - else - { - throw new InvalidOperationException(string.Format(ErrorConstants.Message.InstanceExists, nameof(GraphSession), "Initialize(Func, bool)")); - } } finally { diff --git a/src/Authentication/Authentication/ErrorConstants.cs b/src/Authentication/Authentication/ErrorConstants.cs index 88bf163e50b..50575b97efc 100644 --- a/src/Authentication/Authentication/ErrorConstants.cs +++ b/src/Authentication/Authentication/ErrorConstants.cs @@ -19,7 +19,6 @@ internal static class Message { internal const string InvalidJWT = "Invalid JWT access token."; internal const string MissingAuthContext = "Authentication needed, call Connect-Graph."; - internal const string InstanceExists = "An instance of {0} already exists. Call {1} to overwrite it."; internal const string NullOrEmptyParameter = "Parameter '{0}' cannot be null or empty."; internal const string MacKeyChainFailed = "{0} failed with result code {1}."; }