Esempio n. 1
0
        public JsonResult Salvar(SeguroModel model)
        {
            Result result = new Result();

            try
            {
                var service = new SeguroService(new Business.DBContext());
                if (model.ID == 0)
                {
                    service.Insert(model);
                }
                else
                {
                    service.Update(model);
                }

                result.setSuccess();
            }
            catch (Exception ex)
            {
                result.setError(ex.Message);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public void Seguro_CriarNovo()
        {
            var data = _dataSource.AsQueryable();

            var mock = new Mock <DbSet <Seguro> >();

            mock.As <IQueryable <Seguro> >().Setup(m => m.Provider).Returns(data.Provider);
            mock.As <IQueryable <Seguro> >().Setup(m => m.Expression).Returns(data.Expression);
            mock.As <IQueryable <Seguro> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mock.As <IQueryable <Seguro> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            mock.Object.AddRange(data);
            var mockContext = new Mock <DBContext>();

            mockContext.Setup(m => m.Seguro).Returns(mock.Object);

            var service = new SeguroService(mockContext.Object);

            service.Insert(new SeguroModel()
            {
                IDTipo = 4, CPFCNPJ = "123123123-12", Placa = "AYB5757"
            });

            mock.Verify(m => m.Add(It.IsAny <Seguro>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
 public IActionResult CreateSeguro(Seguro seguro)
 {
     _seguroService.Insert(seguro);
     return(RedirectToAction(nameof(Index)));
 }