public void GiftVouchersCanOnlyBeRedeemedAgainstNonGiftVoucherProducts()
        {
            //Arrange
            var expectedTotal = 30.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat));
            basket.Add(ProductService.Get(ProductService.ProductCode.GiftVoucher));

            var giftVoucher1 = VoucherService.Get("XXX-XXX");
            var giftVoucher2 = VoucherService.Get("XXX-XXX");
            var giftVoucher3 = VoucherService.Get("XXX-XXX");
            var giftVoucher4 = VoucherService.Get("XXX-XXX");
            var giftVoucher5 = VoucherService.Get("XXX-XXX");
            var giftVoucher6 = VoucherService.Get("XXX-XXX");

            //Act
            basket.ApplyVoucher(giftVoucher1);
            basket.ApplyVoucher(giftVoucher2);
            basket.ApplyVoucher(giftVoucher3);
            basket.ApplyVoucher(giftVoucher4);
            basket.ApplyVoucher(giftVoucher5);
            basket.ApplyVoucher(giftVoucher6); //Edge case: sixth voucher should not be applied

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
Exemplo n.º 2
0
 public CheckoutController(ILogger <CheckoutController> log, PaymentService pagamentoService, DiscountService discountService, VoucherService voucherService)
 {
     this.log = log;
     this.pagamentoService = pagamentoService;
     this.discountService  = discountService;
     this.voucherService   = voucherService;
 }
Exemplo n.º 3
0
        public async Task GetVoucher()
        {
            var request  = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
            var response = await VoucherService.GetVoucherAsync(request, 2, "B", 2);

            Assert.IsNotNull(response);
        }
Exemplo n.º 4
0
        public JsonResult GetVoucherByVoucherNumberByCustomer(string voucherNumber, Guid customerId)
        {
            var vouchers =
                VoucherService.QueryVouchersByVoucherNumberByCustomer(GetHttpClient(), voucherNumber, customerId);

            return(Json(vouchers, JsonRequestBehavior.AllowGet));
        }
 public DataBaseSeeder()
 {
     this.countryService = new CountryService();
     this.townService    = new TownService();
     this.hotelService   = new HotelService();
     this.touristService = new TouristService();
     this.voucherService = new VoucherService();
 }
        public JsonResult ApplyDiscount(Opportunity opportunity, Guid voucherId)
        {
            var httpClient = GetHttpClient();
            var success    = OpportunityService.UpdateOpportunity(httpClient, opportunity);

            VoucherService.SetVoucherState(GetService(), voucherId);
            return(Json(success, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 7
0
        public HttpResponseMessage GetReceiptVList(ReceiptPostModel receiptPostModel)
        {
            var result = VoucherService.GetReceiptVList(receiptPostModel);

            return(Request.CreateResponse(HttpStatusCode.OK, new ApplicationResultModel {
                Success = true, Result = result.Result
            }));
        }
Exemplo n.º 8
0
        public async Task GetVouchersTest()
        {
            var request = new VoucherListRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);

            request.SearchParameters[VoucherSearchParameters.FinancialYearDate] = DateTime.UtcNow.ToString("yyyy-MM-dd");
            var voucherList = await VoucherService.GetVouchersAsync(request);

            Assert.IsTrue(voucherList.Data.ToList().Count > 0);
        }
Exemplo n.º 9
0
        public VoucherServiceTests()
        {
            _voucherRepository = new Mock <IVoucherRepository>();
            _voucherService    = new VoucherService(_voucherRepository.Object);

            _voucherRepository.Setup(
                v => v.GetGiftVouchersDeductionAsync(It.IsAny <IEnumerable <string> >()))
            .ReturnsAsync(giftVoucherAmount);
        }
        public void GetPriceWithDiscountShouldThrowExceptionWithInvalidId()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            Assert.Throws <InvalidOperationException>(() => service.GetPriceWithDiscount(35, 10));
        }
        public void CalculatePriceShouldThrowExceptionWithInvalidVoucherId()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            Assert.Throws <InvalidOperationException>(() => service.CalculateTripPrice(50));
        }
        public void GetAllTouristsByHotelShouldThrowExceptionWithNoTouristsInHotel()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            Assert.Throws <InvalidOperationException>(() => service.GetAllTouristsByHotel("Bulgaria", "Sunny Beach", "Kokiche"));
        }
        public void SetUp()
        {
            _voucherRepository = new Mock <IVoucherRepository>();
            _voucherRepository.Setup(x => x.GetAllVouchers()).Returns(() => new Data.Voucher.GetAllVouchersResponse
            {
                VoucherDetails = new List <VoucherDetails>
                {
                    new VoucherDetails
                    {
                        Voucher = new VoucherRecord
                        {
                            Id        = 1,
                            Code      = "SOME_VOUCHER_CODE",
                            Price     = "1200",
                            Quantity  = 2,
                            OnlyNamed = true,
                            Title     = "AWESOME DEAL"
                        },
                        AllowedSizes = new List <VoucherSizeRecord>
                        {
                            new VoucherSizeRecord
                            {
                                Id      = 1,
                                Voucher = new VoucherRecord {
                                    Id = 1
                                },
                                Size = new SizeRecord {
                                    Id = 1
                                }
                            }
                        },
                        AllowedDeliveryTypes = new List <VoucherDeliveryTypeRecord>
                        {
                            new VoucherDeliveryTypeRecord
                            {
                                Id      = 1,
                                Voucher = new VoucherRecord {
                                    Id = 1
                                },
                                DeliveryType = new DeliveryTypeRecord {
                                    Id = 1
                                }
                            }
                        }
                    }
                }
            });

            var subject = new VoucherService(_voucherRepository.Object);

            _result = subject.GetAll();
        }
