Exemple #1
0
        public void AlertJobs()
        {
            ILogger <AlertJobsController> _testlogger = null;

            using (var context = new AppDbContext(options, null))
            {
                var controller = new AlertJobsController(context, _testlogger, null);
                // Get all
                var result = controller.Get();
                // Assert
                var okResult = Assert.IsAssignableFrom <IEnumerable <AlertJobs> >(result);
                var pgcount  = okResult.ToList().Count;
                Assert.Equal(2, pgcount);
                // Get by ID
                var result1   = controller.Get(1);
                var okResult1 = Assert.IsAssignableFrom <AlertJobs>(result1);
                Assert.Equal("user1", okResult1.CreatedBy);
                // test update
                var pg1 = new AlertJobs {
                    AlertJobsID = 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);
            }
        }
Exemple #2
0
        public IActionResult Create([FromBody] AlertJobs newmodel)
        {
            if (ModelState.IsValid)
            {
                _context.AlertJobs.Add(newmodel);
                _context.SaveChanges();

                return(CreatedAtRoute("GetAlertJobs", new { id = newmodel.AlertJobsID }, newmodel));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemple #3
0
        internal void PopulateData()
        {
            using (var context = new AppDbContext(options, null))
            {
                if (context.AlertJobs.Count() < 1)
                {
                    var p1 = new AlertJobs {
                        AlertJobsID = 1, JobName = "AlertJobs 1"
                    };
                    var p2 = new AlertJobs {
                        AlertJobsID = 2, JobName = "AlertJobs 2"
                    };
                    context.AlertJobs.Add(p1);
                    context.AlertJobs.Add(p2);

                    context.SaveChanges();
                }

                if (context.AlertNames.Count() < 1)
                {
                    var p1 = new AlertNames {
                        AlertNameID = 1, NameEntry = "AlertNames 1", AlertJobsID = 1
                    };
                    var p2 = new AlertNames {
                        AlertNameID = 2, NameEntry = "AlertNames 2", AlertJobsID = 2
                    };
                    context.AlertNames.Add(p1);
                    context.AlertNames.Add(p2);

                    context.SaveChanges();
                }

                if (context.AlertJobsQueue.Count() < 1)
                {
                    var p1 = new AlertJobsQueue {
                        AlertJobsQueueID = 1, CreatedBy = "6", StatusCollectionItemID = 1047
                    };
                    var p2 = new AlertJobsQueue {
                        AlertJobsQueueID = 2, CreatedBy = "6", StatusCollectionItemID = 1047
                    };
                    context.AlertJobsQueue.Add(p1);
                    context.AlertJobsQueue.Add(p2);

                    context.SaveChanges();
                }
            }
        }
Exemple #4
0
        public IActionResult UpdateEntry([FromBody] AlertJobs objupd)
        {
            var targetObject = _context.AlertJobs.FirstOrDefault(t => t.AlertJobsID == objupd.AlertJobsID);

            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));
        }
Exemple #5
0
        public void AlertJobs()
        {
            IQueryable <AlertJobs> AlertJobsCollection = Enumerable.Empty <AlertJobs>().AsQueryable();
            AlertJobs ct = new AlertJobs {
                AlertJobsID = 1, JobName = "Test AlertJobs"
            };

            Mock <IAlertJobsRepository> AlertJobsService = new Mock <IAlertJobsRepository>();

            object obj = new object();

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

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

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

                AlertJobsService.VerifyAll();

                AlertJobsObject.Dispose();
            }
            finally
            {
                AlertJobsService = null;
            }
        }
        public IActionResult Update([FromBody] AlertJobs editentry)
        {
            var result = _repository.Update(editentry, editentry.AlertJobsID);

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

            return(Helper.CheckResult(result));
        }
Exemple #8
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();
                }
            }
        }