Exemplo n.º 1
0
        public void CreateForScalarQuery()
        {
            _dataStoragePropertyDefinitionFactoryStrictMock
            .Expect(mock => mock.CreateStoragePropertyDefinition(DomainObjectIDs.Order1))
            .Return(_property1);
            _dataStoragePropertyDefinitionFactoryStrictMock
            .Expect(mock => mock.CreateStoragePropertyDefinition(DomainObjectIDs.Order3.Value))
            .Return(_property2);
            _dataStoragePropertyDefinitionFactoryStrictMock
            .Expect(mock => mock.CreateStoragePropertyDefinition(DomainObjectIDs.Official1))
            .Return(_property3);
            _dataStoragePropertyDefinitionFactoryStrictMock.Replay();

            var commandBuilderStub         = MockRepository.GenerateStub <IDbCommandBuilder> ();
            var expectedParametersWithType =
                new[]
            {
                new QueryParameterWithType(
                    new QueryParameter(_queryParameter1.Name, DomainObjectIDs.Order1.Value, _queryParameter1.ParameterType),
                    StoragePropertyDefinitionTestHelper.GetIDColumnDefinition(_property1).StorageTypeInfo),
                new QueryParameterWithType(_queryParameter2, _property2.ColumnDefinition.StorageTypeInfo),
                new QueryParameterWithType(
                    new QueryParameter(_queryParameter3.Name, DomainObjectIDs.Official1.ToString(), _queryParameter3.ParameterType),
                    StoragePropertyDefinitionTestHelper.GetSingleColumn(_property3.SerializedIDProperty).StorageTypeInfo)
            };

            _dbCommandBuilderFactoryStrictMock
            .Expect(
                stub => stub.CreateForQuery(Arg.Is("statement"), Arg <IEnumerable <QueryParameterWithType> > .List.Equal(expectedParametersWithType)))
            .Return(commandBuilderStub);
            _dbCommandBuilderFactoryStrictMock.Replay();

            var result = _factory.CreateForScalarQuery(_queryStub);

            _dataStoragePropertyDefinitionFactoryStrictMock.VerifyAllExpectations();
            _dbCommandBuilderFactoryStrictMock.VerifyAllExpectations();

            Assert.That(result, Is.TypeOf(typeof(ScalarValueLoadCommand)));
            var command = ((ScalarValueLoadCommand)result);

            Assert.That(command.DbCommandBuilder, Is.SameAs(commandBuilderStub));
        }
 public IStorageProviderCommand <object, IRdbmsProviderCommandExecutionContext> CreateForScalarQuery(IQuery query)
 {
     ArgumentUtility.CheckNotNull("query", query);
     return(_queryCommandFactory.CreateForScalarQuery(query));
 }