public void Build_Verify_If_No_Parameters_Specified_Should_Return_NonNull_Default_Parameters()
        {
            var result = RetrievalQueryExecutorBuilder <int> .ForQuery("A")
                         .Build();

            Assert.AreSame(RetrievalQueryExecutorBuilder.EmptyParameters, result.Parameters);
        }
        public void PerformOnConnection_Verify_IfParameters_Verify_Created_And_Added_To_Command()
        {
            var value = new object();

            this.Command.Expect(x => x.CreateParameter())
            .Return(Parameter);

            this.ParameterCollection.Expect(x => x.Add(Parameter))
            .Return(1);

            this.Parameter.Expect(x => x.ParameterName = Arg <string> .Matches(item => item == "myParam"));
            this.Parameter.Expect(x => x.Value         = Arg <object> .Matches(item => item == value));


            var result = RetrievalQueryExecutorBuilder <MyTestClass> .ForQuery("QUERY")
                         .WithCustomFuncMapper((x) => null)
                         .WithParameters(new Dictionary <string, object>
            {
                { "myParam", value }
            })
                         .Build()
                         .PerformOnConnection(this.Connection);

            this.Command.VerifyAllExpectations();

            this.ParameterCollection.VerifyAllExpectations();

            this.Parameter.VerifyAllExpectations();
        }
        public void PerformOnConnection_Verify_Mapper_Called_On_DataReader()
        {
            IResultMapper <MyTestClass> mockMapper = MockRepository.GenerateMock <IResultMapper <MyTestClass> >();

            var mockTestClass = new MyTestClass();

            this.DataReader.Stub(x => x.Read())
            .Repeat
            .Once()
            .Return(true);

            //mock no fields so that no query structure is populated as we do not care about
            //it in this test
            this.DataReader.Stub(x => x.FieldCount)
            .Return(0);


            mockMapper.Expect(x => x.MapResult(Arg <IDataReader> .Is.Equal(this.DataReader), Arg <QueryResultStructure> .Is.Anything))
            .Return(mockTestClass);

            var result = RetrievalQueryExecutorBuilder <MyTestClass> .ForQuery("QUERY")
                         .WithCustomResultMapper(mockMapper)
                         .Build()
                         .PerformOnConnection(this.Connection);

            mockMapper.VerifyAllExpectations();

            Assert.AreSame(mockTestClass, result.First(), "Did not return the expected mapped object");
        }
        public void Build_Verify_WithCustomFuncMapper_CustomMapper_Added()
        {
            var result = RetrievalQueryExecutorBuilder <int> .ForQuery("A")
                         .WithCustomFuncMapper((x) => { return(1); })
                         .Build();

            Assert.IsInstanceOf <FuncBasedResultMapper <int> >(result.ResultMapper, "Incorrect mapper retrieved");
        }
        public void Build_Verify_WithCustomMapper_CustomMapper_Added()
        {
            var mockMapper = MockRepository.GenerateMock <IResultMapper <int> >();

            var result = RetrievalQueryExecutorBuilder <int> .ForQuery("A")
                         .WithCustomResultMapper(mockMapper)
                         .Build();

            Assert.AreEqual(mockMapper, result.ResultMapper, "Did not set the specified mapper");
        }
        public void Build_Verify_If_Parameters_Specified_Should_Return_Them()
        {
            var mockParameters = new Dictionary <string, object>();

            var result = RetrievalQueryExecutorBuilder <int> .ForQuery("A")
                         .WithParameters(mockParameters)
                         .Build();

            Assert.AreSame(mockParameters, result.Parameters);
        }
        public void PerformOnConnection_Verify_IfNoParameters_NoneShouldBeSpecified()
        {
            this.Command.Expect(x => x.CreateParameter())
            .Repeat
            .Never();

            var result = RetrievalQueryExecutorBuilder <MyTestClass> .ForQuery("QUERY")
                         .WithCustomFuncMapper((x) => null)
                         .Build()
                         .PerformOnConnection(this.Connection);

            this.Parameter.VerifyAllExpectations();
        }
        public void Build_Verify_WithParameters_Clears_Previous_Parameters()
        {
            var mockParameters = new Dictionary <string, object>()
            {
                { "A", "B" }
            };

            var result = RetrievalQueryExecutorBuilder <int> .ForQuery("A")
                         .WithParameter("C", "D")
                         .WithParameters(mockParameters)
                         .Build();

            Assert.AreEqual(1, result.Parameters.Count);
        }