示例#1
0
        public async Task <IActionResult> GetVoucher([FromQuery] String voucherCode,
                                                     [FromQuery] String applicationVersion,
                                                     CancellationToken cancellationToken)
        {
            if (ClaimsHelper.IsPasswordToken(this.User) == false)
            {
                return(this.Forbid());
            }

            // Do the software version check
            try
            {
                VersionCheckRequest versionCheckRequest = VersionCheckRequest.Create(applicationVersion);
                await this.Mediator.Send(versionCheckRequest, cancellationToken);
            }
            catch (VersionIncompatibleException vex)
            {
                Logger.LogError(vex);
                return(this.StatusCode(505));
            }

            Guid estateId   = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "estateId").Value);
            Guid contractId = Guid.Parse(ClaimsHelper.GetUserClaim(this.User, "contractId").Value);

            // Now do the GET
            GetVoucherRequest request = GetVoucherRequest.Create(estateId, contractId, voucherCode);

            GetVoucherResponse response = await this.Mediator.Send(request, cancellationToken);

            return(this.Ok(this.ModelFactory.ConvertFrom(response)));
        }
示例#2
0
        public void GetVoucherRequest_CanBeCreated_IsCreated()
        {
            GetVoucherRequest request = GetVoucherRequest.Create(TestData.EstateId, TestData.ContractId, TestData.VoucherCode);

            request.EstateId.ShouldBe(TestData.EstateId);
            request.ContractId.ShouldBe(TestData.ContractId);
            request.VoucherCode.ShouldBe(TestData.VoucherCode);
        }
        public async Task VoucherRequestHandler_GetVoucherRequest_Handle_RequestIsHandled()
        {
            Mock <IVoucherManagementACLApplicationService> voucherManagementACLApplicationService = new Mock <IVoucherManagementACLApplicationService>();
            VoucherRequestHandler requestHandler = new VoucherRequestHandler(voucherManagementACLApplicationService.Object);

            GetVoucherRequest request = GetVoucherRequest.Create(TestData.EstateId, TestData.ContractId, TestData.VoucherCode);

            Should.NotThrow(async() =>
            {
                await requestHandler.Handle(request, CancellationToken.None);
            });
        }