Exemplo n.º 1
0
        //[Ignore]
        public void GetText_Returns_UpdateText()
        {
            var person  = new Person();
            var mapping = new PersonMap();

            mapping.ExecuteMapping();

            var mapInt    = new TypeMap(DbType.Int32, typeof(int), new GenericConverter());
            var mapString = new TypeMap(DbType.String, typeof(string), new GenericConverter());

            var mock = new Moq.Mock <ITypeRegister>();

            mock.Setup(x => x.Get(typeof(int))).Returns(mapInt);
            mock.Setup(x => x.Get(typeof(string))).Returns(mapString);

            var dbparam = new Moq.Mock <IDbDataParameter>();
            Func <IDbDataParameter> func = () => dbparam.Object;

            var register = mock.Object;

            var insert = new UpdatePlan(mapping, register);
            var text   = insert.CreatePlanParameter(func, person);

            text.SqlText.ToUpper().Should().Be("UPDATE PERSON SET NAME = @NAME, AGE = @AGE WHERE ID = @ID");
            text.Parameters.Count.Should().Be(3);
        }
Exemplo n.º 2
0
        public void MapIdentifier_Must_Be_Case_Insensitive()
        {
            var mapper = new PersonMap();
            mapper.ExecuteMapping();

            mapper.Executing(x => x.GetByFieldName("id")).NotThrows();
        }
Exemplo n.º 3
0
        //[Ignore]
        public void GetText_Returns_InsertText()
        {
            var person  = new Person();
            var mapping = new PersonMap();

            mapping.ExecuteMapping();

            var mapInt    = new TypeMap(DbType.Int32, typeof(int), new GenericConverter());
            var mapString = new TypeMap(DbType.String, typeof(string), new GenericConverter());

            var mock = new Moq.Mock <ITypeRegister>();

            mock.Setup(x => x.Get(typeof(int))).Returns(mapInt);
            mock.Setup(x => x.Get(typeof(string))).Returns(mapString);

            var dbparam = new Moq.Mock <IDbDataParameter>();
            Func <IDbDataParameter> func = () => dbparam.Object;

            var register = mock.Object;

            var insert = new InsertPlan(mapping, register);
            var text   = insert.CreatePlanParameter(func, person);

            text.SqlText.ToUpper().Should().Be("INSERT INTO PERSON (NAME, AGE) VALUES (@NAME, @AGE)");
        }
Exemplo n.º 4
0
        public void MapAttribute_Must_Be_Case_Insensitive()
        {
            var mapper = new PersonMap();
            mapper.ExecuteMapping();

            mapper.Executing(x => x.GetByFieldName("NOME")).NotThrows();
        }
Exemplo n.º 5
0
        public void GetText_Returns_SelectText()
        {
            var mapping = new PersonMap();
            mapping.ExecuteMapping();

            var select = new QueryPlan(mapping, null, null);

            select.CreatePlanParameter().SqlText.ToUpper().Should().Be("SELECT ID, NAME, AGE FROM PERSON");
        }
Exemplo n.º 6
0
        public void GetText_Returns_SelectText()
        {
            var mapping = new PersonMap();

            mapping.ExecuteMapping();

            var select = new QueryPlan(mapping, null, null);

            select.CreatePlanParameter().SqlText.ToUpper().Should().Be("SELECT ID, NAME, AGE FROM PERSON");
        }
Exemplo n.º 7
0
        public void Simple_Query_Translate()
        {
            var container = new NinjectContainer();
            var map = container.Resolve<IMappingManager>();
            var mapper = new PersonMap();
            mapper.ExecuteMapping();
            map.Register(mapper.MappedType, mapper);

            var query = new Query<Person>();
            query.Where(x => x.Name).Equal("Alaor").And(x => x.Age).GreaterThan(18).And(x => x.Id).NotEqual(0);

            var translator = new QueryTranslator(map);
            var result = translator.Translate(query);

            result.SqlText.Trim().ToUpper().Should().Be("NAME = @PARAMETER_0 AND AGE > @PARAMETER_1 AND ID <> @PARAMETER_2");
            result.Parameters.Count.Should().Be(3);
        }
Exemplo n.º 8
0
        public void Simple_Query_Translate()
        {
            var container = new NinjectContainer();
            var map       = container.Resolve <IMappingManager>();
            var mapper    = new PersonMap();

            mapper.ExecuteMapping();
            map.Register(mapper.MappedType, mapper);

            var query = new Query <Person>();

            query.Where(x => x.Name).Equal("Alaor").And(x => x.Age).GreaterThan(18).And(x => x.Id).NotEqual(0);

            var translator = new QueryTranslator(map);
            var result     = translator.Translate(query);

            result.SqlText.Trim().ToUpper().Should().Be("NAME = @PARAMETER_0 AND AGE > @PARAMETER_1 AND ID <> @PARAMETER_2");
            result.Parameters.Count.Should().Be(3);
        }
Exemplo n.º 9
0
        public void GetText_Returns_InsertText()
        {
            var person = new Person();
            var mapping = new PersonMap();
            mapping.ExecuteMapping();

            var mapInt = new TypeMap(DbType.Int32,typeof(int),new GenericConverter());
            var mapString = new TypeMap(DbType.String,typeof(string),new GenericConverter());

            var mock = new Moq.Mock<ITypeRegister>();
            mock.Setup(x => x.Get(typeof (int))).Returns(mapInt);
            mock.Setup(x => x.Get(typeof(string))).Returns(mapString);

            var dbparam = new Moq.Mock<IDbDataParameter>();
            Func<IDbDataParameter> func = () => dbparam.Object;

            var register = mock.Object;

            var insert = new InsertPlan(mapping, register);
            var text = insert.CreatePlanParameter(func, person);

            text.SqlText.ToUpper().Should().Be("INSERT INTO PERSON (NAME, AGE) VALUES (@NAME, @AGE)");
        }
Exemplo n.º 10
0
        public void GetText_Returns_DeleteText()
        {
            var person = new Person();
            var mapping = new PersonMap();
            mapping.ExecuteMapping();

            var mapInt = new TypeMap(DbType.Int32, typeof(int), new GenericConverter());
            var mapString = new TypeMap(DbType.String, typeof(string), new GenericConverter());

            var mock = new Moq.Mock<ITypeRegister>();
            mock.Setup(x => x.Get(typeof(int))).Returns(mapInt);
            mock.Setup(x => x.Get(typeof(string))).Returns(mapString);

            var dbparam = new Moq.Mock<IDbDataParameter>();
            Func<IDbDataParameter> func = () => dbparam.Object;

            var register = mock.Object;

            var insert = new DeletePlan(mapping, register);
            var param = insert.CreatePlanParameter(func, person);

            param.SqlText.ToUpper().Should().Be("DELETE FROM PERSON WHERE ID = @ID");
        }