diff --git a/MFaaP.MFWSClient.Tests/MFWSClient.Authentication.cs b/MFaaP.MFWSClient.Tests/MFWSClient.Authentication.cs index 4fa2604..aed0fd7 100644 --- a/MFaaP.MFWSClient.Tests/MFWSClient.Authentication.cs +++ b/MFaaP.MFWSClient.Tests/MFWSClient.Authentication.cs @@ -36,7 +36,7 @@ public void AuthenticateUsingSingleSignOn() { var options = new RestClientOptions(); options.BaseUrl = runner.RestClientMock.Object.BaseUrl; - runner.RestClientMock.Setup(m => m.Options).Returns(options); + runner.RestClientMock.Setup(m => m.Options).Returns(new ReadOnlyRestClientOptions(options)); var cookieContainer = new CookieContainer(); runner.RestClientMock.Setup(m => m.CookieContainer).Returns(cookieContainer); } @@ -110,7 +110,7 @@ public async Task AuthenticateUsingSingleSignOnAsync() { var options = new RestClientOptions(); options.BaseUrl = runner.RestClientMock.Object.BaseUrl; - runner.RestClientMock.Setup(m => m.Options).Returns(options); + runner.RestClientMock.Setup(m => m.Options).Returns(new ReadOnlyRestClientOptions(options)); var cookieContainer = new CookieContainer(); runner.RestClientMock.Setup(m => m.CookieContainer).Returns(cookieContainer); } diff --git a/MFaaP.MFWSClient.Tests/MFWSClient.cs b/MFaaP.MFWSClient.Tests/MFWSClient.cs index d5915fe..2c57952 100644 --- a/MFaaP.MFWSClient.Tests/MFWSClient.cs +++ b/MFaaP.MFWSClient.Tests/MFWSClient.cs @@ -89,7 +89,7 @@ public static MFaaP.MFWSClient.MFWSClient GetMFWSClient(Moq.Mock re // Ensure that we have a default parameter collection, if it's not been mocked already. if (null == restClientMoq.Object.DefaultParameters) { - var defaultParameters = new ParametersCollection(); + var defaultParameters = new DefaultParameters(new ReadOnlyRestClientOptions(new RestClientOptions())); restClientMoq .SetupGet(p => p.DefaultParameters) .Returns(defaultParameters); diff --git a/MFaaP.MFWSClient.Tests/MFWSVaultObjectFileOperations.cs b/MFaaP.MFWSClient.Tests/MFWSVaultObjectFileOperations.cs index 85a8dda..39e2697 100644 --- a/MFaaP.MFWSClient.Tests/MFWSVaultObjectFileOperations.cs +++ b/MFaaP.MFWSClient.Tests/MFWSVaultObjectFileOperations.cs @@ -423,14 +423,14 @@ public async Task AddFilesAsync_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new ExtendedObjectVersion() - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new ExtendedObjectVersion() + } + ); }); // We also need to handle the upload file call or our tests will except. @@ -439,17 +439,17 @@ public async Task AddFilesAsync_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new UploadInfo() - { - UploadID = 1 - } - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new UploadInfo() + { + UploadID = 1 + } + } + ); }); /* Act */ @@ -498,14 +498,14 @@ public void AddFiles_CorrectResource() }) // Return a mock response. .Returns(() => - { - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new ExtendedObjectVersion() - ) - ); + { + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new ExtendedObjectVersion() + } + ); }); // We also need to handle the upload file call or our tests will except. @@ -514,17 +514,17 @@ public void AddFiles_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new UploadInfo() - { - UploadID = 1 - } - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new UploadInfo() + { + UploadID = 1 + } + } + ); }); @@ -578,14 +578,14 @@ public async Task AddFilesAsync_CorrectMethod() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new ExtendedObjectVersion() - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new ExtendedObjectVersion() + } + ); }); // We also need to handle the upload file call or our tests will except. @@ -594,17 +594,17 @@ public async Task AddFilesAsync_CorrectMethod() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new UploadInfo() - { - UploadID = 1 - } - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new UploadInfo() + { + UploadID = 1 + } + } + ); }); /* Act */ @@ -657,10 +657,10 @@ public void AddFiles_CorrectMethod() //Return the mock object. return Task.FromResult ( - Mock.Of> - ( - m => m.Data == new ExtendedObjectVersion() - ) + new RestResponse(new RestRequest()) + { + Data = new ExtendedObjectVersion() + } ); }); @@ -670,17 +670,17 @@ public void AddFiles_CorrectMethod() // Return a mock response. .Returns(() => { - //Return the mock object. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new UploadInfo() - { - UploadID = 1 - } - ) - ); + //Return the mock object. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new UploadInfo() + { + UploadID = 1 + } + } + ); }); /* Act */ @@ -830,14 +830,14 @@ public void RemoveFile_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new ExtendedObjectVersion() - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new ExtendedObjectVersion() + } + ); }); @@ -881,14 +881,14 @@ public async Task RemoveFileAsync_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new ExtendedObjectVersion() - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new ExtendedObjectVersion() + } + ); }); diff --git a/MFaaP.MFWSClient.Tests/MFWSVaultObjectSearchOperations.cs b/MFaaP.MFWSClient.Tests/MFWSVaultObjectSearchOperations.cs index 9143a03..11b3aa3 100644 --- a/MFaaP.MFWSClient.Tests/MFWSVaultObjectSearchOperations.cs +++ b/MFaaP.MFWSClient.Tests/MFWSVaultObjectSearchOperations.cs @@ -670,13 +670,12 @@ public void SearchForObjectsByConditions_DatePropertyValueSearchCondition_Correc // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult + return Task.FromResult ( - Mock.Of>> - ( - m => m.Data == new Results() - ) + new RestResponse>(new RestRequest()) + { + Data = new Results() + } ); }); @@ -721,15 +720,15 @@ public async Task SearchForObjectsByConditionsAsync_DatePropertyValueSearchCondi // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -772,15 +771,15 @@ public void SearchForObjectsByConditions_DatePropertyValueSearchCondition_Correc // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -827,15 +826,15 @@ public async Task SearchForObjectsByConditionsAsync_LookupPropertyValueSearchCon // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -878,15 +877,15 @@ public void SearchForObjectsByConditions_LookupPropertyValueSearchCondition_Corr // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -933,15 +932,15 @@ public async Task SearchForObjectsByConditionsAsync_MultiSelectLookupPropertyVal // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -984,15 +983,15 @@ public void SearchForObjectsByConditions_MultiSelectLookupPropertyValueSearchCon // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1039,15 +1038,15 @@ public async Task SearchForObjectsByConditionsAsync_TextPropertyValueSearchCondi // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1090,15 +1089,15 @@ public void SearchForObjectsByConditions_TextPropertyValueSearchCondition_Correc // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1141,15 +1140,15 @@ public async Task SearchForObjectsByConditionsAsync_TextPropertyValueSearchCondi // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1192,15 +1191,15 @@ public void SearchForObjectsByConditions_TextPropertyValueSearchCondition_Correc // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1243,15 +1242,15 @@ public async Task SearchForObjectsByConditionsAsync_TextPropertyValueSearchCondi // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1294,15 +1293,15 @@ public void SearchForObjectsByConditions_TextPropertyValueSearchCondition_Correc // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1345,15 +1344,15 @@ public async Task SearchForObjectsByConditionsAsync_TextPropertyValueSearchCondi // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1396,15 +1395,15 @@ public void SearchForObjectsByConditions_TextPropertyValueSearchCondition_Correc // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1451,15 +1450,15 @@ public async Task SearchForObjectsByConditionsAsync_ValueList_CorrectResource_In // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ @@ -1502,15 +1501,15 @@ public void SearchForObjectsByConditionsAsync_ValueList_CorrectResource_External // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new Results() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new Results() + } + ); + }); /* Act */ diff --git a/MFaaP.MFWSClient.Tests/MFWSVaultPropertyDefOperations.cs b/MFaaP.MFWSClient.Tests/MFWSVaultPropertyDefOperations.cs index f5597ad..0baff9f 100644 --- a/MFaaP.MFWSClient.Tests/MFWSVaultPropertyDefOperations.cs +++ b/MFaaP.MFWSClient.Tests/MFWSVaultPropertyDefOperations.cs @@ -126,16 +126,15 @@ public async Task GetPropertyDefsAsync_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new List() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new List() + } + ); + }); /* Act */ @@ -178,16 +177,15 @@ public void GetPropertyDefs_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new List() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new List() + } + ); + }); /* Act */ @@ -230,16 +228,15 @@ public async Task GetPropertyDefsAsync_CorrectMethod() // Return a mock response. .Returns(() => { - // Create the mock response. - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new List() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new List() + } + ); + }); /* Act */ @@ -282,14 +279,14 @@ public void GetPropertyDefs_CorrectMethod() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of>> - ( - m => m.Data == new List() - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse>(new RestRequest()) + { + Data = new List() + } + ); }); /* Act */ @@ -337,15 +334,15 @@ public async Task GetPropertyDefAsync_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new PropertyDef() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new PropertyDef() + } + ); + }); /* Act */ @@ -388,15 +385,15 @@ public void GetPropertyDef_CorrectResource() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new PropertyDef() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new PropertyDef() + } + ); + }); /* Act */ @@ -439,15 +436,15 @@ public async Task GetPropertyDefAsync_CorrectMethod() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new PropertyDef() - ) - ); - }); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new PropertyDef() + } + ); + }); /* Act */ @@ -490,14 +487,14 @@ public void GetPropertyDef_CorrectMethod() // Return a mock response. .Returns(() => { - // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == new PropertyDef() - ) - ); + // Create the mock response. + return Task.FromResult + ( + new RestResponse(new RestRequest()) + { + Data = new PropertyDef() + } + ); }); /* Act */ diff --git a/MFaaP.MFWSClient.Tests/MFaaP.MFWSClient.Tests.csproj b/MFaaP.MFWSClient.Tests/MFaaP.MFWSClient.Tests.csproj index 74e1232..6f54d9f 100644 --- a/MFaaP.MFWSClient.Tests/MFaaP.MFWSClient.Tests.csproj +++ b/MFaaP.MFWSClient.Tests/MFaaP.MFWSClient.Tests.csproj @@ -74,6 +74,7 @@ + @@ -83,13 +84,13 @@ - 4.7.1 + 4.20.72 - 13.0.1 + 13.0.3 - 108.0.2 + 112.0.0 diff --git a/MFaaP.MFWSClient.Tests/RestApiTestRunner.cs b/MFaaP.MFWSClient.Tests/RestApiTestRunner.cs index ef6ff84..db37b38 100644 --- a/MFaaP.MFWSClient.Tests/RestApiTestRunner.cs +++ b/MFaaP.MFWSClient.Tests/RestApiTestRunner.cs @@ -249,14 +249,14 @@ protected virtual void HandleCallback(RestRequest r) if (null != this.ExpectedRequestBody) { // Get the body from the request. - var requestBody = (r.Parameters ?? new ParametersCollection()) + var requestBody = (r.Parameters ?? new RequestParameters()) .FirstOrDefault(p => p.Type == ParameterType.RequestBody); if (null == requestBody) Assert.Fail("A request body was expected but none was provided."); // Ensure the content type is correct. Assert.AreEqual( - this.ExpectedRequestBody.Name, + this.ExpectedRequestBody.ContentType, requestBody.ContentType); // Ensure that the value is correct. @@ -364,16 +364,15 @@ public RestApiTestRunner(RestSharp.Method expectedMethod, /// public new Task> HandleReturns(RestRequest r) { + var result = new RestResponse(r) + { + Data = this.ResponseData, + StatusCode = this.ResponseStatusCode, + ResponseUri = new Uri(r.Resource, UriKind.Relative) + }; + // Create the mock response. - return Task.FromResult - ( - Mock.Of> - ( - m => m.Data == this.ResponseData - && m.StatusCode == this.ResponseStatusCode - && m.ResponseUri == new Uri(r.Resource, UriKind.Relative) - ) - ); + return Task.FromResult(result); } } diff --git a/MFaaP.MFWSClient.Tests/Setup.cs b/MFaaP.MFWSClient.Tests/Setup.cs new file mode 100644 index 0000000..9501bd1 --- /dev/null +++ b/MFaaP.MFWSClient.Tests/Setup.cs @@ -0,0 +1,58 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MFaaP.MFWSClient.Tests +{ + [TestClass] + public class SetupAssemblyInitializer + { + [AssemblyInitialize] + public static void AssemblyInit(TestContext context) + { + var assemblies = new List() + { + "System.Text.Json", + "System.Runtime.CompilerServices.Unsafe" + }; + var assemlbyResolveHelper = new AssemblyResolveHelper(assemblies); + AppDomain.CurrentDomain.AssemblyResolve += assemlbyResolveHelper.OnAssemlbyResolve; + } + } + public class AssemblyResolveHelper + { + public AssemblyResolveHelper(string assemblyName) + { + _assemlbyNames.Add(assemblyName); + } + + public AssemblyResolveHelper(List assemblyNames) + { + if (assemblyNames != null) + { + _assemlbyNames = assemblyNames; + } + } + + private List _assemlbyNames = new List(); + + public System.Reflection.Assembly OnAssemlbyResolve(object sender, ResolveEventArgs args) + { + var assemblyName = _assemlbyNames.FirstOrDefault(i => i == args.Name.Split(',')[0]); + if (assemblyName != null) + { + string assemlbyPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), assemblyName + ".dll"); + + if (File.Exists(assemlbyPath)) + { + return System.Reflection.Assembly.LoadFrom(assemlbyPath); + } + } + return null; + } + } +} diff --git a/MFaaP.MFWSClient/MFWSClient.Authentication.cs b/MFaaP.MFWSClient/MFWSClient.Authentication.cs index b201189..b41d156 100644 --- a/MFaaP.MFWSClient/MFWSClient.Authentication.cs +++ b/MFaaP.MFWSClient/MFWSClient.Authentication.cs @@ -43,7 +43,7 @@ public string AuthenticationToken foreach (var parameter in this.DefaultParameters.Where(p => p.Name == MFWSClient.XAuthenticationHttpHeaderName) .ToArray()) { - this.DefaultParameters.RemoveParameter(parameter); + this.DefaultParameters.RemoveParameter(parameter.Name, parameter.Type); } // Add the new one. @@ -81,7 +81,7 @@ public void ClearVaultHeader() foreach (var parameter in this.DefaultParameters.Where(p => p.Name == MFWSClient.VaultHttpHeaderName) .ToArray()) { - this.DefaultParameters.RemoveParameter(parameter); + this.DefaultParameters.RemoveParameter(parameter.Name, parameter.Type); } } @@ -110,7 +110,7 @@ protected virtual void ClearAuthenticationToken() foreach (var parameter in this.DefaultParameters.Where(p => p.Name == MFWSClient.AuthorizationHttpHeaderName) .ToArray()) { - this.DefaultParameters.RemoveParameter(parameter); + this.DefaultParameters.RemoveParameter(parameter.Name, parameter.Type); } } diff --git a/MFaaP.MFWSClient/MFWSClientBase.HttpRequests.cs b/MFaaP.MFWSClient/MFWSClientBase.HttpRequests.cs index 2aed321..f54db2d 100644 --- a/MFaaP.MFWSClient/MFWSClientBase.HttpRequests.cs +++ b/MFaaP.MFWSClient/MFWSClientBase.HttpRequests.cs @@ -403,7 +403,7 @@ public virtual void EnsureEnabledExtensionsAreSpecified(RestRequest request) // Retrieve the current X-Extensions values (comma-separated) as an array. // Need to handle various null/empty scenarios here. - var existingExtensions = ((request.Parameters ?? new ParametersCollection()) + var existingExtensions = ((request.Parameters ?? new RequestParameters()) .FirstOrDefault(p => p.Type == ParameterType.HttpHeader && p.Name == MFWSClientBase.ExtensionsHttpHeaderName)? diff --git a/MFaaP.MFWSClient/MFWSClientBase.cs b/MFaaP.MFWSClient/MFWSClientBase.cs index dabf4ab..01b467b 100644 --- a/MFaaP.MFWSClient/MFWSClientBase.cs +++ b/MFaaP.MFWSClient/MFWSClientBase.cs @@ -11,13 +11,13 @@ namespace MFaaP.MFWSClient public interface IRestClient { CookieContainer CookieContainer { get; } - ParametersCollection DefaultParameters { get; } + DefaultParameters DefaultParameters { get; } Task ExecuteAsync(RestRequest request, CancellationToken cancellationToken = default); Task> ExecuteAsync(RestRequest request, CancellationToken cancellationToken = default); - bool FollowRedirects { get; set; } - bool PreAuthenticate { get; set; } - RestClientOptions Options { get; } - Uri BaseUrl { get; set; } + bool FollowRedirects { get; } + bool PreAuthenticate { get; } + ReadOnlyRestClientOptions Options { get; } + Uri BaseUrl { get; } } public class RestSharpRestClient : RestClient, IRestClient @@ -25,7 +25,6 @@ public class RestSharpRestClient public RestSharpRestClient(Uri baseUri) : base(baseUri) { - } public RestSharpRestClient(RestClientOptions options) @@ -47,21 +46,23 @@ public Task> ExecuteAsync(RestRequest request, CancellationTo return RestClientExtensions.ExecuteAsync(this, request, request.Method, cancellationToken); } + public CookieContainer CookieContainer + { + get => base.Options?.CookieContainer; + } + public Uri BaseUrl { get => base.Options?.BaseUrl; - set => base.Options.BaseUrl = value; } - public bool FollowRedirects + public bool FollowRedirects { get => base.Options.FollowRedirects; - set => base.Options.FollowRedirects = value; } public bool PreAuthenticate { get => base.Options.PreAuthenticate; - set => base.Options.PreAuthenticate = value; } } /// @@ -115,7 +116,7 @@ public CookieContainer CookieContainer /// /// The default parameters for all http requests. /// - public ParametersCollection DefaultParameters + public DefaultParameters DefaultParameters { get { return this.RestClient.DefaultParameters; } } @@ -215,8 +216,6 @@ protected MFWSClientBase(IRestClient restClient) // Set up the RestClient. this.RestClient = restClient ?? throw new ArgumentNullException(nameof(restClient)); - this.RestClient.FollowRedirects = true; - this.RestClient.PreAuthenticate = true; // Set up our sub-objects. this.ObjectSearchOperations = new MFWSVaultObjectSearchOperations(this); @@ -245,26 +244,41 @@ protected MFWSClientBase(IRestClient restClient) protected MFWSClientBase(string baseUrl) : this(new Uri(baseUrl)) { - } + } - /// - /// Creates an MFWSClient pointing at the MFWA site. - /// - /// The base url of the MFWA (web access) site; note that this should be of the form - /// "http://localhost", not of the form "http://localhost/REST". - protected MFWSClientBase(Uri baseUrl) - : this(new RestSharpRestClient(baseUrl)) - { - } + /// + /// Creates an MFWSClient pointing at the MFWA site. + /// + /// The base url of the MFWA (web access) site; note that this should be of the form + /// "http://localhost", not of the form "http://localhost/REST". + protected MFWSClientBase(Uri baseUrl) + : this(new RestClientOptions() + { + BaseUrl = baseUrl, + FollowRedirects = true, + PreAuthenticate = true + }) + { + } - /// - /// Adds a default header to requests. - /// - /// The name of the HTTP header. - /// The value of the HTTP header. - public void AddDefaultHeader(string name, string value) + /// + /// Creates an MFWSClient pointing at the MFWA site. + /// + /// The base url of the MFWA (web access) site; note that this should be of the form + /// "http://localhost", not of the form "http://localhost/REST". + protected MFWSClientBase(RestClientOptions options) + : this(new RestSharpRestClient(options ?? new RestClientOptions())) + { + } + + /// + /// Adds a default header to requests. + /// + /// The name of the HTTP header. + /// The value of the HTTP header. + public void AddDefaultHeader(string name, string value) { - try { this.RestClient.DefaultParameters.RemoveParameter(name); } + try { this.RestClient.DefaultParameters.RemoveParameter(name, ParameterType.HttpHeader); } catch{ } this.RestClient.DefaultParameters.AddParameter(new HeaderParameter(name, value)); @@ -282,7 +296,7 @@ public void ClearPresharedKey() .ToArray(); foreach (var existingHeader in existingHeaders) { - this.RestClient.DefaultParameters.RemoveParameter(existingHeader); + this.RestClient.DefaultParameters.RemoveParameter(existingHeader.Name, existingHeader.Type); } } @@ -320,7 +334,7 @@ public void SetAcceptLanguage(string acceptLanguages) .ToArray(); foreach (var existingHeader in existingHeaders) { - this.RestClient.DefaultParameters.RemoveParameter(existingHeader); + this.RestClient.DefaultParameters.RemoveParameter(existingHeader.Name, existingHeader.Type); } // Sanity. diff --git a/MFaaP.MFWSClient/MFaaP.MFWSClient.csproj b/MFaaP.MFWSClient/MFaaP.MFWSClient.csproj index 80d2eaa..8173278 100644 --- a/MFaaP.MFWSClient/MFaaP.MFWSClient.csproj +++ b/MFaaP.MFWSClient/MFaaP.MFWSClient.csproj @@ -17,7 +17,7 @@ - +