Esempio n. 1
0
        public void UpdateSupplierFromProduct()
        {
            // Arrange
            Builder builder = new Builder(
                SqlDataMapperType,
                DataMapperParams,
                PropertyColumnMapperType,
                MultipleConnectionPolicyType);
            IDataMapper       productMapper            = builder.Build <Product>();
            IConnectionPolicy explicitConnectionPolicy = productMapper.GetConnectionPolicy();
            String            fakeName    = "teste";
            String            trueName    = "";
            String            updatedName = "";
            // Act
            Product p1 = (Product)productMapper.GetAll().First();

            trueName = p1.SupplierID.CompanyName;
            p1.SupplierID.CompanyName = fakeName;
            productMapper.Update(p1);

            Product p2 = (Product)productMapper.GetAll().First();

            updatedName = p2.SupplierID.CompanyName;

            p2.SupplierID.CompanyName = trueName;
            productMapper.Update(p2);

            // Assert
            Assert.AreEqual(fakeName, updatedName);
        }
Esempio n. 2
0
        public static void m2()
        {
            Builder builder = new Builder(
                typeof(SqlDataMapper <>),
                new Object[] { SqlMapperUnitTest.getMySqlConnectionString() },
                typeof(PropertyColumnMapper),
                typeof(ExplicitConnectionPolicy));

            IDataMapper <ProductSimple> productMapper            = builder.Build <ProductSimple>();
            IConnectionPolicy           explicitConnectionPolicy = productMapper.GetConnectionPolicy();

            // Act
            explicitConnectionPolicy.OpenConnection();
            explicitConnectionPolicy.BeginTransaction();

            ProductSimple p1 = productMapper.GetAll().First();

            p1.ProductName = "Potatoes";
            productMapper.Update(p1);

            ProductSimple p2 = productMapper.GetAll().First();

            // Assert
            bool result = p1.ProductName == p2.ProductName;

            explicitConnectionPolicy.RollBack();
            explicitConnectionPolicy.Dispose();
        }
Esempio n. 3
0
        public static void m3()
        {
            SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder();

            sqlConnectionStringBuilder.DataSource         = @"RoXaSDTD-PC\SQLEXPRESS";
            sqlConnectionStringBuilder.InitialCatalog     = "PlaylistManager";
            sqlConnectionStringBuilder.UserID             = "Rafael";
            sqlConnectionStringBuilder.Password           = "******";
            sqlConnectionStringBuilder.IntegratedSecurity = true;
            string connectionString = sqlConnectionStringBuilder.ConnectionString;

            Builder builder = new Builder(
                typeof(SqlDataMapper <>),
                new Object[] { connectionString },
                typeof(PropertyColumnMapper),
                typeof(MultipleConnectionPolicy));

            IDataMapper <Playlist> playlistMapper = builder.Build <Playlist>();
            IConnectionPolicy      policy         = playlistMapper.GetConnectionPolicy();

            Playlist p = playlistMapper.GetAll().First();

            p.name = "teste";
            playlistMapper.Update(p);

            Playlist p2 = playlistMapper.GetAll().First();

            p2.name = "JoanaPlaylist";
            playlistMapper.Update(p2);
        }
Esempio n. 4
0
        public void UpdateProductsWithSuccess()
        {
            // Arrange
            Builder builder = new Builder(
                SqlDataMapperType,
                DataMapperParams,
                PropertyColumnMapperType,
                ExplicitConnectionPolicyType);

            IDataMapper <ProductSimple> productMapper            = builder.Build <ProductSimple>();
            IConnectionPolicy           explicitConnectionPolicy = productMapper.GetConnectionPolicy();

            // Act
            explicitConnectionPolicy.OpenConnection();
            explicitConnectionPolicy.BeginTransaction();

            ProductSimple p1 = productMapper.GetAll().First();

            p1.ProductName = "Potatoes";
            productMapper.Update(p1);

            ProductSimple p2 = productMapper.GetAll().First();

            // Assert
            Assert.AreEqual(p1.ProductName, p2.ProductName);
            explicitConnectionPolicy.RollBack();
            explicitConnectionPolicy.Dispose();
        }
