public async Task ShouldCreatePexaWorkspaceResponse() { using (var _httpClient = new PEXAMockHttpClient(A.Fake <PEXAMockClientHandler>(opt => opt.CallsBaseMethods()))) { var _iPEXAService = new PEXAService(_httpClient, _config); var response = await _iPEXAService.Handle <WorkspaceCreationResponse>( new WorkspaceCreationRequestCommand(new WorkspaceCreationRequest(), "testBearerToken"), CancellationToken.None).ConfigureAwait(true); Assert.Equal("PEXA190167645", response.WorkspaceId); Assert.Equal("In Preparation", response.WorkspaceStatus); } }
public async Task ShouldCaptureExceptionResponse() { try { using (var _httpClient = new PEXAMockHttpClient(A.Fake <PEXAMockClientHandler>(opt => opt.CallsBaseMethods()))) { var _iPEXAService = new PEXAService(_httpClient, _config); _httpClient.MockHandler.ReturnException = true; var response = await _iPEXAService.Handle <WorkspaceCreationResponse>( new WorkspaceCreationRequestCommand(new WorkspaceCreationRequest(), "testBearerToken"), CancellationToken.None).ConfigureAwait(true); } } catch (PEXAException ex) { var exceptionResponse = ex.ExceptionResponse; Assert.Equal("400001", exceptionResponse.ExceptionList.ElementAt(0).Code); Assert.Equal("The message has failed schema validation", exceptionResponse.ExceptionList.ElementAt(0).Message); Assert.Equal("OB1409.002", exceptionResponse.ExceptionList.ElementAt(1).Code); Assert.Equal("The workgroup cannot be found", exceptionResponse.ExceptionList.ElementAt(1).Message); } }
public async Task ShouldCreatePEXAWorkspaceRequestFromActionstep() { var testUser = await _containerFixture.GetTestUser(); await _containerFixture.ExecuteScopeAsync(async serviceProvider => { using (var authDelegatingHandler = new AuthDelegatingHandler() { InnerHandler = _handler }) using (var httpClient = new HttpClient(authDelegatingHandler)) { var fakeClock = new FakeClock(new Instant()); var testTokenSetRepository = new TestTokenSetRepository(); await testTokenSetRepository.AddOrUpdateTokenSet(new TokenSet("accessToken", "bearer", 3600, new Uri("https://uri/api"), "testOrg", "refreshToken", fakeClock.GetCurrentInstant(), testUser.Id)); var options = new ActionstepServiceConfigurationOptions("clientId", "clientSecret"); var actionstepService = new ActionstepService(new NullLogger <ActionstepService>(), httpClient, options, testTokenSetRepository, fakeClock, new MemoryCache(new MemoryCacheOptions())); var mapper = serviceProvider.GetService <IMapper>(); var actionstepToWcaMapper = serviceProvider.GetService <IActionstepToWCAMapper>(); PrepareTestData(serviceProvider); var handler = new PEXAWorkspaceCreationRequestFromActionstepQueryHandler(actionstepService, mapper, actionstepToWcaMapper); var token = new CancellationToken(); var query = new PEXAWorkspaceCreationRequestFromActionstepQuery { AuthenticatedUser = testUser, MatterId = 1, ActionstepOrg = "testOrg" }; var pexaWorkspaceCreationResponse = await handler.Handle(query, token); Assert.Equal("1", pexaWorkspaceCreationResponse.CreatePexaWorkspaceCommand.PexaWorkspaceCreationRequest.SubscriberReference); Assert.Equal("Yes", pexaWorkspaceCreationResponse.CreatePexaWorkspaceCommand.PexaWorkspaceCreationRequest.FinancialSettlement); var config = new ConfigurationBuilder(); config.AddInMemoryCollection(new Dictionary <string, string>() { { "WCACoreSettings:PEXASettings:Environment", "Test" } }); var pexaService = new PEXAService(httpClient, config.Build()); var request = new WorkspaceCreationRequestCommand(pexaWorkspaceCreationResponse.CreatePexaWorkspaceCommand.PexaWorkspaceCreationRequest, "dummyToken"); var response = await pexaService.Handle <WorkspaceCreationResponse>(request, CancellationToken.None); Assert.Equal("PEXA190167645", response.WorkspaceId); Assert.Equal("In Preparation", response.WorkspaceStatus); var xmldiff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes); var expectedXml = EmbeddedResource.Read("ResponseData.create-workspace-result.xml"); var actualXml = _handler.RequestContent; var expectedReader = XElement.Parse(expectedXml).CreateReader(); var actualReader = XElement.Parse(actualXml).CreateReader(); using (var diffStringWriter = new StringWriter()) using (var diffWriter = XmlWriter.Create(diffStringWriter)) { var areXmlIdentical = xmldiff.Compare(expectedReader, actualReader, diffWriter); diffWriter.Flush(); foreach (var diffLine in diffStringWriter.ToString().Split(diffStringWriter.NewLine)) { _output.WriteLine(diffLine); } Assert.True(areXmlIdentical); } } }); }