Example #1
0
        public void CreateSqlQuery()
        {
            var fakePreparationResult = CreateSqlStatement();

            _preparationStageMock
            .Expect(mock => mock.PrepareSqlStatement(_queryModel, null))
            .Return(fakePreparationResult);
            var fakeResolutionResult = CreateSqlStatement();

            _resolutionStageMock
            .Expect(mock => mock.ResolveSqlStatement(Arg.Is(fakePreparationResult), Arg <MappingResolutionContext> .Is.TypeOf))
            .Return(fakeResolutionResult);
            _generationStageMock
            .Expect(mock => mock.GenerateTextForOuterSqlStatement(Arg <SqlCommandBuilder> .Is.TypeOf, Arg.Is(fakeResolutionResult)))
            .WhenCalled(mi =>
            {
                var sqlCommandBuilder = ((SqlCommandBuilder)mi.Arguments[0]);
                sqlCommandBuilder.Append("TestTest");
                sqlCommandBuilder.SetInMemoryProjectionBody(Expression.Constant(null));
            });

            var result = _sqlQueryGenerator.CreateSqlQuery(_queryModel);

            _preparationStageMock.VerifyAllExpectations();
            _resolutionStageMock.VerifyAllExpectations();
            _generationStageMock.VerifyAllExpectations();

            Assert.That(result.SqlCommand.CommandText, Is.EqualTo("TestTest"));
        }