public async Task invalid_account_returns_empty_row_set() { const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetCustomer</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""firstname"" type=""string"" nullable=""true""></RSColumn> <RSColumn name=""lastname"" type=""string"" nullable=""true""></RSColumn> </ResultSetMetaData> <Rows></Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetCustomerAsync( "primaryposref = ?", new[] { new ColumnValue("primaryPOSRef", "doesNotMatter") }, new[] { new Column("firstname"), new Column("lastname") }); Assert.Equal(2, actual.MetaData.Length); Assert.Empty(actual.Rows); }
public async Task valid_account_with_multiple_customers() { // If we create multiple customers and associate each with the same // account, response becomes as below. const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetCustomer</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""firstname"" type=""string"" nullable=""true""></RSColumn> <RSColumn name=""lastname"" type=""string"" nullable=""true""></RSColumn> </ResultSetMetaData> <Rows> <Row id=""416440""> <Col>John</Col> <Col>Doe</Col> </Row> <Row id=""422056""> <Col /> <Col /> </Row> <Row id=""456663""> <Col>Rubber</Col> <Col>Duck</Col> </Row> </Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetCustomerAsync( "primaryposref = ?", new[] { new ColumnValue("primaryPOSRef", "doesNotMatter") }, new[] { new Column("firstname"), new Column("lastname") }); Assert.Equal(3, actual.Rows.Length); var r0 = actual.Rows[0]; Assert.Equal(416440, r0.Id); Assert.Equal("John", r0.Columns["firstname"]); Assert.Equal("Doe", r0.Columns["lastname"]); var r1 = actual.Rows[1]; Assert.Equal(422056, r1.Id); Assert.Null(r1.Columns["firstname"]); Assert.Null(r1.Columns["lastname"]); var r2 = actual.Rows[2]; Assert.Equal(456663, r2.Id); Assert.Equal("Rubber", r2.Columns["firstname"]); Assert.Equal("Duck", r2.Columns["lastname"]); }
public async Task triggers_http_406_on_too_many_calls() { var i = 1; try { var client = new CrmClient(_options, _executor); var columnValues = new[] { new ColumnValue("primaryposref", "2200000") }; var columns = new[] { new Column("firstname"), new Column("lastname"), new Column("active") }; for (; ; i++) { var _ = await client.GetCustomerAsync("primaryposref = ?", columnValues, columns); } } catch (OracleHospitalityClientException) { // Intentionally left blank. Query i for count. } }
private async Task <GetCustomerResponse> GetCustomer(CrmClient client, string accountNumber) { // Whereas this operations returns A25 as the value of a column, // when we actually issue queries using GetCustomer, that isn't the // column type returned. Instead its string, long, boolean in // concert with a nullable attribute. var columnList = await client.GetColumnListAsync("customer"); // By including every column in the query, we make sure that our // mapper keeps supporting every known type. var columnNames = columnList.Row.Columns.Select(c => new Column(c.Key)).ToArray(); var customer = await client.GetCustomerAsync( "primaryposref = ?", new[] { new ColumnValue("primaryposref", accountNumber) }, columnNames); InferMetaDataToFieldSpecifications(customer.MetaData, columnList.Row.Columns); Assert.Single(customer.Rows); Assert.Equal(accountNumber, customer.Rows[0].Columns["PRIMARYPOSREF"]); return(customer); }
public async Task valid_account_with_single_customer() { const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetCustomer</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""firstname"" type=""string"" nullable=""true""></RSColumn> <RSColumn name=""lastname"" type=""string"" nullable=""true""></RSColumn> </ResultSetMetaData> <Rows> <Row id=""27350""> <Col>George</Col> <Col>Washington</Col> </Row> </Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetCustomerAsync( "primaryposref = ?", new[] { new ColumnValue("primaryposref", "doesNotMatter") }, new[] { new Column("firstname"), new Column("lastname") }); Assert.Equal(2, actual.MetaData.Length); Assert.Single(actual.Rows); var r0 = actual.Rows[0]; Assert.Equal(27350, r0.Id); Assert.Equal("George", r0.Columns["firstname"]); Assert.Equal("Washington", r0.Columns["lastname"]); }