コード例 #1
0
        public void AndTheSearchMethodIsCalledCorrectly()
        {
            _searchQueryMethod = (text, session) => { if (session == _session) throw new MethodAccessException(); return null; };
            _searchForItemsMethodGroup = new SearchForItemsMethodGroup(_searchTextValidation, _searchQueryMethod, _sessionMethod);

            AssertionExtensions.ShouldThrow<MethodAccessException>(() => _searchController.SearchForItems(_searchString, _searchForItemsMethodGroup));
        }
コード例 #2
0
        public void AndTheSearchResultReturnsAnEmptyListSoTheEmptyListIsReturned()
        {
            _searchQueryMethod = (text, session) => new List<SearchForItemsResult>();
            _searchForItemsMethodGroup = new SearchForItemsMethodGroup(_searchTextValidation, _searchQueryMethod, _sessionMethod);

            ((SimpleResult<IList<SearchForItemsResult>>)
                 _searchController
                     .SearchForItems(_searchString, _searchForItemsMethodGroup)
                     .Data)
                    .Value
                    .Any()
                    .Should()
                    .BeFalse();
        }
コード例 #3
0
        public JsonResult SearchForItems(string searchString, SearchForItemsMethodGroup methodGroup)
        {
            var validationResult = methodGroup.SearchTextIsValid(searchString);

            var searchResult =
                When<MethodResult<IList<SearchForItemsResult>>>
                    .True(validationResult.Success)
                    .Then(() =>
                        new WithSession(methodGroup.SessionMethod)
                            .ReturnResult(session =>
                                new MethodResult<IList<SearchForItemsResult>>().SetValue(methodGroup.SearchQueryMethod(searchString, session))))
                    .Else(() => new MethodResult<IList<SearchForItemsResult>>(validationResult.Messages, new List<SearchForItemsResult>()));

            return new JsonResult { Data = new SimpleResult<IList<SearchForItemsResult>>(searchResult) };
        }
コード例 #4
0
        public void AndTheSearchTextIsTooShortAnUnsuccessfulRestultIsReturned()
        {
            _searchTextValidation = (text) => new MethodResult<bool>().AddErrorMessage("error");
            _searchForItemsMethodGroup = new SearchForItemsMethodGroup(_searchTextValidation, _searchQueryMethod, _sessionMethod);

            ((SimpleResult<IList<SearchForItemsResult>>)
                _searchController
                    .SearchForItems(_searchString, _searchForItemsMethodGroup)
                    .Data)
                    .Success
                    .Should()
                    .BeFalse();
        }
コード例 #5
0
 public void AndANewSessionIsCreated()
 {
     _searchForItemsMethodGroup = new SearchForItemsMethodGroup(_searchTextValidation, _searchQueryMethod, () => { throw new MethodAccessException(); });
     AssertionExtensions.ShouldThrow<MethodAccessException>(() => _searchController.SearchForItems(_searchString, _searchForItemsMethodGroup));
 }
コード例 #6
0
        public void TestInitialize()
        {
            _searchString = RandomTool.RandomString();

            _searchController = new SearchControllerShadow();
            _searchTextValidation = (text) => new MethodResult<bool>();

            _resultList = Enumerable.Range(0, ListCount).Select(item => new SearchForItemsResult(ListCount, RandomTool.RandomString(), RandomTool.RandomString(), RandomTool.RandomString())).ToList();

            _session = Substitute.For<ISession>();
            _sessionMethod = () => _session;

            _searchQueryMethod = (text, session) => _resultList;

            _searchForItemsMethodGroup = new SearchForItemsMethodGroup(_searchTextValidation, _searchQueryMethod, _sessionMethod);
        }