public void AddTrip_ReturnsRedirectToAction()
        {
            var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork          = TestHelperLibrary.SetupUnitOfWork();
            var tempData            = new TempDataDictionary(httpContextAccessor.Object.HttpContext, Mock.Of <ITempDataProvider>());
            var controller          = new VacationController(unitOfWork.Object, httpContextAccessor.Object);

            controller.TempData = tempData;

            var trip = new Trip {
                Id              = 1,
                DestinationId   = 6,
                AccommodationId = 4,
                StartDate       = new DateTime(2020, 12, 20),
                EndDate         = new DateTime(2021, 1, 2)
            };

            controller.TempData["trip_dest"]  = trip.DestinationId;
            controller.TempData["trip_acc"]   = trip.AccommodationId;
            controller.TempData["trip_start"] = trip.StartDate;
            controller.TempData["trip_end"]   = trip.EndDate;
            var result = controller.AddTrip(new[] { 1, 2 }) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
        }
        public void AddTripStep1_ReturnsViewResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();
            var controller = new VacationController(unitOfWork.Object, accessor.Object);

            var result = controller.AddTripStep1() as ViewResult;

            Assert.IsType <ViewResult>(result);
        }
示例#3
0
        public void PageSize_ReturnsRedirectToActionResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);

            var result = controller.PageSize(1) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
        }
        public void Filter_ByYear_ReturnsIndexView()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();
            var controller = new HomeController(unitOfWork.Object, accessor.Object);

            controller.Filter(new[] { "-1", "-1", "2016" });
            var result = controller.Index() as ViewResult;
            var sales  = result.Model as SalesListViewModel;

            Assert.Single(sales.Sales);
            Assert.IsType <ViewResult>(result);
        }
        public void FilterCleared__ReturnsIndexView()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();
            var controller = new HomeController(unitOfWork.Object, accessor.Object);

            controller.Filter(new[] { "-1", "-1", "-1" }, true);
            var result = controller.Index() as ViewResult;
            var sales  = result.Model as SalesListViewModel;

            Assert.Equal(3, sales.Sales.Count);
            Assert.IsType <ViewResult>(result);
        }
示例#6
0
        public void HttpGetAddSalesRep_ViewBagSalesRepsSet_ReturnsViewResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);

            var result = controller.AddSalesRep() as ViewResult;
            var reps   = (List <SalesRep>)controller.ViewBag.Managers;

            Assert.Equal(3, reps.Count);
            Assert.IsType <ViewResult>(result);
        }
示例#7
0
        public void DeleteTrip_Delete1_ReturnsRedirectToActionResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();
            var tempData   = new TempDataDictionary(accessor.Object.HttpContext, Mock.Of <ITempDataProvider>());
            var controller = new VacationController(unitOfWork.Object, accessor.Object);

            controller.TempData = tempData;

            var result = controller.DeleteTrip(1) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
        }
示例#8
0
        public void HttpPostAddSalesRep_HasModelError_ReturnsViewResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);
            var salesRep   = new SalesRep();

            controller.ModelState.AddModelError("Error", "Message");
            var result = controller.AddSalesRep(salesRep) as ViewResult;
            var reps   = (List <SalesRep>)controller.ViewBag.Managers;

            Assert.Equal(3, reps.Count);
            Assert.IsType <ViewResult>(result);
        }
        public void SortIsAscending_ByRep_ReturnsIndexView()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);

            controller.Sort(SortType.SortByName);

            var result = controller.Index() as ViewResult;
            var sales  = result.Model as SalesListViewModel;

            Assert.Equal(1, sales.Sales[0].SalesRepId);
            Assert.Equal(2, sales.Sales[2].SalesRepId);
            Assert.Equal(3, sales.Sales[1].SalesRepId);
            Assert.IsType <ViewResult>(result);
        }
示例#10
0
        public void DeleteFromManage_ContainsAcc_ContainsDest_ReturnsRedirectToAction()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();
            var tempData   = new TempDataDictionary(accessor.Object.HttpContext, Mock.Of <ITempDataProvider>());
            var controller = new VacationController(unitOfWork.Object, accessor.Object);

            controller.TempData = tempData;
            var viewmodel = new ManageViewModel {
                SelectedAccommodationToDelete = 1,
                SelectedActivityToDelete      = 0,
                SelectedDestinationToDelete   = 1
            };
            var result = controller.DeleteFromManage(viewmodel) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("Manage", result.ActionName);
        }
示例#11
0
        public void AddTripStep2_ModelStateInValid_ReturnsViewResult()
        {
            var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork          = TestHelperLibrary.SetupUnitOfWork();
            var controller          = new VacationController(unitOfWork.Object, httpContextAccessor.Object);

            controller.ModelState.AddModelError("error", "error");
            var trip = new Trip {
                Id              = 1,
                DestinationId   = 6,
                AccommodationId = 4,
                StartDate       = new DateTime(2020, 12, 20),
                EndDate         = new DateTime(2021, 1, 2)
            };
            var result = controller.AddTripStep2(trip) as ViewResult;

            Assert.IsType <ViewResult>(result);
        }
