public async Task report_unconsumed_attribute() { const string response = @" <?xml version=""1.0"" encoding=""UTF-8""?> <SVCMessage hostVersion=""9.1.0000.2301"" version=""1"" posIntfcName=""posInterfaceName"" posIntfcVersion=""1.00"" language=""en-US"" currency=""DKK"" sequence=""0"" retransmit=""n"" newAttribute=""42""> <RequestCode>COUPON_INQUIRY</RequestCode> <TraceID>190826145135N000000</TraceID> <Amount>0.00</Amount> <SVAN>42</SVAN> <AccountCurrency>DKK</AccountCurrency> <ExchangeRate>1.00</ExchangeRate> <ResponseCode>A</ResponseCode> <DisplayMessage>There are no eligible coupons for this card.</DisplayMessage> </SVCMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new PosClient(_messageSequencingStrategy, executor); using (new TimeProviderTestScope(() => DateTime.Parse("2019-08-26T14:51:35"))) { var e = await Assert.ThrowsAsync <OracleHospitalityClientException>(() => sut.CouponInquiryAsync(new AccountNumber("42"))); Assert.Contains(@"<SVCMessage newAttribute=""42"" />", e.InnerException.Message); } }
public async Task invalid_account() { const string response = @" <?xml version=""1.0""?> <SVCMessage language=""en-US"" retransmit=""n"" sequence=""00"" currency=""DKK"" posIntfcVersion=""1.00"" posIntfcName=""posInterfaceName"" version=""1"" hostVersion=""9.1.0000.2301""> <RequestCode>COUPON_INQUIRY</RequestCode> <TraceID>190820113916N000000</TraceID> <Amount>0.00</Amount> <SVAN>123</SVAN> <ResponseCode hostCode=""1"">D</ResponseCode> <DisplayMessage>There is no account number or the account number (123) is too short</DisplayMessage> </SVCMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new PosClient(_messageSequencingStrategy, executor); using (new TimeProviderTestScope(() => DateTime.Parse("2019-08-20T11:39:16"))) { var e = await Assert.ThrowsAsync <OracleHospitalityClientException>( () => sut.CouponInquiryAsync(new AccountNumber("123"))); Assert.Equal("1", e.Code); Assert.Equal("There is no account number or the account number (123) is too short", e.Message); } }
public async Task end_to_end() { // To create a new account, specify a non-existing account number. // Creating an account isn't part of this test because (1) accounts // can never be deleted and (2) we'd have to determine next // available account number prior to creating the account. var accountNumber = new AccountNumber("2200000"); var client = new PosClient(_messageSequencingStrategy, _executor); var pointIssue = await client.PointIssueAsync(accountNumber); var couponInquiry = await client.CouponInquiryAsync(pointIssue.AccountNumber); var couponCode = new CouponCode("10DKK"); var couponIssue = await client.CouponIssueAsync(accountNumber, couponCode); var couponAccept = await client.CouponAcceptAsync(accountNumber, couponIssue.CouponCode); }
public async Task with_both_unconsumed_element_and_backend_reporting_error_unconsumed_exception_takes_precedence() { // Only check ResponseCode and throw exception after validating // every element and attribute. Otherwise, we miss the opportunity // to catch responses of unanticipated forms. const string response = @" <?xml version=""1.0"" encoding=""UTF-8""?> <SVCMessage hostVersion=""9.1.0000.2301"" version=""1"" posIntfcName=""posInterfaceName"" posIntfcVersion=""1.00"" language=""en-US"" currency=""DKK"" sequence=""0"" retransmit=""n""> <RequestCode>COUPON_INQUIRY</RequestCode> <TraceID>190826145135N000000</TraceID> <Amount>0.00</Amount> <SVAN>42</SVAN> <ResponseCode hostCode=""93"">D</ResponseCode> <DisplayMessage>Coupon (NotExist) cannot be found</DisplayMessage> <NewElement>42</NewElement> </SVCMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new PosClient(_messageSequencingStrategy, executor); using (new TimeProviderTestScope(() => DateTime.Parse("2019-08-26T14:51:35"))) { var e = await Assert.ThrowsAsync <OracleHospitalityClientException>(() => sut.CouponInquiryAsync(new AccountNumber("42"))); Assert.Contains( "<SVCMessage><NewElement>42</NewElement></SVCMessage>", e.InnerException.Message.Replace(Environment.NewLine, "").Replace(" ", "")); } }
public async Task valid_account_with_two_coupons() { const string response = @" <SVCMessage hostVersion=""9.1.0000.2301"" version=""1"" posIntfcName=""posInterfaceName"" posIntfcVersion=""1.00"" language=""en-US"" currency=""DKK"" sequence=""00"" retransmit=""n""> <RequestCode>COUPON_INQUIRY</RequestCode> <TraceID>190826145135N000000</TraceID> <Amount>0.00</Amount> <SVAN>123</SVAN> <AccountCurrency>DKK</AccountCurrency> <ExchangeRate>1.00</ExchangeRate> <ResponseCode>A</ResponseCode> <Actions> <Action> <Type tid=""12"">Accept Coupon</Type> <Data pid=""9"">1005016</Data> <Code>10DKK</Code> <Text>Coupon: 10 DKK, Always Valid</Text> </Action> <Action> <Type tid=""12"">Accept Coupon</Type> <Data pid=""9"">1006014</Data> <Code>10DKK</Code> <Text>Coupon: 10 DKK, Always Valid</Text> </Action> </Actions> <PrintLines/> <DisplayMessage>There are 2 eligible coupons for this card.</DisplayMessage> </SVCMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new PosClient(_messageSequencingStrategy, executor); using (new TimeProviderTestScope(() => DateTime.Parse("2019-08-26T14:51:35"))) { var actual = await sut.CouponInquiryAsync(new AccountNumber("123")); Assert.Equal("There are 2 eligible coupons for this card.", actual.DisplayMessage.Value); Assert.Equal(2, actual.Actions.Count); var a = actual.Actions[0]; AssertAction( a, ActionType.TransactionId.AcceptCoupon, ActionData.PromptId.PleaseEnterCoupon, "1005016", "10DKK", "Coupon: 10 DKK, Always Valid"); var b = actual.Actions[1]; AssertAction( b, ActionType.TransactionId.AcceptCoupon, ActionData.PromptId.PleaseEnterCoupon, "1006014", "10DKK", "Coupon: 10 DKK, Always Valid"); } }
public async Task valid_account_with_one_coupon() { var response = @" <SVCMessage hostVersion=""9.1.0000.2301"" version=""1"" posIntfcName=""posInterfaceName"" posIntfcVersion=""1.00"" language=""en-US"" currency=""DKK"" sequence=""00"" retransmit=""n""> <RequestCode>COUPON_INQUIRY</RequestCode> <TraceID>190826145135N000000</TraceID> <Amount>0.00</Amount> <SVAN>123</SVAN> <AccountCurrency>DKK</AccountCurrency> <ExchangeRate>1.00</ExchangeRate> <ResponseCode>A</ResponseCode> <Actions> <Action> <Type tid=""12"">Accept Coupon</Type> <Data pid=""9"">1004019</Data> <Code>10DKK</Code> <Text>Coupon: 10 DKK, Always Valid</Text> </Action> </Actions> <PrintLines /> <DisplayMessage>There is an eligible coupon for this card.</DisplayMessage> </SVCMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new PosClient(_messageSequencingStrategy, executor); using (new TimeProviderTestScope(() => DateTime.Parse("2019-08-26T14:51:35"))) { var actual = await sut.CouponInquiryAsync(new AccountNumber("123")); // Attributes Assert.Equal("9.1.0000.2301", actual.HostVersion.Value); Assert.Equal("1", actual.Version.Value); Assert.Equal("posInterfaceName", actual.PosInterfaceName.Value); Assert.Equal("en-US", actual.Language.Value); Assert.Equal(Currency.Kind.DKK, actual.Currency.Value); Assert.Equal(0, actual.SequenceNumber.Value); Assert.Equal(Transmission.Kind.Normal, actual.Transmission.Value); // Elements Assert.Equal(TransactionKind.COUPON_INQUIRY, actual.RequestCode.Value); Assert.Equal("190826145135N000000", actual.TraceId.ToString()); Assert.Equal(0, actual.Amount.Value); Assert.Equal("123", actual.AccountNumber.Value); Assert.Equal(Currency.Kind.DKK, actual.AccountCurrency.Value); Assert.Equal(1.00m, actual.ExchangeRate.Value); Assert.Equal(ResponseCode.Kind.Approved, actual.ResponseCode.Value); Assert.Single(actual.Actions); var action = actual.Actions[0]; AssertAction( action, ActionType.TransactionId.AcceptCoupon, ActionData.PromptId.PleaseEnterCoupon, "1004019", "10DKK", "Coupon: 10 DKK, Always Valid"); Assert.Empty(actual.PrintLines.Values); Assert.Equal("There is an eligible coupon for this card.", actual.DisplayMessage.Value); } }