예제 #1
0
        public void Given_get_When_responsibilities_index_page_Then_should_return_index_view()
        {
            // Given
            var controller = GetTarget();
            var viewModel = new ResponsibilitiesIndexViewModel();
            _searchViewModelFactory.Setup(mock => mock.GetViewModel()).Returns(viewModel);
         
            // When
            var result = controller.Index(viewModel) as ViewResult;

            // Then
            Assert.That(result.ViewName, Is.EqualTo("Index"));
        }
        private ResponsibilitiesIndexViewModel GetResponsibilitiesIndexViewModel(ResponsibilitiesIndexViewModel model)
        {
            _searchResponsibilityViewModelFactory
                .WithCompanyId(CurrentUser.CompanyId)
                .WithTitle(model.Title)
                .WithPageNumber(model.Page != default(int) ? model.Page : 1)
                .WithPageSize(model.PageSize != default(int) ? model.PageSize : PAGE_SIZE)
                .WithOrderBy(model.OrderBy)
                .WithShowDeleted(model.IsShowDeleted);
               
            if (model.CategoryId.HasValue)
                _searchResponsibilityViewModelFactory.WithCategoryId(model.CategoryId.Value);

            if (model.SiteId.HasValue)
                _searchResponsibilityViewModelFactory.WithSiteId(model.SiteId.Value);

            if (model.SiteGroupId.HasValue)
                _searchResponsibilityViewModelFactory.WithSiteGroupId(model.SiteGroupId.Value);

            if (!string.IsNullOrEmpty(model.CreatedFrom))
                _searchResponsibilityViewModelFactory.WithCreatedFrom(DateTime.Parse(model.CreatedFrom));

            if (!string.IsNullOrEmpty(model.CreatedTo))
                _searchResponsibilityViewModelFactory.WithCreatedTo(DateTime.Parse(model.CreatedTo));

            var allowedSites = CurrentUser.GetSitesFilter();

            if (allowedSites.Count > 0)
                _searchResponsibilityViewModelFactory.WithAllowedSiteIds(allowedSites);

            var viewModel = _searchResponsibilityViewModelFactory.GetViewModel();
            return viewModel;
        }
        public ViewResult Find(ResponsibilitiesIndexViewModel model)
        {
            var viewModel = GetResponsibilitiesIndexViewModel(model);

            return View("Index", viewModel);
        }
        public ActionResult Index(ResponsibilitiesIndexViewModel model)
        {
            var viewModel = GetResponsibilitiesIndexViewModel(model);

            return View("Index", viewModel);
        }
예제 #5
0
        public void SetUp()
        {
            _returnedModel = new ResponsibilitiesIndexViewModel();
            _request = new ResponsibilitiesIndexViewModel()
                           {
                               CategoryId = 1234L,
                               SiteId = 12345L,
                               SiteGroupId = 3574L,
                               Title = "title",
                               CreatedFrom = DateTime.Now.AddDays(-1434).ToShortDateString(),
                               CreatedTo = DateTime.Now.AddDays(-2).ToShortDateString(),
                               IsShowDeleted = true
                           };
            _searchViewModelFactory = new Mock<ISearchResponsibilityViewModelFactory>();

            _searchViewModelFactory
                .Setup(x => x.WithCompanyId(It.IsAny<long>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithCategoryId(It.IsAny<long>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithSiteId(It.IsAny<long>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithSiteGroupId(It.IsAny<long>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithTitle(It.IsAny<string>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithCreatedFrom(It.IsAny<DateTime>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithCreatedTo(It.IsAny<DateTime>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithShowDeleted(It.IsAny<bool>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
              .Setup(x => x.WithPageNumber(It.IsAny<int>()))
              .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
              .Setup(x => x.WithPageSize(It.IsAny<int>()))
              .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.WithOrderBy(It.IsAny<string>()))
                .Returns(_searchViewModelFactory.Object);

            _searchViewModelFactory
                .Setup(x => x.GetViewModel())
                .Returns(_returnedModel);

            _createUpdateResponsibilityTaskViewModelFactory =
                new Mock<ICreateUpdateResponsibilityTaskViewModelFactory>();

            _completeResponsibilityTaskViewModelFactory =
                new Mock<ICompleteResponsibilityTaskViewModelFactory>();

            _bus = new Mock<IBus>();
            _businessSafeSessionManager = new Mock<IBusinessSafeSessionManager>();

            _responsibilityTaskService = new Mock<IResponsibilityTaskService>();
        }
        public ResponsibilitiesIndexViewModel GetViewModel()
        {
            var sites = GetSites();
            var siteGroups = GetSiteGroups();
            var categories = GetResponsibilityCategories();
            var responsibilities = GetResponsibilities();

            var request = CreateSearchResponsibilitiesRequest();
            var total = _responsibilitiesService.Count(request);
            var viewModel = new ResponsibilitiesIndexViewModel
            {
                Sites = sites,
                SiteGroups = siteGroups,
                Categories = categories,
                Responsibilities = responsibilities,
                CategoryId = _categoryId,
                CreatedFrom = _createdFrom,
                CreatedTo = _createdTo,
                Title = _title,
                SiteId = _siteId,
                SiteGroupId = _siteGroupId,
                IsShowDeleted = _showDeleted,
                Page = _page,
                PageSize = _pageSize,
                Total = total
            };

            return viewModel;
        }