public void Test_GetList()
        {
            ScanBLL bll   = new ScanBLL(_unit);
            var     sList = bll.GetList();

            Assert.IsTrue(sList.Count() > 0);
        }
Esempio n. 2
0
        public void TestRunScan()
        {
            ScanBLL sBLL = new ScanBLL(_unit);

            var s = sBLL.GetList().ToArray()[0];

            _bll.RunScan(s);
        }
        public void Test_Delete()
        {
            ScanBLL bll   = new ScanBLL(_unit);
            var     sList = bll.GetList();

            var s = sList.ToArray()[0];

            bll.Delete(s.Id);
        }
        public void Test_Update()
        {
            ScanBLL bll   = new ScanBLL(_unit);
            var     sList = bll.GetList();

            var s = sList.ToArray()[0];

            s.Description = "updated description...";

            bll.Update(s);
        }
        public void Test_Create()
        {
            ScanBLL bll = new ScanBLL(_unit);

            Scan s = new Scan
            {
                Owner = "2b658482-6a38-4ed3-b356-77fe9b1569f1",
                //ShareId = 1585,
                IsActive    = true,
                IsSystem    = false,
                RuleId      = 4,
                StartDate   = 20160101,
                EndDate     = 20160501,
                Name        = "test scan",
                Description = "test scan description"
            };

            bll.Create(s);
        }
        public async Task <IHttpActionResult> Get(int id)
        {
            Scan s = null;

            try
            {
                var currentUser = await base.GetCurrentUser();

                ScanBLL bll = new ScanBLL(_unit);

                s = bll.GetByID(id);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(s));
        }
        public async Task <IHttpActionResult> Get()
        {
            List <Scan> slist = null;

            try
            {
                var currentUser = await base.GetCurrentUser();

                ScanBLL bll = new ScanBLL(_unit);

                slist = bll.GetList().ToList();
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(slist));
        }
        public async Task <IHttpActionResult> Run(int id)
        {
            List <ScanResult> mlist = null;

            try
            {
                ScanBLL bll = new ScanBLL(_unit);

                var scan = bll.GetByID(id);

                mlist = new ScanCalculator(_unit).RunScan(scan);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(mlist));
        }
        public async Task <IHttpActionResult> Delete(int id)
        {
            try
            {
                var currentUser = await GetCurrentUser();

                ScanBLL bll = new ScanBLL(_unit);

                bool isAdmin = await AppUserManager.IsInRoleAsync(currentUser.Id, "Admin");

                if (isAdmin)
                {
                    bll.Delete(id);
                }
                else
                {
                    var w = bll.GetByID(id);

                    if (w.Owner == currentUser.Id)
                    {
                        bll.Delete(id);
                    }
                    else
                    {
                        BadRequest("You don't have permission to delete this scan.");
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok());
        }