예제 #1
0
        public void Init()
        {
            _costServiceMock          = new Mock <ICostService>();
            UserSearchServiceMock     = new Mock <IUserSearchService>();
            _permissionServiceMock    = new Mock <IPermissionService>();
            AdvancedSearchServiceMock = new Mock <IAdvancedSearchService>(
                );
            _permissionServiceMock.Setup(a => a.GetObjectUserGroups(It.IsAny <Guid>(), It.IsAny <Guid?>()))
            .ReturnsAsync(new[]
            {
                Guid.NewGuid().ToString()
            });
            var actionDescriptor = new Mock <ActionDescriptor>();

            actionDescriptor.SetupGet(x => x.DisplayName).Returns("Action_With_SomeAttribute");
            User = new UserIdentity
            {
                AgencyId   = Guid.NewGuid(),
                BuType     = BuType.Pg,
                Email      = "email",
                FirstName  = "Bruce",
                FullName   = "Bat Man",
                LastName   = "Wayne",
                GdamUserId = "gdamID",
                Id         = Guid.NewGuid(),
                ModuleId   = Guid.NewGuid()
            };
            WatchersController       = SetupWatcherController(actionDescriptor.Object);
            AdvancedSearchController = SetupAdvancedSearchController(actionDescriptor.Object);
        }
예제 #2
0
        public async Task SearchWatchers_return_none()
        {
            const int expected  = 0;
            var       costQuery = new CostUserQuery();
            var       result    = await WatchersController.Search(costQuery);

            var objectResult = result.As <OkObjectResult>();

            objectResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var costUserSearchItems = objectResult.Value as IEnumerable <CostUserSearchItem>;

            costUserSearchItems.Should().NotBeNull();
            costUserSearchItems.Count().Should().Be(expected);
        }
예제 #3
0
        public async Task SearchWatchers_return_one()
        {
            const int expected = 1;

            UserSearchServiceMock.Setup(a => a.SearchWatchers(It.IsAny <CostUserQuery>())).ReturnsAsync(new List <CostUserSearchItem> {
                new CostUserSearchItem()
            });
            var costQuery = new CostUserQuery();
            var result    = await WatchersController.Search(costQuery);

            var objectResult = result.As <OkObjectResult>();

            objectResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var costUserSearchItems = objectResult.Value as IEnumerable <CostUserSearchItem>;

            costUserSearchItems.Should().NotBeNull();
            costUserSearchItems.Count().Should().Be(expected);
        }
예제 #4
0
        private WatchersController SetupWatcherController(ActionDescriptor actionDescriptor)
        {
            WatchersController =
                new WatchersController(_costServiceMock.Object, UserSearchServiceMock.Object, _permissionServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
            };
            WatchersController.ControllerContext.HttpContext = new DefaultHttpContext();

            WatchersController.HttpContext.Request.Headers["X-Forwarded-For"] = "127.0.0.1";
            WatchersController.HttpContext.Items["user"] = User;
            var httpActionContext = new ActionExecutingContext(
                new ActionContext
            {
                HttpContext      = WatchersController.HttpContext,
                RouteData        = new RouteData(),
                ActionDescriptor = actionDescriptor
            }, new Mock <List <IFilterMetadata> >().Object,
                new Mock <IDictionary <string, object> >().Object,
                WatchersController);

            WatchersController.OnActionExecuting(httpActionContext);
            return(WatchersController);
        }