public void GetAcknowledgementTest() { string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <response> <acknowledgement> <status>success</status> </acknowledgement> <control> <status>success</status> <senderid>testsenderid</senderid> <controlid>ControlIdHere</controlid> <uniqueid>false</uniqueid> <dtdversion>3.0</dtdversion> </control> </response>"; Stream stream = new MemoryStream(); StreamWriter streamWriter = new StreamWriter(stream); streamWriter.Write(xml); streamWriter.Flush(); stream.Position = 0; OfflineResponse response = new OfflineResponse(stream); Assert.Equal("success", response.Status); }
public async Task MockExecuteAsynchronousTest() { string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?> <response> <acknowledgement> <status>success</status> </acknowledgement> <control> <status>success</status> <senderid>testsenderid</senderid> <controlid>requestUnitTest</controlid> <uniqueid>false</uniqueid> <dtdversion>3.0</dtdversion> </control> </response>"; HttpResponseMessage mockResponse = new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent(xml) }; List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage> { mockResponse, }; MockHandler mockHandler = new MockHandler(mockResponses); ClientConfig clientConfig = new ClientConfig() { SenderId = "testsenderid", SenderPassword = "******", SessionId = "testsession..", MockHandler = mockHandler, }; RequestConfig requestConfig = new RequestConfig() { PolicyId = "policyid321", ControlId = "requestUnitTest", }; List <IFunction> contentBlock = new List <IFunction> { new ApiSessionCreate() }; RequestHandler requestHandler = new RequestHandler(clientConfig, requestConfig); OfflineResponse response = await requestHandler.ExecuteOffline(contentBlock); Assert.IsType <OfflineResponse>(response); }
public async Task ExecuteBatchTest() { string xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <response> <acknowledgement> <status>success</status> </acknowledgement> <control> <status>success</status> <senderid>testsenderid</senderid> <controlid>requestUnitTest</controlid> <uniqueid>false</uniqueid> <dtdversion>3.0</dtdversion> </control> </response>"; HttpResponseMessage mockResponse1 = new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent(xml) }; List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage> { mockResponse1, }; MockHandler mockHandler = new MockHandler(mockResponses); ClientConfig clientConfig = new ClientConfig() { SenderId = "testsender", SenderPassword = "******", SessionId = "testsession..", MockHandler = mockHandler, }; RequestConfig requestConfig = new RequestConfig() { PolicyId = "asyncPolicyId", }; OfflineClient client = new OfflineClient(clientConfig); List <IFunction> contentBlock = new List <IFunction> { new ApiSessionCreate("func1UnitTest") }; OfflineResponse response = await client.ExecuteBatch(contentBlock, requestConfig); Assert.Equal("requestUnitTest", response.Control.ControlId); }
protected async Task <OfflineResponse> ExecuteOfflineRequest(List <IFunction> functions, RequestConfig requestConfig = null) { if (requestConfig == null) { requestConfig = new RequestConfig(); } RequestHandler requestHandler = new RequestHandler(this.Config, requestConfig); OfflineResponse response = await requestHandler.ExecuteOffline(functions).ConfigureAwait(false); return(response); }
public async Task MockExecuteOfflineWithSessionCredsTest() { string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?> <response> <acknowledgement> <status>success</status> </acknowledgement> <control> <status>success</status> <senderid>testsenderid</senderid> <controlid>requestUnitTest</controlid> <uniqueid>false</uniqueid> <dtdversion>3.0</dtdversion> </control> </response>"; HttpResponseMessage mockResponse = new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent(xml) }; List <HttpResponseMessage> mockResponses = new List <HttpResponseMessage> { mockResponse, }; MockHandler mockHandler = new MockHandler(mockResponses); var guid = Guid.NewGuid().ToString(); MemoryTarget target = new MemoryTarget { Name = guid, Layout = "${message}" }; SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug); ClientConfig clientConfig = new ClientConfig() { SenderId = "testsenderid", SenderPassword = "******", SessionId = "testsession..", MockHandler = mockHandler, Logger = LogManager.GetLogger(guid), }; RequestConfig requestConfig = new RequestConfig() { ControlId = "requestUnitTest", PolicyId = "policyid123", }; List <IFunction> contentBlock = new List <IFunction> { new ApiSessionCreate() }; RequestHandler requestHandler = new RequestHandler(clientConfig, requestConfig); OfflineResponse response = await requestHandler.ExecuteOffline(contentBlock); Assert.True(true); // TODO fix this test from randomly failing //Assert.Contains("Offline execution sent to Intacct using Session-based credentials.", target.Logs[0]); }