From d7ee8dd7a14c4c17e12ef4fb4f750990b66be62d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 02:06:16 +0000 Subject: [PATCH 1/4] fix(deps): bump NUnit from 3.14.0 to 4.0.1 Bumps [NUnit](https://github.com/nunit/nunit) from 3.14.0 to 4.0.1. - [Release notes](https://github.com/nunit/nunit/releases) - [Changelog](https://github.com/nunit/nunit/blob/master/CHANGES.md) - [Commits](https://github.com/nunit/nunit/compare/v3.14.0...v4.0.1) --- updated-dependencies: - dependency-name: NUnit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- tests/FactSet.SDK.Utils.Tests/FactSet.SDK.Utils.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FactSet.SDK.Utils.Tests/FactSet.SDK.Utils.Tests.csproj b/tests/FactSet.SDK.Utils.Tests/FactSet.SDK.Utils.Tests.csproj index 1175d46..409b957 100644 --- a/tests/FactSet.SDK.Utils.Tests/FactSet.SDK.Utils.Tests.csproj +++ b/tests/FactSet.SDK.Utils.Tests/FactSet.SDK.Utils.Tests.csproj @@ -9,7 +9,7 @@ - + From d4f38aa0e1169d03eb03d0f59111002a23a2a3d5 Mon Sep 17 00:00:00 2001 From: Granit Dula Date: Wed, 27 Dec 2023 17:23:20 +0000 Subject: [PATCH 2/4] refactor: adjusted tests for breaking change in NUnit --- .../Authentication/ConfidentialClientTests.cs | 140 +++++++++--------- .../Authentication/ConfigurationTests.cs | 84 +++++------ .../Authentication/ExceptionsTests.cs | 78 +++++----- .../Authentication/OAuth2ClientTests.cs | 2 +- 4 files changed, 151 insertions(+), 153 deletions(-) diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs index c5c8d9b..dc0b96e 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs @@ -36,7 +36,7 @@ public async Task CreateAsync_PassNullPath_ThrowsArgumentNullException() } catch (Exception e) { - Assert.AreEqual("Value cannot be null. (Parameter 'configPath')", e.Message); + Assert.That("Value cannot be null. (Parameter 'configPath')", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } @@ -50,11 +50,11 @@ public async Task CreateAsync_PassingExplicitNull_ThrowsArgumentNullException() } catch (Exception e) { - Assert.AreEqual("Value cannot be null. (Parameter 'config')", e.Message); + Assert.That("Value cannot be null. (Parameter 'config')", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidConfig_ThrowsArgumentException() { @@ -67,11 +67,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual("'clientId' cannot be null or empty.", e.Message); + Assert.That("'clientId' cannot be null or empty.", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidConfigPath_ThrowsDirectoryNotFoundException() { @@ -81,7 +81,7 @@ await ConfidentialClient.CreateAsync( "somemoretests.txt", httpClient: _testHttpClientEmptyRes ); - + // Should fail if no exception is thrown, since that file does not exist. Assert.Fail(); } @@ -90,7 +90,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathNonJsonConfig_ThrowsConfigurationException() { @@ -103,11 +103,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"Exception caught when retrieving contents of {Path.Join(_resourcesPath, "badJson.txt")}", e.Message); + Assert.That($"Exception caught when retrieving contents of {Path.Join(_resourcesPath, "badJson.txt")}", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathInvalidConfig_ThrowsArgumentException() { @@ -120,11 +120,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"'clientId' cannot be null or empty.", e.Message); + Assert.That($"'clientId' cannot be null or empty.", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingMissingJwk_ThrowsArgumentException() { @@ -137,11 +137,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"'jwk' cannot be null.", e.Message); + Assert.That($"'jwk' cannot be null.", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidJwk_ThrowsConfigurationException() { @@ -154,11 +154,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", e.Message); + Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidJwkEmptyStringValue_ThrowsConfigurationException() { @@ -171,11 +171,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", e.Message); + Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingConfigInvalidJwkEmptyStringValue_ThrowsConfigurationException() { @@ -203,11 +203,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", e.Message); + Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingConfigPathEmptyValues_ThrowsArgumentException() { @@ -220,11 +220,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"'clientId' cannot be null or empty.", e.Message); + Assert.That($"'clientId' cannot be null or empty.", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidWellKnownUri_ThrowsWellKnownUriException() { @@ -236,9 +236,9 @@ public async Task CreateAsync_PassingInvalidWellKnownUri_ThrowsWellKnownUriExcep ItExpr.Is(r => r.Method == HttpMethod.Get), ItExpr.IsAny()) .Throws(new Exception()); - + var testHttpClient = new HttpClient(mockHandlerLocal.Object); - + try { await ConfidentialClient.CreateAsync( @@ -248,11 +248,11 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.AreEqual($"Error retrieving contents from the well_known_uri: {Constants.FACTSET_WELL_KNOWN_URI}", e.Message); - Assert.IsInstanceOf(e); + Assert.That($"Error retrieving contents from the well_known_uri: {Constants.FACTSET_WELL_KNOWN_URI}", Is.EqualTo(e.Message)); + Assert.That(e, Is.InstanceOf()); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathValidConfigInvalidUri_ThrowsWellKnownUriContentException() { @@ -268,7 +268,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathValidConfigJSON_InitialisesWithNoException() { @@ -278,15 +278,15 @@ public async Task CreateAsync_PassingValidConfigPathValidConfigJSON_InitialisesW Path.Join(_resourcesPath, "validConfig.json"), httpClient: _testHttpClientValidRes ); - - Assert.IsInstanceOf(confidentialClient); + + Assert.That(confidentialClient, Is.InstanceOf()); } catch (Exception) { Assert.Fail(); } } - + [Test] public async Task CreateAsync_InitialiseAndCastConfidentialClientToIOAuth2Client_InitialisesAndCastsSuccessfully() { @@ -294,119 +294,119 @@ public async Task CreateAsync_InitialiseAndCastConfidentialClientToIOAuth2Client Path.Join(_resourcesPath, "validConfig.json"), httpClient: _testHttpClientValidRes ); - - Assert.IsInstanceOf(confidentialClient); - Assert.IsInstanceOf((IOAuth2Client)confidentialClient); + + Assert.That(confidentialClient, Is.InstanceOf()); + Assert.That((IOAuth2Client)confidentialClient, Is.InstanceOf()); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedSigning_RaisesSigningJwsException() { int expireTime = 100; HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + // validConfig.txt is a valid config format, but invalid for signing a JWT. ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfig.txt"), mockClient ); - + try { await confidentialClient.GetAccessTokenAsync(); } catch (Exception e) { - Assert.AreEqual($"Failed signing of the JWS", e.Message); + Assert.That($"Failed signing of the JWS", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenWithErrorResponse_RaisesAccessTokenException() { HttpClient mockClient = CreateErroneousMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt")); - + // validConfig.txt is a valid config format, but invalid for signing a JWT. ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + try { await confidentialClient.GetAccessTokenAsync(); } catch (Exception e) { - Assert.AreEqual($"Error attempting to get access token", e.Message); + Assert.That($"Error attempting to get access token", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenForTheFirstTime_ReturnsNewAccessToken() { int expireTime = 100; HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + string accessToken = await confidentialClient.GetAccessTokenAsync(); - - Assert.AreEqual("1234", accessToken); + + Assert.That("1234", Is.EqualTo(accessToken)); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenTwiceBeforeExpiration_ReturnsSameAccessToken() { int expireTime = 100; HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + string accessToken = await confidentialClient.GetAccessTokenAsync(); - - Assert.AreEqual("1234", accessToken); - + + Assert.That("1234", Is.EqualTo(accessToken)); + // Called immediately after the first `GetAccessToken` call, so its within expiration. accessToken = await confidentialClient.GetAccessTokenAsync(); - - Assert.AreEqual("1234", accessToken); + + Assert.That("1234", Is.EqualTo(accessToken)); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenBeforeAndAfterExpiration_ReturnsDifferentAccessTokens() { int expireTime = 0; HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + string accessToken = await confidentialClient.GetAccessTokenAsync(); - - Assert.AreEqual("1234", accessToken); - + + Assert.That("1234", Is.EqualTo(accessToken)); + // Called after a zero expiration. accessToken = await confidentialClient.GetAccessTokenAsync(); - - Assert.AreEqual("4321", accessToken); + + Assert.That("4321", Is.EqualTo(accessToken)); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_ThrowAccessTokenException() { string wellKnownUriJson = GetJsonFromFile(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt")); - + var mockHandler = new Mock(MockBehavior.Strict); mockHandler .Protected() @@ -415,7 +415,7 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_Th ItExpr.Is(r => r.Method == HttpMethod.Post), ItExpr.IsAny()) .Throws(new Exception()); - + mockHandler .Protected() .Setup>( @@ -427,22 +427,22 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_Th StatusCode = HttpStatusCode.OK, Content = new StringContent(wellKnownUriJson) }); - + var testHttpClient = new HttpClient(mockHandler.Object); - + try { ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), httpClient: testHttpClient ); - + await confidentialClient.GetAccessTokenAsync(); } catch (Exception e) { - Assert.IsInstanceOf(e); - Assert.AreEqual($"Error attempting to get access token", e.Message); + Assert.That(e, Is.InstanceOf()); + Assert.That($"Error attempting to get access token", Is.EqualTo(e.Message)); } } diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs index 718c77c..047004c 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs @@ -12,12 +12,12 @@ class ConfigurationTests private string _resourcesPath; private string _validJwk; private string _invalidJwkMissingKty; - + [SetUp] public void Setup() { _resourcesPath = Path.Join(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.ToString(), "Resources"); - + _validJwk = @" { 'kty': 'test', @@ -33,7 +33,7 @@ public void Setup() 'dq': 'test', 'qi': 'test' }"; - + _invalidJwkMissingKty = @" { 'use': 'test', @@ -49,7 +49,7 @@ public void Setup() 'qi': 'test' }"; } - + [Test] public void Configuration_PassingEverythingNull_ThrowsArgumentException() { @@ -57,7 +57,7 @@ public void Configuration_PassingEverythingNull_ThrowsArgumentException() clientAuthType: null, jwk: null)); } - + [Test] public void Configuration_PassingClientIdNull_ThrowsArgumentException() { @@ -65,7 +65,7 @@ public void Configuration_PassingClientIdNull_ThrowsArgumentException() clientAuthType: "test", jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingClientAuthTypeNull_ThrowsArgumentException() { @@ -73,7 +73,7 @@ public void Configuration_PassingClientAuthTypeNull_ThrowsArgumentException() clientAuthType: null, jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingJwkNull_ThrowsArgumentException() { @@ -82,7 +82,7 @@ public void Configuration_PassingJwkNull_ThrowsArgumentException() clientAuthType: "test", jwk: jsonWebKey)); } - + [Test] public void Configuration_PassingEmptyAndNull_ThrowsArgumentException() { @@ -90,7 +90,7 @@ public void Configuration_PassingEmptyAndNull_ThrowsArgumentException() clientAuthType: "", jwk: null)); } - + [Test] public void Configuration_PassingClientIdEmpty_ThrowsArgumentException() { @@ -98,7 +98,7 @@ public void Configuration_PassingClientIdEmpty_ThrowsArgumentException() clientAuthType: "test", jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingClientAuthTypeEmpty_ThrowsArgumentException() { @@ -106,7 +106,7 @@ public void Configuration_PassingClientAuthTypeEmpty_ThrowsArgumentException() clientAuthType: "", jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingInvalidJwkMissingKty_ThrowsConfigurationException() { @@ -115,7 +115,7 @@ public void Configuration_PassingInvalidJwkMissingKty_ThrowsConfigurationExcepti clientAuthType: "test", jwk: jsonWebKey)); } - + [Test] public void Configuration_PassingMissingJwk_ThrowsConfigurationException() { @@ -124,16 +124,14 @@ public void Configuration_PassingMissingJwk_ThrowsConfigurationException() clientAuthType: "test", jwk: jsonWebKey)); } - + [Test] public void Configuration_PassingValidConfig_InstantiatesConfiguration() { JsonWebKey jsonWebKey = new(_validJwk); - Assert.IsInstanceOf(new Configuration(clientId: "test", - clientAuthType: "test", - jwk: jsonWebKey)); + Assert.That(new Configuration(clientId: "test", clientAuthType: "test", jwk: jsonWebKey), Is.InstanceOf()); } - + [Test] public void Parse_PassingNullConfigPath_ThrowsConfigurationException() { @@ -143,17 +141,17 @@ public void Parse_PassingNullConfigPath_ThrowsConfigurationException() } catch (Exception e) { - Assert.AreEqual("Value cannot be null. (Parameter 'configPath')", e.Message); + Assert.That("Value cannot be null. (Parameter 'configPath')", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public void Parse_PassingNonExistingFilePath_ThrowsFileNotFoundException() { Assert.Throws(() => Configuration.Parse(Path.Join(_resourcesPath, "somemoretests.txt"))); } - + [Test] public void Parse_PassingConfigFileWithMissingJwkProperties_ThrowsConfigurationException() { @@ -163,11 +161,11 @@ public void Parse_PassingConfigFileWithMissingJwkProperties_ThrowsConfigurationE } catch (Exception e) { - Assert.AreEqual($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", e.Message); + Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public void Parse_PassingConfigFileWithEmptyStringProperties_ThrowsArgumentException() { @@ -177,36 +175,36 @@ public void Parse_PassingConfigFileWithEmptyStringProperties_ThrowsArgumentExcep } catch (Exception e) { - Assert.AreEqual($"'clientId' cannot be null or empty.", e.Message); + Assert.That($"'clientId' cannot be null or empty.", Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public void Parse_PassingCorrectConfigFileFormat_ReturnsConfigurationInstance() { Configuration config = Configuration.Parse(Path.Join(_resourcesPath, "validConfig.json")); - - Assert.IsInstanceOf(config); - + + Assert.That(config, Is.InstanceOf()); + // Non-Jwk config properties. - Assert.AreEqual("testClientId", config.ClientId); - Assert.AreEqual("testClientAuthType", config.ClientAuthType); - Assert.AreEqual(Constants.FACTSET_WELL_KNOWN_URI, config.WellKnownUri); - + Assert.That("testClientId", Is.EqualTo(config.ClientId)); + Assert.That("testClientAuthType", Is.EqualTo(config.ClientAuthType)); + Assert.That(Constants.FACTSET_WELL_KNOWN_URI, Is.EqualTo(config.WellKnownUri)); + // Jwk properties. - Assert.AreEqual("testKty", config.Jwk.Kty); - Assert.AreEqual("testUse", config.Jwk.Use); - Assert.AreEqual("testAlg", config.Jwk.Alg); - Assert.AreEqual("testKid", config.Jwk.Kid); - Assert.AreEqual("testD", config.Jwk.D); - Assert.AreEqual("testN", config.Jwk.N); - Assert.AreEqual("AQAB", config.Jwk.E); - Assert.AreEqual("testP", config.Jwk.P); - Assert.AreEqual("testQ", config.Jwk.Q); - Assert.AreEqual("testDP", config.Jwk.DP); - Assert.AreEqual("testDQ", config.Jwk.DQ); - Assert.AreEqual("testQI", config.Jwk.QI); + Assert.That("testKty", Is.EqualTo(config.Jwk.Kty)); + Assert.That("testUse", Is.EqualTo(config.Jwk.Use)); + Assert.That("testAlg", Is.EqualTo(config.Jwk.Alg)); + Assert.That("testKid", Is.EqualTo(config.Jwk.Kid)); + Assert.That("testD", Is.EqualTo(config.Jwk.D)); + Assert.That("testN", Is.EqualTo(config.Jwk.N)); + Assert.That("AQAB", Is.EqualTo(config.Jwk.E)); + Assert.That("testP", Is.EqualTo(config.Jwk.P)); + Assert.That("testQ", Is.EqualTo(config.Jwk.Q)); + Assert.That("testDP", Is.EqualTo(config.Jwk.DP)); + Assert.That("testDQ", Is.EqualTo(config.Jwk.DQ)); + Assert.That("testQI", Is.EqualTo(config.Jwk.QI)); } } } diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs index cf417a6..28b11ca 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs @@ -10,120 +10,120 @@ class ExceptionsTests public void AccessTokenException_EmptyArg_InitialisesWithBaseMessage() { var exception = new AccessTokenException(); - Assert.AreEqual("Exception of type 'FactSet.SDK.Utils.Authentication.AccessTokenException' was thrown.", - exception.Message); + Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.AccessTokenException' was thrown.", + Is.EqualTo(exception.Message)); } - + [Test] public void AccessTokenException_MessageArg_InitialisesWithCustomMessage() { var exception = new AccessTokenException("Test AccessTokenException message"); - Assert.AreEqual("Test AccessTokenException message", exception.Message); + Assert.That("Test AccessTokenException message", Is.EqualTo(exception.Message)); } - + [Test] public void AccessTokenException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { var exception1 = new AccessTokenException("parent"); var exception2 = new AccessTokenException("Test AccessTokenException message", exception1); - Assert.AreEqual("Test AccessTokenException message", exception2.Message); - Assert.AreEqual(exception1, exception2.InnerException); + Assert.That("Test AccessTokenException message", Is.EqualTo(exception2.Message)); + Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void ConfigurationException_EmptyArg_InitialisesWithBaseMessage() { var exception = new ConfigurationException(); - Assert.AreEqual("Exception of type 'FactSet.SDK.Utils.Authentication.ConfigurationException' was thrown.", - exception.Message); + Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.ConfigurationException' was thrown.", + Is.EqualTo(exception.Message)); } - + [Test] public void ConfigurationException_MessageArg_InitialisesWithCustomMessage() { var exception = new ConfigurationException("Test CredentialsException message"); - Assert.AreEqual("Test CredentialsException message", exception.Message); + Assert.That("Test CredentialsException message", Is.EqualTo(exception.Message)); } - + [Test] public void ConfigurationException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { var exception1 = new ConfigurationException("parent"); var exception2 = new ConfigurationException("Test CredentialsException message", exception1); - Assert.AreEqual("Test CredentialsException message", exception2.Message); - Assert.AreEqual(exception1, exception2.InnerException); + Assert.That("Test CredentialsException message", Is.EqualTo(exception2.Message)); + Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void WellKnownUriException_EmptyArg_InitialisesWithBaseMessage() { var exception = new WellKnownUriException(); - Assert.AreEqual("Exception of type 'FactSet.SDK.Utils.Authentication.WellKnownUriException' was thrown.", - exception.Message); + Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.WellKnownUriException' was thrown.", + Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriException_MessageArg_InitialisesWithCustomMessage() { var exception = new WellKnownUriException("Test WellKnownUriException message"); - Assert.AreEqual("Test WellKnownUriException message", exception.Message); + Assert.That("Test WellKnownUriException message", Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { var exception1 = new WellKnownUriException("parent"); var exception2 = new WellKnownUriException("Test WellKnownUriException message", exception1); - Assert.AreEqual("Test WellKnownUriException message", exception2.Message); - Assert.AreEqual(exception1, exception2.InnerException); + Assert.That("Test WellKnownUriException message", Is.EqualTo(exception2.Message)); + Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void WellKnownUriContentException_EmptyArg_InitialisesWithBaseMessage() { var exception = new WellKnownUriContentException(); - Assert.AreEqual("Exception of type 'FactSet.SDK.Utils.Authentication.WellKnownUriContentException' was thrown.", - exception.Message); + Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.WellKnownUriContentException' was thrown.", + Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriContentException_MessageArg_InitialisesWithCustomMessage() { var exception = new WellKnownUriContentException("Test WellKnownUriContentException message"); - Assert.AreEqual("Test WellKnownUriContentException message", exception.Message); + Assert.That("Test WellKnownUriContentException message", Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriContentException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { var exception1 = new WellKnownUriContentException("parent"); var exception2 = new WellKnownUriContentException("Test WellKnownUriContentException message", exception1); - Assert.AreEqual("Test WellKnownUriContentException message", exception2.Message); - Assert.AreEqual(exception1, exception2.InnerException); + Assert.That("Test WellKnownUriContentException message", Is.EqualTo(exception2.Message)); + Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void SigningJwsException_EmptyArg_InitialisesWithBaseMessage() { var exception = new SigningJwsException(); - Assert.AreEqual("Exception of type 'FactSet.SDK.Utils.Authentication.SigningJwsException' was thrown.", - exception.Message); + Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.SigningJwsException' was thrown.", + Is.EqualTo(exception.Message)); } - + [Test] public void SigningJwsException_MessageArg_InitialisesWithCustomMessage() { var exception = new SigningJwsException("Test SigningJwsException message"); - Assert.AreEqual("Test SigningJwsException message", exception.Message); + Assert.That("Test SigningJwsException message", Is.EqualTo(exception.Message)); } - + [Test] public void SigningJwsException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { var exception1 = new SigningJwsException("parent"); var exception2 = new SigningJwsException("Test SigningJwsException message", exception1); - Assert.AreEqual("Test SigningJwsException message", exception2.Message); - Assert.AreEqual(exception1, exception2.InnerException); + Assert.That("Test SigningJwsException message", Is.EqualTo(exception2.Message)); + Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } } } diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/OAuth2ClientTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/OAuth2ClientTests.cs index 1ce5b75..6012ec3 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/OAuth2ClientTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/OAuth2ClientTests.cs @@ -10,7 +10,7 @@ class OAuth2ClientTests public void OAuth2ClientGoodInstantiation() { OAuth2ClientCorrect oAuth = new OAuth2ClientCorrect(); - Assert.IsInstanceOf(oAuth); + Assert.That(oAuth, Is.InstanceOf()); } } From c829bad4b93a253a83ff42f5ee0b34a68b8dde4a Mon Sep 17 00:00:00 2001 From: Granit Dula Date: Wed, 27 Dec 2023 17:28:35 +0000 Subject: [PATCH 3/4] fix: lint --- .../Authentication/ConfidentialClientTests.cs | 154 ++++++++++-------- .../Authentication/ConfigurationTests.cs | 92 ++++++----- .../Authentication/ExceptionsTests.cs | 36 ++-- 3 files changed, 149 insertions(+), 133 deletions(-) diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs index dc0b96e..64af11f 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.Net.Http; @@ -22,7 +21,8 @@ class ConfidentialClientTests [SetUp] public void Setup() { - _resourcesPath = Path.Join(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.ToString(), "Resources"); + _resourcesPath = Path.Join(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.ToString(), + "Resources"); _testHttpClientEmptyRes = CreateMockHttp(Path.Join(_resourcesPath, "emptyJson.json")); _testHttpClientValidRes = CreateMockHttp(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt")); } @@ -54,7 +54,7 @@ public async Task CreateAsync_PassingExplicitNull_ThrowsArgumentNullException() Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidConfig_ThrowsArgumentException() { @@ -71,7 +71,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidConfigPath_ThrowsDirectoryNotFoundException() { @@ -81,7 +81,7 @@ await ConfidentialClient.CreateAsync( "somemoretests.txt", httpClient: _testHttpClientEmptyRes ); - + // Should fail if no exception is thrown, since that file does not exist. Assert.Fail(); } @@ -90,7 +90,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathNonJsonConfig_ThrowsConfigurationException() { @@ -103,11 +103,12 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.That($"Exception caught when retrieving contents of {Path.Join(_resourcesPath, "badJson.txt")}", Is.EqualTo(e.Message)); + Assert.That($"Exception caught when retrieving contents of {Path.Join(_resourcesPath, "badJson.txt")}", + Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathInvalidConfig_ThrowsArgumentException() { @@ -124,7 +125,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingMissingJwk_ThrowsArgumentException() { @@ -141,7 +142,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidJwk_ThrowsConfigurationException() { @@ -154,11 +155,13 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); + Assert.That( + $"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", + Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidJwkEmptyStringValue_ThrowsConfigurationException() { @@ -171,11 +174,13 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); + Assert.That( + $"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", + Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingConfigInvalidJwkEmptyStringValue_ThrowsConfigurationException() { @@ -203,11 +208,13 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); + Assert.That( + $"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", + Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingConfigPathEmptyValues_ThrowsArgumentException() { @@ -224,7 +231,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingInvalidWellKnownUri_ThrowsWellKnownUriException() { @@ -236,9 +243,9 @@ public async Task CreateAsync_PassingInvalidWellKnownUri_ThrowsWellKnownUriExcep ItExpr.Is(r => r.Method == HttpMethod.Get), ItExpr.IsAny()) .Throws(new Exception()); - + var testHttpClient = new HttpClient(mockHandlerLocal.Object); - + try { await ConfidentialClient.CreateAsync( @@ -248,11 +255,12 @@ await ConfidentialClient.CreateAsync( } catch (Exception e) { - Assert.That($"Error retrieving contents from the well_known_uri: {Constants.FACTSET_WELL_KNOWN_URI}", Is.EqualTo(e.Message)); + Assert.That($"Error retrieving contents from the well_known_uri: {Constants.FACTSET_WELL_KNOWN_URI}", + Is.EqualTo(e.Message)); Assert.That(e, Is.InstanceOf()); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathValidConfigInvalidUri_ThrowsWellKnownUriContentException() { @@ -268,7 +276,7 @@ await ConfidentialClient.CreateAsync( Assert.Throws(() => throw e); } } - + [Test] public async Task CreateAsync_PassingValidConfigPathValidConfigJSON_InitialisesWithNoException() { @@ -278,7 +286,7 @@ public async Task CreateAsync_PassingValidConfigPathValidConfigJSON_InitialisesW Path.Join(_resourcesPath, "validConfig.json"), httpClient: _testHttpClientValidRes ); - + Assert.That(confidentialClient, Is.InstanceOf()); } catch (Exception) @@ -286,31 +294,33 @@ public async Task CreateAsync_PassingValidConfigPathValidConfigJSON_InitialisesW Assert.Fail(); } } - + [Test] - public async Task CreateAsync_InitialiseAndCastConfidentialClientToIOAuth2Client_InitialisesAndCastsSuccessfully() + public async Task + CreateAsync_InitialiseAndCastConfidentialClientToIOAuth2Client_InitialisesAndCastsSuccessfully() { ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfig.json"), httpClient: _testHttpClientValidRes ); - + Assert.That(confidentialClient, Is.InstanceOf()); Assert.That((IOAuth2Client)confidentialClient, Is.InstanceOf()); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedSigning_RaisesSigningJwsException() { int expireTime = 100; - HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + HttpClient mockClient = + CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); + // validConfig.txt is a valid config format, but invalid for signing a JWT. ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfig.txt"), mockClient ); - + try { await confidentialClient.GetAccessTokenAsync(); @@ -321,18 +331,19 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedSigning_Rai Assert.Throws(() => throw e); } } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenWithErrorResponse_RaisesAccessTokenException() { - HttpClient mockClient = CreateErroneousMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt")); - + HttpClient mockClient = + CreateErroneousMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt")); + // validConfig.txt is a valid config format, but invalid for signing a JWT. ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + try { await confidentialClient.GetAccessTokenAsync(); @@ -343,70 +354,74 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithErrorResponse_Rai Assert.Throws(() => throw e); } } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenForTheFirstTime_ReturnsNewAccessToken() { int expireTime = 100; - HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + HttpClient mockClient = + CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); + ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + string accessToken = await confidentialClient.GetAccessTokenAsync(); - + Assert.That("1234", Is.EqualTo(accessToken)); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenTwiceBeforeExpiration_ReturnsSameAccessToken() { int expireTime = 100; - HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + HttpClient mockClient = + CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); + ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + string accessToken = await confidentialClient.GetAccessTokenAsync(); - + Assert.That("1234", Is.EqualTo(accessToken)); - + // Called immediately after the first `GetAccessToken` call, so its within expiration. accessToken = await confidentialClient.GetAccessTokenAsync(); - + Assert.That("1234", Is.EqualTo(accessToken)); } - + [Test] - public async Task GetAccessTokenAsync_CallingGetAccessTokenBeforeAndAfterExpiration_ReturnsDifferentAccessTokens() + public async Task + GetAccessTokenAsync_CallingGetAccessTokenBeforeAndAfterExpiration_ReturnsDifferentAccessTokens() { int expireTime = 0; - HttpClient mockClient = CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); - + HttpClient mockClient = + CreateMockHttpTokenRequest(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt"), expireTime); + ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), mockClient ); - + string accessToken = await confidentialClient.GetAccessTokenAsync(); - + Assert.That("1234", Is.EqualTo(accessToken)); - + // Called after a zero expiration. accessToken = await confidentialClient.GetAccessTokenAsync(); - + Assert.That("4321", Is.EqualTo(accessToken)); } - + [Test] public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_ThrowAccessTokenException() { string wellKnownUriJson = GetJsonFromFile(Path.Join(_resourcesPath, "exampleResponseWellKnownUri.txt")); - + var mockHandler = new Mock(MockBehavior.Strict); mockHandler .Protected() @@ -415,7 +430,7 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_Th ItExpr.Is(r => r.Method == HttpMethod.Post), ItExpr.IsAny()) .Throws(new Exception()); - + mockHandler .Protected() .Setup>( @@ -424,19 +439,18 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_Th ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.OK, - Content = new StringContent(wellKnownUriJson) + StatusCode = HttpStatusCode.OK, Content = new StringContent(wellKnownUriJson) }); - + var testHttpClient = new HttpClient(mockHandler.Object); - + try { ConfidentialClient confidentialClient = await ConfidentialClient.CreateAsync( Path.Join(_resourcesPath, "validConfigGeneratedSample.txt"), httpClient: testHttpClient ); - + await confidentialClient.GetAccessTokenAsync(); } catch (Exception e) @@ -460,8 +474,7 @@ private static HttpClient CreateMockHttp(string getAsyncResponseFilePath) ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.OK, - Content = new StringContent(json) + StatusCode = HttpStatusCode.OK, Content = new StringContent(json) }); return new HttpClient(mockHandler.Object); @@ -488,8 +501,7 @@ private static HttpClient CreateErroneousMockHttpTokenRequest(string wellKnownUr ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.NotFound, - Content = new StringContent(wellKnownUriJson) + StatusCode = HttpStatusCode.NotFound, Content = new StringContent(wellKnownUriJson) }); return new HttpClient(mockHandler.Object); @@ -509,12 +521,14 @@ private static HttpClient CreateMockHttpTokenRequest(string wellKnownUriPath, in .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, - Content = new StringContent($"{{\"access_token\":\"1234\",\"token_type\":\"Bearer\",\"expires_in\":\"{expireTime}\"}}") + Content = new StringContent( + $"{{\"access_token\":\"1234\",\"token_type\":\"Bearer\",\"expires_in\":\"{expireTime}\"}}") }) .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, - Content = new StringContent($"{{\"access_token\":\"4321\",\"token_type\":\"Bearer\",\"expires_in\":\"{expireTime}\"}}") + Content = new StringContent( + $"{{\"access_token\":\"4321\",\"token_type\":\"Bearer\",\"expires_in\":\"{expireTime}\"}}") }); mockHandler @@ -525,8 +539,7 @@ private static HttpClient CreateMockHttpTokenRequest(string wellKnownUriPath, in ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.OK, - Content = new StringContent(wellKnownUriJson) + StatusCode = HttpStatusCode.OK, Content = new StringContent(wellKnownUriJson) }); return new HttpClient(mockHandler.Object); @@ -552,4 +565,3 @@ private static string GetJsonFromFile(string path) } } } - diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs index 047004c..7f08233 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfigurationTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using FactSet.SDK.Utils.Authentication; using Microsoft.IdentityModel.Tokens; @@ -12,12 +11,13 @@ class ConfigurationTests private string _resourcesPath; private string _validJwk; private string _invalidJwkMissingKty; - + [SetUp] public void Setup() { - _resourcesPath = Path.Join(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.ToString(), "Resources"); - + _resourcesPath = Path.Join(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.ToString(), + "Resources"); + _validJwk = @" { 'kty': 'test', @@ -33,7 +33,7 @@ public void Setup() 'dq': 'test', 'qi': 'test' }"; - + _invalidJwkMissingKty = @" { 'use': 'test', @@ -49,89 +49,90 @@ public void Setup() 'qi': 'test' }"; } - + [Test] public void Configuration_PassingEverythingNull_ThrowsArgumentException() { Assert.Throws(() => new Configuration(clientId: null, - clientAuthType: null, - jwk: null)); + clientAuthType: null, + jwk: null)); } - + [Test] public void Configuration_PassingClientIdNull_ThrowsArgumentException() { Assert.Throws(() => new Configuration(clientId: null, - clientAuthType: "test", - jwk: new JsonWebKey(_validJwk))); + clientAuthType: "test", + jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingClientAuthTypeNull_ThrowsArgumentException() { Assert.Throws(() => new Configuration(clientId: "test", - clientAuthType: null, - jwk: new JsonWebKey(_validJwk))); + clientAuthType: null, + jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingJwkNull_ThrowsArgumentException() { JsonWebKey jsonWebKey = null; Assert.Throws(() => new Configuration(clientId: "test", - clientAuthType: "test", - jwk: jsonWebKey)); + clientAuthType: "test", + jwk: jsonWebKey)); } - + [Test] public void Configuration_PassingEmptyAndNull_ThrowsArgumentException() { Assert.Throws(() => new Configuration(clientId: "", - clientAuthType: "", - jwk: null)); + clientAuthType: "", + jwk: null)); } - + [Test] public void Configuration_PassingClientIdEmpty_ThrowsArgumentException() { Assert.Throws(() => new Configuration(clientId: "", - clientAuthType: "test", - jwk: new JsonWebKey(_validJwk))); + clientAuthType: "test", + jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingClientAuthTypeEmpty_ThrowsArgumentException() { Assert.Throws(() => new Configuration(clientId: "test", - clientAuthType: "", - jwk: new JsonWebKey(_validJwk))); + clientAuthType: "", + jwk: new JsonWebKey(_validJwk))); } - + [Test] public void Configuration_PassingInvalidJwkMissingKty_ThrowsConfigurationException() { JsonWebKey jsonWebKey = new(_invalidJwkMissingKty); Assert.Throws(() => new Configuration(clientId: "test", - clientAuthType: "test", - jwk: jsonWebKey)); + clientAuthType: "test", + jwk: jsonWebKey)); } - + [Test] public void Configuration_PassingMissingJwk_ThrowsConfigurationException() { JsonWebKey jsonWebKey = new("{}"); Assert.Throws(() => new Configuration(clientId: "test", - clientAuthType: "test", - jwk: jsonWebKey)); + clientAuthType: "test", + jwk: jsonWebKey)); } - + [Test] public void Configuration_PassingValidConfig_InstantiatesConfiguration() { JsonWebKey jsonWebKey = new(_validJwk); - Assert.That(new Configuration(clientId: "test", clientAuthType: "test", jwk: jsonWebKey), Is.InstanceOf()); + Assert.That(new Configuration(clientId: "test", clientAuthType: "test", jwk: jsonWebKey), + Is.InstanceOf()); } - + [Test] public void Parse_PassingNullConfigPath_ThrowsConfigurationException() { @@ -145,13 +146,14 @@ public void Parse_PassingNullConfigPath_ThrowsConfigurationException() Assert.Throws(() => throw e); } } - + [Test] public void Parse_PassingNonExistingFilePath_ThrowsFileNotFoundException() { - Assert.Throws(() => Configuration.Parse(Path.Join(_resourcesPath, "somemoretests.txt"))); + Assert.Throws(() => + Configuration.Parse(Path.Join(_resourcesPath, "somemoretests.txt"))); } - + [Test] public void Parse_PassingConfigFileWithMissingJwkProperties_ThrowsConfigurationException() { @@ -161,11 +163,13 @@ public void Parse_PassingConfigFileWithMissingJwkProperties_ThrowsConfigurationE } catch (Exception e) { - Assert.That($"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", Is.EqualTo(e.Message)); + Assert.That( + $"JWK must contain the following items: {string.Join(", ", Constants.CONFIG_JWK_REQUIRED_KEYS)}", + Is.EqualTo(e.Message)); Assert.Throws(() => throw e); } } - + [Test] public void Parse_PassingConfigFileWithEmptyStringProperties_ThrowsArgumentException() { @@ -179,19 +183,19 @@ public void Parse_PassingConfigFileWithEmptyStringProperties_ThrowsArgumentExcep Assert.Throws(() => throw e); } } - + [Test] public void Parse_PassingCorrectConfigFileFormat_ReturnsConfigurationInstance() { Configuration config = Configuration.Parse(Path.Join(_resourcesPath, "validConfig.json")); - + Assert.That(config, Is.InstanceOf()); - + // Non-Jwk config properties. Assert.That("testClientId", Is.EqualTo(config.ClientId)); Assert.That("testClientAuthType", Is.EqualTo(config.ClientAuthType)); Assert.That(Constants.FACTSET_WELL_KNOWN_URI, Is.EqualTo(config.WellKnownUri)); - + // Jwk properties. Assert.That("testKty", Is.EqualTo(config.Jwk.Kty)); Assert.That("testUse", Is.EqualTo(config.Jwk.Use)); diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs index 28b11ca..a1d8a89 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ExceptionsTests.cs @@ -1,5 +1,4 @@ -using System.Runtime.Serialization; -using FactSet.SDK.Utils.Authentication; +using FactSet.SDK.Utils.Authentication; using NUnit.Framework; namespace FactSet.SDK.Utils.Tests.Authentication @@ -11,16 +10,16 @@ public void AccessTokenException_EmptyArg_InitialisesWithBaseMessage() { var exception = new AccessTokenException(); Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.AccessTokenException' was thrown.", - Is.EqualTo(exception.Message)); + Is.EqualTo(exception.Message)); } - + [Test] public void AccessTokenException_MessageArg_InitialisesWithCustomMessage() { var exception = new AccessTokenException("Test AccessTokenException message"); Assert.That("Test AccessTokenException message", Is.EqualTo(exception.Message)); } - + [Test] public void AccessTokenException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { @@ -29,7 +28,7 @@ public void AccessTokenException_MessageArgAndInnerException_InitialisesWithCust Assert.That("Test AccessTokenException message", Is.EqualTo(exception2.Message)); Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void ConfigurationException_EmptyArg_InitialisesWithBaseMessage() { @@ -37,14 +36,14 @@ public void ConfigurationException_EmptyArg_InitialisesWithBaseMessage() Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.ConfigurationException' was thrown.", Is.EqualTo(exception.Message)); } - + [Test] public void ConfigurationException_MessageArg_InitialisesWithCustomMessage() { var exception = new ConfigurationException("Test CredentialsException message"); Assert.That("Test CredentialsException message", Is.EqualTo(exception.Message)); } - + [Test] public void ConfigurationException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { @@ -53,7 +52,7 @@ public void ConfigurationException_MessageArgAndInnerException_InitialisesWithCu Assert.That("Test CredentialsException message", Is.EqualTo(exception2.Message)); Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void WellKnownUriException_EmptyArg_InitialisesWithBaseMessage() { @@ -61,14 +60,14 @@ public void WellKnownUriException_EmptyArg_InitialisesWithBaseMessage() Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.WellKnownUriException' was thrown.", Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriException_MessageArg_InitialisesWithCustomMessage() { var exception = new WellKnownUriException("Test WellKnownUriException message"); Assert.That("Test WellKnownUriException message", Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { @@ -77,7 +76,7 @@ public void WellKnownUriException_MessageArgAndInnerException_InitialisesWithCus Assert.That("Test WellKnownUriException message", Is.EqualTo(exception2.Message)); Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void WellKnownUriContentException_EmptyArg_InitialisesWithBaseMessage() { @@ -85,23 +84,24 @@ public void WellKnownUriContentException_EmptyArg_InitialisesWithBaseMessage() Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.WellKnownUriContentException' was thrown.", Is.EqualTo(exception.Message)); } - + [Test] public void WellKnownUriContentException_MessageArg_InitialisesWithCustomMessage() { var exception = new WellKnownUriContentException("Test WellKnownUriContentException message"); Assert.That("Test WellKnownUriContentException message", Is.EqualTo(exception.Message)); } - + [Test] - public void WellKnownUriContentException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() + public void + WellKnownUriContentException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { var exception1 = new WellKnownUriContentException("parent"); var exception2 = new WellKnownUriContentException("Test WellKnownUriContentException message", exception1); Assert.That("Test WellKnownUriContentException message", Is.EqualTo(exception2.Message)); Assert.That(exception1, Is.EqualTo(exception2.InnerException)); } - + [Test] public void SigningJwsException_EmptyArg_InitialisesWithBaseMessage() { @@ -109,14 +109,14 @@ public void SigningJwsException_EmptyArg_InitialisesWithBaseMessage() Assert.That("Exception of type 'FactSet.SDK.Utils.Authentication.SigningJwsException' was thrown.", Is.EqualTo(exception.Message)); } - + [Test] public void SigningJwsException_MessageArg_InitialisesWithCustomMessage() { var exception = new SigningJwsException("Test SigningJwsException message"); Assert.That("Test SigningJwsException message", Is.EqualTo(exception.Message)); } - + [Test] public void SigningJwsException_MessageArgAndInnerException_InitialisesWithCustomMessageAndInnerException() { From f6850bf63a955adb236c062b6fd5d05cd2d6db25 Mon Sep 17 00:00:00 2001 From: Granit Dula Date: Thu, 28 Dec 2023 10:48:17 +0000 Subject: [PATCH 4/4] fix: lint format --- .../Authentication/ConfidentialClientTests.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs index 64af11f..5bf7e44 100644 --- a/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs +++ b/tests/FactSet.SDK.Utils.Tests/Authentication/ConfidentialClientTests.cs @@ -439,7 +439,8 @@ public async Task GetAccessTokenAsync_CallingGetAccessTokenWithFailedResponse_Th ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.OK, Content = new StringContent(wellKnownUriJson) + StatusCode = HttpStatusCode.OK, + Content = new StringContent(wellKnownUriJson) }); var testHttpClient = new HttpClient(mockHandler.Object); @@ -474,7 +475,8 @@ private static HttpClient CreateMockHttp(string getAsyncResponseFilePath) ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.OK, Content = new StringContent(json) + StatusCode = HttpStatusCode.OK, + Content = new StringContent(json) }); return new HttpClient(mockHandler.Object); @@ -501,7 +503,8 @@ private static HttpClient CreateErroneousMockHttpTokenRequest(string wellKnownUr ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.NotFound, Content = new StringContent(wellKnownUriJson) + StatusCode = HttpStatusCode.NotFound, + Content = new StringContent(wellKnownUriJson) }); return new HttpClient(mockHandler.Object); @@ -539,7 +542,8 @@ private static HttpClient CreateMockHttpTokenRequest(string wellKnownUriPath, in ItExpr.IsAny()) .ReturnsAsync(new HttpResponseMessage() { - StatusCode = HttpStatusCode.OK, Content = new StringContent(wellKnownUriJson) + StatusCode = HttpStatusCode.OK, + Content = new StringContent(wellKnownUriJson) }); return new HttpClient(mockHandler.Object);