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)); }
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(); }
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) }; }
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(); }
public void AndANewSessionIsCreated() { _searchForItemsMethodGroup = new SearchForItemsMethodGroup(_searchTextValidation, _searchQueryMethod, () => { throw new MethodAccessException(); }); AssertionExtensions.ShouldThrow<MethodAccessException>(() => _searchController.SearchForItems(_searchString, _searchForItemsMethodGroup)); }
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); }