Ejemplo n.º 1
0
        public ActionResult CreateForProductLocation(Voucher voucher)
        {
            voucher.Used         = false;
            voucher.DateInserted = DateTime.Now;


            int ProductInGameID = db.ProductLocations.Find(voucher.ProductLocationID).ProductInGameID;

            VoucherValidator validator = new VoucherValidator();

            if (ModelState.IsValid && validator.Validate(voucher).IsValid)
            {
                db.Vouchers.Add(voucher);
                db.SaveChanges();
                return(RedirectToAction("EditFromProductInGame", "ProductLocations", new { id = voucher.ProductLocationID, productInGameID = ProductInGameID }));
            }


            FluentValidation.Results.ValidationResult results = validator.Validate(voucher);
            IList <ValidationFailure> failures = results.Errors;
            StringBuilder             sb       = new StringBuilder();

            foreach (var e in results.Errors)
            {
                ModelState.AddModelError(e.PropertyName + "Error", e.ErrorMessage);
                sb.AppendLine(e.ErrorMessage);
            }


            ViewBag.ProductLocationID = voucher.ProductLocationID;
            return(View(voucher));
        }
Ejemplo n.º 2
0
        public void Validate_ShouldReturnInvalidVouchers()
        {
            var voucher  = new OfferVoucher(5, 50);
            var products = new[] { new Product(50) };
            var vouchers = new[] { voucher };
            var invalid  = new[] { new InvalidVoucherDecorator(voucher, "") };

            _validationRule.Setup(o => o.Validate(products, vouchers)).Returns(invalid);

            var result = _validator.Validate(products, vouchers);

            result.invalidVouchers.Should().HaveCount(1);
            result.validVouchers.Should().HaveCount(0);

            result.invalidVouchers.Should().Contain(invalid);
        }
Ejemplo n.º 3
0
        public void SumVoucherNotEqualsVoucherDetailsSumIsNotValid()
        {
            var details = data.CurrentVoucher.Details;

            details.Add(new VoucherDetail {
                VoucherID = data.CurrentVoucher.ID, Text = "USB Stick", Amount = 22, AccountID = 1
            });
            Assert.Equal(VoucherValidator.Validate(data.CurrentVoucher, details.ToArray(), data.Accounts.ToArray()), false);
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "VoucherID,VoucherNumber,ProductLocationID,Used,DateInserted,DateUsed")] Voucher voucher)
        {
            VoucherValidator validator = new VoucherValidator();

            if (ModelState.IsValid && validator.Validate(voucher).IsValid)
            {
                db.Vouchers.Add(voucher);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductLocationID = new SelectList(db.ProductLocations, "ProductLocationID", "USR", voucher.ProductLocationID);
            return(View(voucher));
        }
Ejemplo n.º 5
0
        public ActionResult EditFromProductInGameMakeGame(ProductLocationViewModel plvm)
        {
            int GameID = db.ProductInGames.Find(plvm.ProductLocation.ProductInGameID).GameID;

            if (ModelState.IsValid)
            {
                db.Entry(plvm.ProductLocation).State = EntityState.Modified;

                foreach (var s in plvm.ProductLocation.SerialNumbers)
                {
                    SerialNumberValidator validator = new SerialNumberValidator();

                    FluentValidation.Results.ValidationResult results = validator.Validate(s);
                    IList <ValidationFailure> failures = results.Errors;
                    StringBuilder             sb       = new StringBuilder();
                    foreach (var e in results.Errors)
                    {
                        ModelState.AddModelError(e.PropertyName + "Error", e.ErrorMessage);
                        sb.AppendLine(e.ErrorMessage);
                    }
                    if (ModelState.IsValid)
                    {
                        db.Entry(s).State = EntityState.Modified;
                    }
                    else
                    {
                        ViewBag.ProductInGameID            = plvm.ProductLocation.ProductInGameID;
                        plvm.ProductLocation.ProductInGame = db.ProductInGames.Find(plvm.ProductLocation.ProductInGameID);
                        return(View(plvm));
                    }
                }
                foreach (var v in plvm.ProductLocation.Vouchers)
                {
                    VoucherValidator validator = new VoucherValidator();

                    FluentValidation.Results.ValidationResult results = validator.Validate(v);
                    IList <ValidationFailure> failures = results.Errors;
                    StringBuilder             sb       = new StringBuilder();
                    foreach (var e in results.Errors)
                    {
                        ModelState.AddModelError(e.PropertyName + "Error", e.ErrorMessage);
                        sb.AppendLine(e.ErrorMessage);
                    }


                    if (ModelState.IsValid)
                    {
                        db.Entry(v).State = EntityState.Modified;
                    }
                    else
                    {
                        ViewBag.ProductInGameID            = plvm.ProductLocation.ProductInGameID;
                        plvm.ProductLocation.ProductInGame = db.ProductInGames.Find(plvm.ProductLocation.ProductInGameID);
                        return(View(plvm));
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("EditMakeGame", "Games", new { id = GameID }));
            }
            ViewBag.ProductInGameID = plvm.ProductLocation.ProductInGameID;
            return(View(plvm));
        }
Ejemplo n.º 6
0
 public void VoucherWithDetailsNullNotValid()
 {
     Assert.Equal(VoucherValidator.Validate(data.CurrentVoucher, null, data.Accounts.ToArray()), false);
 }
Ejemplo n.º 7
0
 public void VoucherNullIsNotValid()
 {
     Assert.Equal(VoucherValidator.Validate(null, data.CurrentVoucher.Details.ToArray(), data.Accounts.ToArray()), false);
 }
Ejemplo n.º 8
0
 public void SumVoucherEqualsVoucherDetailsSum()
 {
     Assert.Equal(VoucherValidator.Validate(data.CurrentVoucher, data.CurrentVoucher.Details.ToArray(), data.Accounts.ToArray()), true);
 }