public void ModelFactory_ConvertFrom_RedeemVoucherResponse_NullInput_IsConverted() { ModelFactory modelFactory = new ModelFactory(); IssueVoucherResponse model = null; DataTransferObjects.IssueVoucherResponse dto = modelFactory.ConvertFrom(model); dto.ShouldBeNull(); }
public void ModelFactory_ConvertFrom_IssueVoucherResponse_IsConverted() { ModelFactory modelFactory = new ModelFactory(); IssueVoucherResponse model = TestData.IssueVoucherResponse; DataTransferObjects.IssueVoucherResponse dto = modelFactory.ConvertFrom(model); dto.ShouldNotBeNull(); dto.ExpiryDate.ShouldBe(model.ExpiryDate); dto.Message.ShouldBe(model.Message); dto.VoucherCode.ShouldBe(model.VoucherCode); dto.VoucherId.ShouldBe(model.VoucherId); }
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); }
public async Task VoucherDomainService_IssueVoucher_VoucherIssued() { IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build(); ConfigurationReader.Initialise(configurationRoot); Logger.Initialise(NullLogger.Instance); Mock <IEstateClient> estateClient = new Mock <IEstateClient>(); Mock <ISecurityServiceClient> securityServiceClient = new Mock <ISecurityServiceClient>(); Mock <IAggregateRepository <VoucherAggregate, DomainEventRecord.DomainEvent> > voucherAggregateRepository = new Mock <IAggregateRepository <VoucherAggregate, DomainEventRecord.DomainEvent> >(); voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(new VoucherAggregate()); securityServiceClient.Setup(s => s.GetToken(It.IsAny <String>(), It.IsAny <String>(), It.IsAny <CancellationToken>())).ReturnsAsync(TestData.TokenResponse); estateClient.Setup(e => e.GetEstate(It.IsAny <String>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(TestData.GetEstateResponseWithOperator1); EstateReportingGenericContext context = await this.GetContext(Guid.NewGuid().ToString("N"), TestDatabaseType.InMemory); var dbContextFactory = this.GetMockDbContextFactory(); dbContextFactory.Setup(d => d.GetContext(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(context); VoucherDomainService domainService = new VoucherDomainService(voucherAggregateRepository.Object, securityServiceClient.Object, estateClient.Object, dbContextFactory.Object); IssueVoucherResponse issueVoucherResponse = await domainService.IssueVoucher(TestData.VoucherId, TestData.OperatorIdentifier, TestData.EstateId, TestData.TransactionId, TestData.IssuedDateTime, TestData.Value, TestData.RecipientEmail, TestData.RecipientMobile, CancellationToken.None); issueVoucherResponse.ShouldNotBeNull(); }