Esempio n. 1
0
        public void AlertWorkers()
        {
            ILogger <AlertWorkersController> _testlogger = null;

            using (var context = new AppDbContext(options, null))
            {
                var controller = new AlertWorkersController(context, _testlogger);
                // Get all
                var result = controller.Get();
                // Assert
                var okResult = Assert.IsAssignableFrom <IEnumerable <AlertWorkers> >(result);
                var pgcount  = okResult.ToList().Count;
                Assert.Equal(2, pgcount);
                // Get by ID
                var result1   = controller.Get(1);
                var okResult1 = Assert.IsAssignableFrom <AlertWorkers>(result1);
                Assert.Equal("user1", okResult1.CreatedBy);
                // test update
                var pg1 = new AlertWorkers {
                    AlertWorkersID = 1, CreatedBy = "user1 upd"
                };
                controller.UpdateEntry(pg1);
                var result3 = controller.Get(1);
                Assert.NotEqual("user1", result3.CreatedBy);
                Assert.Equal("user1 upd", result3.CreatedBy);
                // test delete
                var result4 = controller.Get(2);
                Assert.Equal("user1", result4.CreatedBy);

                var result5    = controller.Delete(2);
                var viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5);
                var result6    = controller.Get(2);
                Assert.Null(result6);
            }
        }
Esempio n. 2
0
        public IActionResult Create([FromBody] AlertWorkers newmodel)
        {
            if (ModelState.IsValid)
            {
                _context.AlertWorkers.Add(newmodel);
                _context.SaveChanges();

                return(CreatedAtRoute("GetAlertWorkers", new { id = newmodel.AlertWorkersID }, newmodel));
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 3
0
        public IActionResult UpdateEntry([FromBody] AlertWorkers objupd)
        {
            var targetObject = _context.AlertWorkers.FirstOrDefault(t => t.AlertWorkersID == objupd.AlertWorkersID);

            if (targetObject == null)
            {
                return(NotFound());
            }

            _context.Entry(targetObject).CurrentValues.SetValues(objupd);
            ReturnData ret;

            ret = _context.SaveData();

            if (ret.Message == "Success")
            {
                return(Ok());
            }

            return(NotFound(ret));
        }
Esempio n. 4
0
        public void AlertWorkers()
        {
            IQueryable <AlertWorkers> AlertWorkersCollection = Enumerable.Empty <AlertWorkers>().AsQueryable();
            AlertWorkers ct = new AlertWorkers {
                AlertWorkersID = 1, CreatedBy = "Test AlertWorkers"
            };

            Mock <IAlertWorkersRepository> AlertWorkersService = new Mock <IAlertWorkersRepository>();

            object obj = new object();

            try
            {
                AlertWorkersService.Setup(x => x.GetAll()).Returns(AlertWorkersCollection);
                AlertWorkersService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct);
                AlertWorkersService.Setup(x => x.Add(It.IsAny <AlertWorkers>())).Returns(ct);
                AlertWorkersService.Setup(x => x.Delete(It.IsAny <AlertWorkers>())).Verifiable();
                AlertWorkersService.Setup(x => x.Update(It.IsAny <AlertWorkers>(), It.IsAny <object>())).Returns(ct);

                var AlertWorkersObject = AlertWorkersService.Object;
                var p1 = AlertWorkersObject.GetAll();
                var p2 = AlertWorkersObject.Get(1);
                var p3 = AlertWorkersObject.Update(ct, obj);
                var p4 = AlertWorkersObject.Add(ct);
                AlertWorkersObject.Delete(ct);

                Assert.IsAssignableFrom <IQueryable <AlertWorkers> >(p1);
                Assert.IsAssignableFrom <AlertWorkers>(p2);
                Assert.Equal("Test AlertWorkers", p2.CreatedBy);
                Assert.Equal("Test AlertWorkers", p3.CreatedBy);

                AlertWorkersService.VerifyAll();

                AlertWorkersObject.Dispose();
            }
            finally
            {
                AlertWorkersService = null;
            }
        }
Esempio n. 5
0
        internal void PopulateData()
        {
            using (var context = new AppDbContext(options, null))
            {
                if (context.AlertJobs.Count() < 1)
                {
                    var p1 = new AlertJobs {
                        AlertJobsID = 1, CreatedBy = "user1",
                    };
                    var p2 = new AlertJobs {
                        AlertJobsID = 2, CreatedBy = "user1",
                    };
                    context.AlertJobs.Add(p1);
                    context.AlertJobs.Add(p2);

                    context.SaveChanges();
                }

                if (context.AlertSchedules.Count() < 1)
                {
                    var p1 = new AlertSchedules {
                        AlertSchedulesId = 1, CreatedBy = "user1",
                    };
                    var p2 = new AlertSchedules {
                        AlertSchedulesId = 2, CreatedBy = "user1",
                    };
                    context.AlertSchedules.Add(p1);
                    context.AlertSchedules.Add(p2);

                    context.SaveChanges();
                }

                if (context.AlertScheduleType.Count() < 1)
                {
                    var p1 = new AlertScheduleType {
                        AlertScheduleTypeID = 1, CreatedBy = "user1",
                    };
                    var p2 = new AlertScheduleType {
                        AlertScheduleTypeID = 2, CreatedBy = "user1",
                    };
                    context.AlertScheduleType.Add(p1);
                    context.AlertScheduleType.Add(p2);

                    context.SaveChanges();
                }

                if (context.AlertSourceType.Count() < 1)
                {
                    var p1 = new AlertSourceType {
                        AlertSourceTypeID = 1, CreatedBy = "user1",
                    };
                    var p2 = new AlertSourceType {
                        AlertSourceTypeID = 2, CreatedBy = "user1",
                    };
                    context.AlertSourceType.Add(p1);
                    context.AlertSourceType.Add(p2);

                    context.SaveChanges();
                }

                if (context.AlertWorkers.Count() < 1)
                {
                    var p1 = new AlertWorkers {
                        AlertWorkersID = 1, CreatedBy = "user1",
                    };
                    var p2 = new AlertWorkers {
                        AlertWorkersID = 2, CreatedBy = "user1",
                    };
                    context.AlertWorkers.Add(p1);
                    context.AlertWorkers.Add(p2);

                    context.SaveChanges();
                }

                if (context.Encoding.Count() < 1)
                {
                    var p1 = new Encoding {
                        EncodingID = 1, CreatedBy = "user1",
                    };
                    var p2 = new Encoding {
                        EncodingID = 2, CreatedBy = "user1",
                    };
                    context.Encoding.Add(p1);
                    context.Encoding.Add(p2);

                    context.SaveChanges();
                }
            }
        }
        public IActionResult Update([FromBody] AlertWorkers editentry)
        {
            var result = _repository.Update(editentry, editentry.AlertWorkersID);

            return(Helper.CheckResult(result));
        }
        public IActionResult Create([FromBody] AlertWorkers newentry)
        {
            var result = _repository.Add(newentry);

            return(Helper.CheckResult(result));
        }