Esempio n. 5
0
        public static void m1()
        {
            Builder builder = new Builder(
                typeof(SqlDataMapper <>),
                new Object[] { SqlMapperUnitTest.getMySqlConnectionString() },
                typeof(PropertyColumnMapper),
                typeof(SingleConnectionPolicy));

            IDataMapper <ProductSimple> productMapper = builder.Build <ProductSimple>();
            IConnectionPolicy           policy        = productMapper.GetConnectionPolicy();

            ProductSimple p = productMapper.GetAll().First();

            p.ProductName = "Potatoes";
            productMapper.Update(p);

            ProductSimple p2 = productMapper.GetAll().First();

            p2.ProductName = "Chai";
            productMapper.Update(p2);

            ProductSimple novoP = new ProductSimple();

            novoP.ProductName     = "batatas";
            novoP.QuantityPerUnit = "setenta mil";
            productMapper.Insert(novoP);
        }
Esempio n. 6
0
 public SqlEnumerable(IConnectionPolicy connectionPolicy, IColumnMapper columnMapper, string tableName, string whereClause = "")
 {
     this.connectionPolicy = connectionPolicy;
     this.columnMapper     = columnMapper;
     this.tableName        = tableName;
     this.whereClause      = whereClause;
     results = null;
 }
Esempio n. 7
0
 public void Set(IConnectionPolicy connectionPolicy)
 {
     lock (_policies)
     {
         _policies.Clear();
         _policies.Push(connectionPolicy);
     }
 }
Esempio n. 8
0
 public void Pop(IConnectionPolicy policy)
 {
     lock (_policies)
         if (_policies.Peek() == policy)
         {
             _policies.Pop();
         }
 }
Esempio n. 9
0
 public SqlEnumerable(IConnectionPolicy connectionPolicy, IColumnMapper columnMapper,
                      Dictionary <Type, IDataMapper> foreignMappers, string tableName, string whereClause = "")
 {
     this.connectionPolicy = connectionPolicy;
     this.columnMapper     = columnMapper;
     this.tableName        = tableName;
     this.whereClause      = whereClause;
     results             = null;
     this.foreignMappers = foreignMappers;
 }
Esempio n. 10
0
        public SqlDataMapper(Type objType, string connectionString, Type columnMapperType, Type connectionPolicyType)
        {
            this.objType = objType;
            this.connectionString = connectionString;
            tableName = objType.GetCustomAttributes(typeof(TableNameAttribute), false).FirstOrDefault().ToString();
            connectionPolicy = (AbstractConnectionPolicy)connectionPolicyType.GetConstructor(new Type[] { typeof(String) })
                .Invoke(new Object[] { connectionString });

            columnMapper = (IColumnMapper)columnMapperType
                .GetConstructor(new Type[] { typeof(Type), typeof(String), typeof(String) })
                .Invoke(new Object[] { objType, connectionString, tableName });
            foreignMappers = BuildForeignKeyMappers();
        }
Esempio n. 11
0
        public SqlDataMapper(Type objType, string connectionString, Type columnMapperType, Type connectionPolicyType)
        {
            this.objType          = objType;
            this.connectionString = connectionString;
            tableName             = objType.GetCustomAttributes(typeof(TableNameAttribute), false).FirstOrDefault().ToString();
            connectionPolicy      = (AbstractConnectionPolicy)connectionPolicyType.GetConstructor(new Type[] { typeof(String) })
                                    .Invoke(new Object[] { connectionString });

            columnMapper = (IColumnMapper)columnMapperType
                           .GetConstructor(new Type[] { typeof(Type), typeof(String), typeof(String) })
                           .Invoke(new Object[] { objType, connectionString, tableName });
            foreignMappers = BuildForeignKeyMappers();
        }
Esempio n. 12
0
 public void Push(IConnectionPolicy policy)
 {
     lock (_policies)
         _policies.Push(policy);
 }