public void Add_EmptyCode_ErrorResult()
        {
            var emptyCode = new CodeViewModel();

            mockUnitOfWork.Setup(m => m.Codes.Get(It.IsAny <Expression <Func <Code, bool> > >(), It.IsAny <Func <IQueryable <Code>,
                                                                                                                 IOrderedQueryable <Code> > >(), It.IsAny <string>()))
            .Returns(new List <Code>());
            mockUnitOfWork.Setup(m => m.Save());

            var result = manager.Add(emptyCode);

            TestContext.WriteLine(result.Details);
            Assert.That(result.Success, Is.False);
        }
        public static void SeedOperators(IOperatorManager operatorManager, ICodeManager codeManager, ITariffManager tariffManager)
        {
            if (operatorManager.GetByName("Vodafone") == null)
            {
                OperatorViewModel oper1 = new OperatorViewModel();
                oper1.Name = "Vodafone";
                operatorManager.Add(oper1);
                oper1 = operatorManager.GetByName("Vodafone");

                CodeViewModel code1 = new CodeViewModel()
                {
                    OperatorId = oper1.Id, OperatorCode = "+38099"
                };
                CodeViewModel code2 = new CodeViewModel()
                {
                    OperatorId = oper1.Id, OperatorCode = "+38066"
                };
                CodeViewModel code3 = new CodeViewModel()
                {
                    OperatorId = oper1.Id, OperatorCode = "+38050"
                };

                codeManager.Add(code1);
                codeManager.Add(code2);
                codeManager.Add(code3);

                SeedTariffs(tariffManager, oper1.Id);
            }

            if (operatorManager.GetByName("Kyivstar") == null)
            {
                OperatorViewModel oper2 = new OperatorViewModel();
                oper2.Name = "Kyivstar";
                operatorManager.Add(oper2);
                oper2 = operatorManager.GetByName("Kyivstar");

                CodeViewModel code4 = new CodeViewModel()
                {
                    OperatorId = oper2.Id, OperatorCode = "+38097"
                };
                CodeViewModel code5 = new CodeViewModel()
                {
                    OperatorId = oper2.Id, OperatorCode = "+38067"
                };
                CodeViewModel code6 = new CodeViewModel()
                {
                    OperatorId = oper2.Id, OperatorCode = "+38096"
                };

                codeManager.Add(code4);
                codeManager.Add(code5);
                codeManager.Add(code6);

                SeedTariffs(tariffManager, oper2.Id);
            }
        }
Beispiel #3
0
 public IActionResult Codes(CodeViewModel newCode, PageState pageState)
 {
     if (ModelState.IsValid)
     {
         newCode.OperatorId = pageState.OperatorId;
         var result = codeManager.Add(newCode);
         if (!result.Success)
         {
             TempData["ErrorMessage"] = result.Details;
             return(Redirect(Url.Action("Codes", pageState)));
         }
         else
         {
             return(Redirect(Url.Action("Codes", pageState)));
         }
     }
     TempData["ErrorMessage"] = "Internal error";
     return(RedirectToAction("Operators", "Operator"));
 }