public void Index_SyncRequest_AsksForIndexView()
        {
            Mock <BusinessTripService> mock       = new Mock <BusinessTripService>();
            BusinessTripController     controller = GetNewBusinessTripControllerWithControllerContext(mock.Object, null);

            ViewResult result = controller.Index(null, null) as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
        public void Index_AsyncRequest_JsonRequestBehaviorEqualsAllowGet()
        {
            Mock <BusinessTripService> mock       = new Mock <BusinessTripService>();
            BusinessTripController     controller = GetNewBusinessTripControllerWithControllerContext(mock.Object, null, true);

            JsonResult result = controller.Index(null, null) as JsonResult;

            Assert.AreEqual(JsonRequestBehavior.AllowGet, result.JsonRequestBehavior);
        }
        public void Index_SyncRequest_RetrievesPageInfoPropertyFromModel()
        {
            Mock <BusinessTripService> mock = new Mock <BusinessTripService>();

            mock.Setup(m => m.PageInfo).Returns(new PageInfo()
            {
                TotalItems = 9, PageSize = 3, PageNumber = 3
            });
            BusinessTripController controller = GetNewBusinessTripControllerWithControllerContext(mock.Object, null);

            ViewResult result = controller.Index(null, null) as ViewResult;

            BusinessTripListViewModel model = result.ViewData.Model as BusinessTripListViewModel;

            Assert.AreEqual(9, model.PageInfo.TotalItems);
            Assert.AreEqual(3, model.PageInfo.PageSize);
            Assert.AreEqual(3, model.PageInfo.PageNumber);
            Assert.AreEqual(3, model.PageInfo.TotalPages);
        }
        public void Index_SyncRequest_RetrievesBusinessTripsPropertyFromModel()
        {
            Mock <BusinessTripService> mock = new Mock <BusinessTripService>();

            mock.Setup(m => m.GetPage(It.IsAny <IEnumerable <BusinessTripDTO> >(), It.IsAny <int>())).Returns(new BusinessTripDTO[] {
                new BusinessTripDTO {
                    Id   = 1,
                    Name = "02.09.2018_026"
                }
            });
            BusinessTripController controller = GetNewBusinessTripControllerWithControllerContext(mock.Object, null);

            ViewResult result = controller.Index(null, null) as ViewResult;

            BusinessTripListViewModel model = result.ViewData.Model as BusinessTripListViewModel;

            Assert.AreEqual(1, model.BusinessTrips.Count());
            Assert.AreEqual(1, model.BusinessTrips.FirstOrDefault().Id);
            Assert.AreEqual("02.09.2018_026", model.BusinessTrips.FirstOrDefault().Name);
        }
        public void Index_AsyncRequest_RetrievesBusinessTripsPropertyFromModel()
        {
            Mock <BusinessTripService> mock = new Mock <BusinessTripService>();

            mock.Setup(m => m.GetPage(It.IsAny <IEnumerable <BusinessTripDTO> >(), It.IsAny <int>())).Returns(new BusinessTripDTO[] {
                new BusinessTripDTO {
                    Id   = 1,
                    Name = "02.09.2018_026"
                }
            });
            BusinessTripController controller = GetNewBusinessTripControllerWithControllerContext(mock.Object, null, true);

            JsonResult result       = controller.Index(null, null) as JsonResult;
            object     businessTrip = (result.Data.GetType().GetProperty("BusinessTrips").GetValue(result.Data) as object[])[0];
            int        id           = (int)businessTrip.GetType().GetProperty("Id").GetValue(businessTrip);
            string     code         = businessTrip.GetType().GetProperty("Code").GetValue(businessTrip).ToString();

            Assert.AreEqual(1, id);
            Assert.AreEqual("02.09.2018_026", code);
        }