public async Task <IActionResult> IssueVoucher(IssueVoucherRequest issueVoucherRequest, CancellationToken cancellationToken) { // Reject password tokens if (ClaimsHelper.IsPasswordToken(this.User)) { return(this.Forbid()); } Guid voucherId = Guid.NewGuid(); DateTime issuedDateTime = issueVoucherRequest.IssuedDateTime.HasValue ? issueVoucherRequest.IssuedDateTime.Value : DateTime.Now; BusinessLogic.Requests.IssueVoucherRequest request = BusinessLogic.Requests.IssueVoucherRequest.Create(voucherId, issueVoucherRequest.OperatorIdentifier, issueVoucherRequest.EstateId, issueVoucherRequest.TransactionId, issuedDateTime, issueVoucherRequest.Value, issueVoucherRequest.RecipientEmail, issueVoucherRequest.RecipientMobile); IssueVoucherResponse response = await this.Mediator.Send(request, cancellationToken); // TODO: Populate the GET route return(this.Created("", this.ModelFactory.ConvertFrom(response))); }
public async Task VoucherManagementRequestHandler_IssueVoucherRequest_IsHandled() { Mock <IVoucherDomainService> voucherDomainService = new Mock <IVoucherDomainService>(); voucherDomainService.Setup(v => v.IssueVoucher(It.IsAny <Guid>(), It.IsAny <String>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <Decimal>(), It.IsAny <String>(), It.IsAny <String>(), It.IsAny <CancellationToken>())).ReturnsAsync(TestData.IssueVoucherResponse); VoucherManagementRequestHandler handler = new VoucherManagementRequestHandler(voucherDomainService.Object); IssueVoucherRequest command = TestData.IssueVoucherRequest; Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); }); }
public void IssueVoucherRequest_CanBeCreated_IsCreated() { IssueVoucherRequest issueVoucherRequest = IssueVoucherRequest.Create(TestData.VoucherId, TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.IssuedDateTime, TestData.Value, TestData.RecipientEmail, TestData.RecipientMobile); issueVoucherRequest.ShouldNotBeNull(); issueVoucherRequest.VoucherId.ShouldBe(TestData.VoucherId); issueVoucherRequest.OperatorIdentifier.ShouldBe(TestData.OperatorIdentifier); issueVoucherRequest.EstateId.ShouldBe(TestData.EstateId); issueVoucherRequest.TransactionId.ShouldBe(TestData.TransactionId); issueVoucherRequest.Value.ShouldBe(TestData.Value); issueVoucherRequest.RecipientEmail.ShouldBe(TestData.RecipientEmail); issueVoucherRequest.RecipientMobile.ShouldBe(TestData.RecipientMobile); issueVoucherRequest.IssuedDateTime.ShouldBe(TestData.IssuedDateTime); }
public async Task WhenIIssueTheFollowingVouchers(Table table) { foreach (TableRow tableRow in table.Rows) { EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); IssueVoucherRequest request = new IssueVoucherRequest { Value = SpecflowTableHelper.GetDecimalValue(tableRow, "Value"), RecipientEmail = SpecflowTableHelper.GetStringRowValue(tableRow, "RecipientEmail"), RecipientMobile = SpecflowTableHelper.GetStringRowValue(tableRow, "RecipientMobile"), EstateId = estateDetails.EstateId, OperatorIdentifier = SpecflowTableHelper.GetStringRowValue(tableRow, "OperatorName"), TransactionId = Guid.Parse(SpecflowTableHelper.GetStringRowValue(tableRow, "TransactionId")) }; IssueVoucherResponse response = await this.TestingContext.DockerHelper.VoucherManagementClient.IssueVoucher(this.TestingContext.AccessToken, request, CancellationToken.None) .ConfigureAwait(false); response.VoucherId.ShouldNotBe(Guid.Empty); await Retry.For(async() => { var v = await this.TestingContext.DockerHelper.VoucherManagementClient .GetVoucher(this.TestingContext.AccessToken, estateDetails.EstateId, response.VoucherCode, CancellationToken.None) .ConfigureAwait(false); v.ShouldNotBeNull(); }); estateDetails.AddVoucher(request.OperatorIdentifier, request.Value, request.TransactionId, response.VoucherCode, response.VoucherId); } }
/// <summary> /// Issues the voucher. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="issueVoucherRequest">The issue voucher request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <IssueVoucherResponse> IssueVoucher(String accessToken, IssueVoucherRequest issueVoucherRequest, CancellationToken cancellationToken) { IssueVoucherResponse response = null; String requestUri = $"{this.BaseAddress}/api/vouchers"; try { String requestSerialised = JsonConvert.SerializeObject(issueVoucherRequest); StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json"); // Add the access token to the client headers this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object response = JsonConvert.DeserializeObject <IssueVoucherResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception("Error issuing voucher.", ex); throw exception; } return(response); }