示例#12
0
        public void Manage_ReturnsViewWithNullValues()
        {
            var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork          = TestHelperLibrary.SetupUnitOfWork();
            var tempData            = new TempDataDictionary(httpContextAccessor.Object.HttpContext, Mock.Of <ITempDataProvider>());
            var controller          = new VacationController(unitOfWork.Object, httpContextAccessor.Object);

            controller.TempData = tempData;
            var result = controller.Manage() as ViewResult;

            Assert.IsType <ViewResult>(result);
            var model = result.Model as ManageViewModel;

            Assert.Equal("", model.AccommodationPhone);
            Assert.Equal("", model.AccommodationEmail);
            Assert.Equal("", model.AccommodationName);
            Assert.Equal("", model.ActivityName);
            Assert.Equal("", model.DestinationName);
        }
        public void HttpPostAddSale_SaleExists_ReturnsViewResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);
            var sale       = new Sale {
                Year       = 2016,
                Month      = 1,
                SalesRepId = 1,
                SalesRep   = unitOfWork.Object.SalesReps.Get().FirstOrDefault(),
                Amount     = 20
            };
            var result = controller.AddSale(sale) as ViewResult;
            var reps   = (List <SalesRep>)controller.ViewBag.SalesReps;

            Assert.Equal(3, reps.Count);
            Assert.IsType <ViewResult>(result);
        }
示例#14
0
        public void SortIsAscending_ByStartDate_ReturnsHomeView()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            accessor.Object.HttpContext.Session.SetInt32("page_size", 3);

            var controller = new VacationController(unitOfWork.Object, accessor.Object);

            controller.Sort(SortType.SortByStartDate);

            var result    = controller.Home() as ViewResult;
            var viewModel = result.Model as VacationListViewModel;

            Assert.Equal(3, viewModel.Trips[0].Id);
            Assert.Equal(2, viewModel.Trips[1].Id);
            Assert.Equal(1, viewModel.Trips[2].Id);
            Assert.IsType <ViewResult>(result);
        }
示例#15
0
        public void AddFromManage_SuccessfulAddAccommodation_WithOnlyName_Returns_RedirectToActionResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();
            var tempData   = new TempDataDictionary(accessor.Object.HttpContext, Mock.Of <ITempDataProvider>());
            var controller = new VacationController(unitOfWork.Object, accessor.Object);

            controller.TempData = tempData;
            var viewmodel = new ManageViewModel {
                DestinationName    = "",
                AccommodationName  = "testacc",
                AccommodationEmail = "",
                AccommodationPhone = "",
                ActivityName       = ""
            };
            var result = controller.AddFromManage(viewmodel) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("Home", result.ActionName);
        }
示例#16
0
        public void HttpPostAddSalesRep_SaleExists_ReturnsViewResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);
            var salesRep   = new SalesRep {
                Id        = 3,
                FirstName = "Tony",
                LastName  = "Lazuto",
                BirthDate = new DateTime(2000, 8, 18),
                HireDate  = DateTime.Today,
                ManagerId = 0
            };
            var result = controller.AddSalesRep(salesRep) as ViewResult;
            var reps   = (List <SalesRep>)controller.ViewBag.Managers;

            Assert.Equal(3, reps.Count);
            Assert.IsType <ViewResult>(result);
        }
        public void HttpPostAddSale_SaleIsPerfect_ReturnsRedirectToActionResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);
            var tempData   = new Mock <ITempDataDictionary>();

            controller.TempData = tempData.Object;
            var sale = new Sale {
                Year       = 2016,
                Month      = 3,
                SalesRepId = 1,
                SalesRep   = unitOfWork.Object.SalesReps.Get().FirstOrDefault(),
                Amount     = 50
            };
            var result = controller.AddSale(sale) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
        }
示例#18
0
        public void HttpPostAddSalesRep_SaleIsPerfect_ReturnsRedirectToActionResult()
        {
            var accessor   = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork = TestHelperLibrary.SetupUnitOfWork();

            var controller = new HomeController(unitOfWork.Object, accessor.Object);
            var tempData   = new Mock <ITempDataDictionary>();

            controller.TempData = tempData.Object;
            var salesRep = new SalesRep {
                Id        = 4,
                FirstName = "Alex",
                LastName  = "Coozie",
                BirthDate = new DateTime(2000, 8, 30),
                HireDate  = DateTime.Today,
                ManagerId = 3
            };
            var result = controller.AddSalesRep(salesRep) as RedirectToActionResult;

            Assert.IsType <RedirectToActionResult>(result);
        }
示例#19
0
        public void AddTripStep2_ModelStateValid_ReturnsViewResult()
        {
            var httpContextAccessor = TestHelperLibrary.SetUpHttpContextAccessor();
            var unitOfWork          = TestHelperLibrary.SetupUnitOfWork();
            var tempData            = new TempDataDictionary(httpContextAccessor.Object.HttpContext, Mock.Of <ITempDataProvider>());
            var controller          = new VacationController(unitOfWork.Object, httpContextAccessor.Object);

            controller.TempData = tempData;
            var trip = new Trip {
                Id              = 1,
                DestinationId   = 6,
                AccommodationId = 4,
                StartDate       = new DateTime(2020, 12, 20),
                EndDate         = new DateTime(2021, 1, 2)
            };
            var result = controller.AddTripStep2(trip) as ViewResult;

            Assert.IsType <ViewResult>(result);
            Assert.Equal(trip.DestinationId, controller.TempData["trip_dest"]);
            Assert.Equal(trip.AccommodationId, controller.TempData["trip_acc"]);
            Assert.Equal(trip.StartDate, controller.TempData["trip_start"]);
            Assert.Equal(trip.EndDate, controller.TempData["trip_end"]);
        }