Exemplo n.º 14
0
        public VouchersController(VoucherInterface voucherRepo, VoucherService voucherService)
        {
            this.voucherService = voucherService;
            this.voucherRepo    = voucherRepo;
            IEnumerable someVoucher = voucherRepo.GetAll();

            newVouchers = new List <VoucherDTO>();
            foreach (Voucher i in someVoucher)
            {
                VoucherDTO newVoucher = new VoucherDTO(i);
                newVouchers.Add(newVoucher);
            }
        }
Exemplo n.º 15
0
        public void SetUp()
        {
            _voucherRepository = new Mock <IVoucherRepository>();
            _voucherRepository.Setup(x => x.GetVoucherById(It.IsAny <int>())).Returns(() => new Data.Voucher.GetVoucherByIdResponse {
                Voucher = new VoucherRecord {
                    Id = 1
                }
            });

            var subject = new VoucherService(_voucherRepository.Object);

            _result = subject.GetById(1);
        }
        public void GetArrivalsByDateShouldThrowExceptionWithNoArrivals()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            DateTime arrivingDate = new DateTime(2019, 01, 31);

            Assert.Throws <InvalidOperationException>(() => service.GetArrtivalsByDate(arrivingDate));
        }
        public void CalculatePriceShouldCalculateTripPrice()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var     service           = new VoucherService(mockContext.Object);
            decimal resultedTripPrice = service.CalculateTripPrice(1);

            decimal expectedTripPrice = 280;

            Assert.AreEqual(expectedTripPrice, resultedTripPrice);
        }
        public void GetAllTouristsByHotelShouldReturnTheTouristsInHotel()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            var tourists = service.GetAllTouristsByHotel("Greece", "Kavala", "Kavala Plaza");

            int expectedTouristsCount = 5;

            Assert.AreEqual(expectedTouristsCount, tourists.Count);
        }
Exemplo n.º 19
0
        public PrintAssemble(PrintTemplateInfo templateInfo, VoucherService service)
        {
            mTemplateInfo = templateInfo;
            SqlParameter[] prams = new SqlParameter[1];
            prams[0] = new SqlParameter("id", mTemplateInfo.id);
            DataSet dataSet = service.RunDataSetProc(mTemplateInfo.procName, prams);

            if (dataSet.Tables.Count > 0)
            {
                mDtHeader = dataSet.Tables[0];
            }
            if (dataSet.Tables.Count > 1)
            {
                mDtEntry = dataSet.Tables[1];
            }
        }
        public void SetUp()
        {
            _voucherRepository = new Mock <IVoucherRepository>();
            _voucherRepository.Setup(x => x.GetAllVouchers()).Returns(() => new GetAllVouchersResponse
            {
                HasError = true,
                Error    = new Error
                {
                    Code = ErrorCodes.DatabaseError
                }
            });

            var subject = new VoucherService(_voucherRepository.Object);

            _result = subject.Verify(new Data.Services.UserSession.Basket(), new List <DeliveryType>(), "VOUCHER_CODE");
        }
        public void GetPriceWithDiscountShouldReturnPriceWithDicountPercent()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            var resultedPrice = service.GetPriceWithDiscount(1, 10);

            decimal expectedPrice = 252M;

            Assert.AreEqual(expectedPrice, resultedPrice);
        }
