public void AndTheColumnQueryIsCalledCorrectly()
        {
            _queryForColumns = (text, session) => { if (session == _session) throw new MethodAccessException(); return null; };
            _methodGroup = new RetrieveTableInformationMethodGroup(_searchForTable, _queryForColumns, _sessionMethod);

            AssertionExtensions.ShouldThrow<MethodAccessException>(() => _tableControllerShadow.RetrieveTableInformationByTableId(TableId, _methodGroup));
        }
        public void TestInitialize()
        {
            _tableControllerShadow = new TableControllerShadow();

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

            _queryForColumns = (x, session) => new List<ColumnItemResult>();
            _searchForTable = (tableId, session) => _tableInformationResult;
            _methodGroup = new RetrieveTableInformationMethodGroup(_searchForTable, _queryForColumns, _sessionMethod);
            _tableInformationResult = new TableInformationResult {Id = RandomTool.RandomInt32()};
        }
        public JsonResult RetrieveTableInformationByTableId(int tableId, RetrieveTableInformationMethodGroup methodGroup)
        {
            var tableResult =
                new WithSession(methodGroup.SessionMethod)
                    .ReturnResult(session =>
                         {
                            var innerResult = methodGroup.SearchForTable(tableId, session);
                            GuardClause.IfNullThrowArgumentException(innerResult,"TableControllerShadow.RetrieveTableInformation: Table doesn't exist.");
                            innerResult.ColumnList = methodGroup.QueryForColumns(innerResult.Id, session);

                            return innerResult;
                        });

            return new JsonResult { Data = tableResult };
        }
        public void TheColumnsForTheTableAreQueriedAndSetOnTheResult()
        {
            var columnList = new List<ColumnItemResult> {new ColumnItemResult(), new ColumnItemResult()};

            Func<int, ISession, IEnumerable<ColumnItemResult>> queryForColumns = (x, session) =>
                {
                    if (x != _tableInformationResult.Id)
                    {
                        throw new ArgumentException();
                    }

                    return columnList;
                };

            _methodGroup = new RetrieveTableInformationMethodGroup(_searchForTable, queryForColumns, _sessionMethod);

            ((TableInformationResult)
            _tableControllerShadow
                .RetrieveTableInformationByTableId(TableId, _methodGroup)
                .Data)
                .ColumnList
                .Should()
                .BeEquivalentTo(columnList);
        }
 public void AndANewSessionIsCreated()
 {
     _methodGroup = new RetrieveTableInformationMethodGroup(_searchForTable, _queryForColumns, () => { throw new MethodAccessException(); });
     AssertionExtensions.ShouldThrow<MethodAccessException>(() => _tableControllerShadow.RetrieveTableInformationByTableId(TableId, _methodGroup));
 }
 public void TheTableDoesNotExistSoAnExceptionIsThrown()
 {
     _methodGroup = new RetrieveTableInformationMethodGroup((tableId, session) => null, _queryForColumns, _sessionMethod);
     AssertionExtensions.ShouldThrow<ArgumentException>(() => _tableControllerShadow.RetrieveTableInformationByTableId(TableId, _methodGroup));
 }