public void ChecklistsController_Put_Returns_NotFoundResponseCode(int dealnumber, int checklistnum, int chkstatus, ChkCategoryTree checklist)
        {
            #region Arrange
            SetupUserIdentity();

            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}/{dealnumber}/checklists/{checklistnum}");

            Mock <ITblCheckListRepository> checkListRepository = new Mock <ITblCheckListRepository>();

            IList <grs_VGrsChecklistsByDeal> data = new List <grs_VGrsChecklistsByDeal>
            {
                new grs_VGrsChecklistsByDeal
                {
                    Dealnum       = 1392041,
                    Entitynum     = 1,
                    Category      = 17,
                    CategoryName  = "Pre-Bind Processing",
                    Catorder      = 14,
                    Chklistnum    = 276,
                    ChecklistName = "Actuarial Analysis",
                    Sortorder     = 3,
                    Readonly      = false,
                    Checked       = true,
                    PersonId      = 714027,
                    PersonName    = "Dhanraj Patil",
                    Note          = "Test DP",
                    FirstName     = "Dhanraj",
                    LastName      = "Patil",
                    MiddleName    = null
                }
            };

            checkListRepository.Setup(p => p.IsValidDealCheckedStatus(data[0].Dealnum, data[0].Chklistnum)).Returns(chkstatus);
            checkListRepository.Setup(p => p.GetPersonByUserId(data[0].PersonId ?? 0)).Returns(data[0].PersonName);
            if (checklist.Checklists[0].ChkListNum == 999)
            {
                data.Clear();
                checkListRepository.Setup(p => p.GetCheckNumByDealChecklists(dealnumber, checklistnum)).Returns(data);
            }
            else
            {
                checkListRepository.Setup(p => p.GetCheckNumByDealChecklists(data[0].Dealnum, data[0].Chklistnum)).Returns(data);
            }
            var chklistval = new TbChklistval {
                PersonId = 714027
            };
            if (checklist.Checklists[0].PersonId > 0)
            {
                checkListRepository.Setup(p => p.Get(It.IsAny <Expression <Func <TbChklistval, bool> > >())).Returns(chklistval);
            }

            CheckListsController checkListsController = CreateChecklistsController(httpRequest, checkListRepository.Object);

            #endregion

            #region Act & Assert

            Assert.Throws(typeof(NotFoundAPIException), delegate { checkListsController.Put(dealnumber, checklistnum, checklist); });

            #endregion
        }
        public void ChecklistsController_Put_Returns_BadRequestResponseCode(int dealnumber, int checklistnum, int chkstatus, ChkCategoryTree checklist)
        {
            #region Arrange
            SetupUserIdentity();

            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}/{dealnumber}/checklists/{checklistnum}");
            Mock <ITblCheckListRepository> checkListRepository = new Mock <ITblCheckListRepository>();

            CheckListsController checkListsController = CreateChecklistsController(httpRequest, checkListRepository.Object);

            #endregion

            #region Act
            var response = checkListsController.Put(dealnumber, checklistnum, checklist);
            #endregion

            #region Assert
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(response);
            #endregion
        }
        public void ChecklistsController_Put_Returns_OKResponseCode(int dealnumber, int checklistnum, bool chkstatus, ChkCategoryTree checklist)
        {
            #region Arrange
            SetupUserIdentity();

            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}/{dealnumber}/checklists/{checklistnum}");

            Mock <ITblCheckListRepository> checkListRepository = new Mock <ITblCheckListRepository>();

            IList <grs_VGrsChecklistsByDeal> data = new List <grs_VGrsChecklistsByDeal>
            {
                new grs_VGrsChecklistsByDeal
                {
                    Dealnum       = 1392041,
                    Entitynum     = 1,
                    Category      = 17,
                    CategoryName  = "Pre-Bind Processing",
                    Catorder      = 14,
                    Chklistnum    = 276,
                    ChecklistName = "Actuarial Analysis",
                    Sortorder     = 3,
                    Readonly      = false,
                    Checked       = true,
                    PersonId      = 714027,
                    PersonName    = "Dhanraj Patil",
                    Note          = "Test DP",
                    FirstName     = "Dhanraj",
                    LastName      = "Patil",
                    MiddleName    = null
                }
            };
            if (chkstatus)
            {
                checkListRepository.Setup(p => p.IsValidDealCheckedStatus(data[0].Dealnum, data[0].Chklistnum)).Returns(1);
            }
            else
            {
                checkListRepository.Setup(p => p.IsValidDealCheckedStatus(data[0].Dealnum, data[0].Chklistnum)).Returns(0);
            }

            checkListRepository.Setup(p => p.GetPersonByUserId(data[0].PersonId ?? 0)).Returns(data[0].PersonName);
            checkListRepository.Setup(p => p.GetCheckNumByDealChecklists(data[0].Dealnum, data[0].Chklistnum)).Returns(data);
            var chklistval = new TbChklistval {
                PersonId = 714027
            };
            checkListRepository.Setup(p => p.Get(It.IsAny <Expression <Func <TbChklistval, bool> > >())).Returns(chklistval);

            CheckListsController checkListsController = CreateChecklistsController(httpRequest, checkListRepository.Object);

            #endregion

            #region Act

            var response = checkListsController.Put(dealnumber, checklistnum, checklist);


            #endregion

            #region Assert

            #region Expected Data

            var expectedchktree = new CheckListTree
            {
                ChkListNum  = 276,
                ChkListName = "Actuarial Analysis",
                SortOrder   = 3,
                ReadOnly    = false,
                Checked     = true,
                PersonId    = 714027,
                PersonName  = "Dhanraj Patil",
                Note        = "Test DP",
                FirstName   = "Dhanraj",
                LastName    = "Patil",
                MiddleName  = null
            };

            var expectedData = new List <ChkCategoryTree> {
                new ChkCategoryTree
                {
                    DealNumber   = 1392041,
                    EntityNum    = 1,
                    CategoryID   = 17,
                    CategoryName = "Pre-Bind Processing",
                    CatOrder     = 14,
                    Checklists   = new List <CheckListTree> {
                        expectedchktree
                    }
                }
            };
            #endregion

            if (chkstatus && !(checklist.Checklists[0].Checked ?? false))
            {
                var contentResult = response as NegotiatedContentResult <Response>;
                Assertions.AssertOkResponse(contentResult);
            }
            else
            {
                var contentResult = response as NegotiatedContentResult <ResponseItem <ChkCategoryTree> >;
                var chklistdata   = contentResult.Content.data;
                Assertions.AssertData(expectedData[0], chklistdata);
                Assertions.AssertOkResponse(contentResult);
            }



            #endregion
        }