Exemplo n.º 22
0
        public void SetUp()
        {
            _voucherRepository = new Mock <IVoucherRepository>();
            _voucherRepository.Setup(x => x.GetVoucherById(It.IsAny <int>())).Returns(() => new Data.Voucher.GetVoucherByIdResponse
            {
                HasError = true,
                Error    = new Error
                {
                    Code = ErrorCodes.DatabaseError
                }
            });

            var subject = new VoucherService(_voucherRepository.Object);

            _result = subject.GetById(1);
        }
        public void DiscountCannotBeNegative()
        {
            //Arrange
            var expectedTotal = 0.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.HeadLight));

            var offerVoucher1 = VoucherService.Get("XXX-XXX");

            //Act
            basket.ApplyVoucher(offerVoucher1);

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
        public void GetDeparturesByDateShouldReturnAllDeparturesOnExactDate()
        {
            Mock <DbSet <Voucher> > mockSet = SeedDataBase();

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Vouchers).Returns(mockSet.Object);

            var service = new VoucherService(mockContext.Object);

            DateTime arrivingDate = new DateTime(2019, 08, 13);

            var departures = service.GetDeparturesByDate(arrivingDate);

            decimal expectedDeparturesCount = 2;

            Assert.AreEqual(expectedDeparturesCount, departures.Count);
        }
Exemplo n.º 25
0
        public void Basket1()
        {
            //Arrange
            var expectedTotal = 60.15m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat2));
            basket.Add(ProductService.Get(ProductService.ProductCode.Jumper2));

            var giftVoucher1 = VoucherService.Get("XXX-XXX");

            //Act
            basket.ApplyVoucher(giftVoucher1);

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
Exemplo n.º 26
0
        public void PurchaseOfGiftVouchersDoNotContributeToDiscountableBasketTotal()
        {
            //Arrange
            var expectedTotal = 55.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat));
            basket.Add(ProductService.Get(ProductService.ProductCode.GiftVoucher));

            var offerVoucher1 = VoucherService.Get("ZZZ-ZZZ");

            //Act
            basket.ApplyVoucher(offerVoucher1);

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
Exemplo n.º 27
0
        public void Basket3()
        {
            //Arrange
            var expectedTotal = 51.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat));
            basket.Add(ProductService.Get(ProductService.ProductCode.Jumper));
            basket.Add(ProductService.Get(ProductService.ProductCode.HeadLight));

            var offerVoucher1 = VoucherService.Get("YYY-YYY");

            //Act
            basket.ApplyVoucher(offerVoucher1);

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
        public void CannotApplyTheSameVoucherTwice()
        {
            //Arrange
            var expectedTotal = 46.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat));
            basket.Add(ProductService.Get(ProductService.ProductCode.Jumper));

            var giftVoucher1 = VoucherService.Get("XXX-XXX");

            //Act
            basket.ApplyVoucher(giftVoucher1);
            basket.ApplyVoucher(giftVoucher1);

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
        }
Exemplo n.º 29
0
        private async Task Initialise()
        {
            _voucherService  = new VoucherService();
            _voucherResponse = await _voucherService.GetVouchers();

            var vouchersList = new List <string> {
                "Select Voucher"
            };

            vouchersList.AddRange(_voucherResponse.Select(x => x.Description).ToList());

            var spnVoucher = FindViewById <Spinner>(Resource.Id.spnVoucher);

            spnVoucher.ItemSelected += Voucher_OnSelected;

            var voucherAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, vouchersList);

            voucherAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spnVoucher.Adapter = voucherAdapter;
        }
Exemplo n.º 30
0
        public void Basket5()
        {
            //Arrange
            var expectedTotal = 55.00m;

            var basket = new Basket();

            basket.Add(ProductService.Get(ProductService.ProductCode.Hat));
            basket.Add(ProductService.Get(ProductService.ProductCode.GiftVoucher));

            var offerVoucher1  = VoucherService.Get("ZZZ-ZZZ");
            var expectedReason = new BasketTotalBelowThresholdReason(offerVoucher1, 25.00m);

            //Act
            basket.ApplyVoucher(offerVoucher1);

            //Assert
            Assert.Equal(expectedTotal, basket.DiscountedTotal);
            Assert.Equal(expectedReason.Message, basket.VoucherResults.First().Message);
        }
Exemplo n.º 31
0
 public ActionResult List(PagedParam<VoucherQuery> queryCond)
 {
     var result = new VoucherService().List(queryCond);
     return Json(new AjaxResult("查询成功", AjaxResultType.Success, new { rows = result.ToList(), total = result.TotalItemCount }));
 }
Exemplo n.º 32
0
 public ActionResult GetVoucherDetailsList(int id)
 {
     var result = new VoucherService().GetVoucherDetailByVoucherId(id);
     return Json(new AjaxResult("查询成功", AjaxResultType.Success, new { rows = result, total = result.Count }));
 }
Exemplo n.º 33
0
 public ActionResult GetVoucherById(int id)
 {
     var result= new VoucherService().GetById(id);
     return Json(new AjaxResult("查询成功", AjaxResultType.Success, result));
 }