public void AlertJobsQueue()
        {
            IQueryable <AlertJobsQueue>  AlertJobsQueueCollection = Enumerable.Empty <AlertJobsQueue>().AsQueryable();
            IEnumerable <CollectionItem> CollectionItems          = Enumerable.Empty <CollectionItem>();

            AlertJobsQueue ct = new AlertJobsQueue {
                AlertJobsQueueID = 1, CreatedBy = "Test AlertJobsQueue"
            };

            Mock <IAlertJobsQueueRepository> AlertJobsQueueService = new Mock <IAlertJobsQueueRepository>();



            object obj = new object();

            try
            {
                AlertJobsQueueService.Setup(x => x.GetAll()).Returns(AlertJobsQueueCollection);
                AlertJobsQueueService.Setup(x => x.Get(It.IsAny <int>())).Returns(ct);
                AlertJobsQueueService.Setup(x => x.Add(It.IsAny <AlertJobsQueue>())).Returns(ct);
                AlertJobsQueueService.Setup(x => x.Delete(It.IsAny <AlertJobsQueue>())).Verifiable();
                AlertJobsQueueService.Setup(x => x.Update(It.IsAny <AlertJobsQueue>(), It.IsAny <object>())).Returns(ct);
                AlertJobsQueueService.Setup(x => x.GetAlertDisposition()).Returns(CollectionItems);
                AlertJobsQueueService.Setup(x => x.GetAlertStatus()).Returns(CollectionItems);
                AlertJobsQueueService.Setup(x => x.GetAlertPriority()).Returns(CollectionItems);

                var AlertJobsQueueObject = AlertJobsQueueService.Object;
                var p1 = AlertJobsQueueObject.GetAll();
                var p2 = AlertJobsQueueObject.Get(1);
                var p3 = AlertJobsQueueObject.Update(ct, obj);
                var p4 = AlertJobsQueueObject.Add(ct);
                AlertJobsQueueObject.Delete(ct);
                var p5 = AlertJobsQueueObject.GetAlertDisposition();
                var p6 = AlertJobsQueueObject.GetAlertStatus();
                var p7 = AlertJobsQueueObject.GetAlertPriority();


                Assert.IsAssignableFrom <IQueryable <AlertJobsQueue> >(p1);
                Assert.IsAssignableFrom <AlertJobsQueue>(p2);
                Assert.Equal("Test AlertJobsQueue", p2.CreatedBy);
                Assert.Equal("Test AlertJobsQueue", p3.CreatedBy);
                Assert.IsAssignableFrom <IEnumerable <CollectionItem> >(p5);
                Assert.IsAssignableFrom <IEnumerable <CollectionItem> >(p6);
                Assert.IsAssignableFrom <IEnumerable <CollectionItem> >(p7);

                AlertJobsQueueService.VerifyAll();

                AlertJobsQueueObject.Dispose();
            }
            finally
            {
                AlertJobsQueueService = null;
            }
        }
Exemple #2
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 #3
0
        public IActionResult Create([FromBody] AlertJobsQueueData newmodel)
        {
            if (!ModelState.IsValid)
            {
                { return(NotFound()); }
            }

            if (newmodel.HRToken.Trim() == "")
            {
                { return(NotFound("Invalid Token")); }
            }
            if (newmodel.AlertNames.Count() < 1)
            {
                return(BadRequest("No Alert Names found"));
            }
            if (newmodel.AlertJobsQueue == null)
            {
                return(BadRequest("No Alert Job found"));
            }

            // Check if HR is up
            var hruri      = _configuration.GetSection("HumanReview:uri").Value + "auth/token";
            var hrResponse = Common.ServerStatusBy(hruri);

            // We expect a 400 - Bad Request, anything else specifically 404 Not Found, return an error
            if (hrResponse.StatusCode == 404)
            {
                { return(NotFound("Error: Human Review Service unavailable")); }
            }

            AlertJobsQueue    alertJobQueue = newmodel.AlertJobsQueue;
            List <AlertNames> alertNames    = newmodel.AlertNames;
            ReturnData        retValue      = null;

            int alertJobsQueueID = 0;
            var identity         = alertJobQueue.CreatedBy;

            try
            {
                var returnObject = _context.AlertJobsQueue.Add(alertJobQueue);
                _context.SaveChanges();

                // check id of new Batch contained in alertJobQueue
                alertJobsQueueID = alertJobQueue.AlertJobsQueueID;
                var todayUtc = DateTime.UtcNow;

                foreach (var alertname in alertNames)
                {
                    var newAlertEntity = new AlertJobsQueueEntity();
                    newAlertEntity.AlertNameID      = alertname.AlertNameID;
                    newAlertEntity.AlertJobsQueueID = alertJobsQueueID; // created above
                    newAlertEntity.CreatedBy        = identity;
                    newAlertEntity.UpdatedBy        = identity;
                    newAlertEntity.DateCreatedUTC   = todayUtc;
                    newAlertEntity.LastUpdatedUTC   = todayUtc;
                    newAlertEntity.StatusID         = 26; // Newly Created, based in CollectionItem, CollectionID
                    //newAlertEntity.WorkItemID
                    _context.AlertJobsQueueEntity.Add(newAlertEntity);
                }
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                var loginfo = e.Message;
                ;
            }

            // Human Review
            #region Human Review Entries

            var AlertEntities = _context.AlertJobsQueueEntity.Where(t => t.AlertJobsQueueID == alertJobsQueueID);
            var Modules       = _context.ApplicationModules;
            var QueueGuid     = (from mods in Modules
                                 where mods.ModuleName == "Alerts"
                                 select mods.QueueGuid).FirstOrDefault();
            try
            {
                foreach (var alertentity in AlertEntities)
                {
                    var JsonData = JsonConvert.SerializeObject(alertentity);

                    WorkItemRequest HRCreateRequest = new WorkItemRequest();
                    HRCreateRequest.name                 = "Created WorkItem for Alert Entity " + alertentity.AlertJobsQueueEntityID;
                    HRCreateRequest.description          = "Created WorkItem for Alert Entity " + alertentity.AlertJobsQueueEntityID;
                    HRCreateRequest.queueGuid            = QueueGuid;
                    HRCreateRequest.statusDetailTypeGuid = _configuration.GetSection("HumanReview:statusDetailTypeGuid_ins").Value;
                    HRCreateRequest.reviewTypeGuid       = _configuration.GetSection("HumanReview:reviewTypeGuid_ins").Value;
                    HRCreateRequest.formDefinitionJson   = JsonData;
                    HRCreateRequest.isActive             = true;

                    var returnGuid = Common.getWorkItemAsync(HRCreateRequest, newmodel.HRToken, _configuration);

                    if (returnGuid.value.workItemGuid == null)
                    {
                        var workitemnotcreated = new
                        {
                            Success = false,
                            Message = "WorkItem not created"
                        };



                        return(Json(workitemnotcreated));
                    }

                    alertentity.WorkItemID = new Guid(returnGuid.value.workItemGuid);
                }

                retValue = _context.SaveData();
                if (retValue.Message == "Success")
                {
                    return(Ok(retValue));
                }                        // return error if workitemid was not updated for this entity
            }
            catch (Exception e)
            {
                var loginfo    = e.Message;
                var iactdelete = Delete(alertJobsQueueID);
            }



            #endregion

            { return(BadRequest(retValue)); }
        }