root/UnityWeb/UnityWeb/Repository/Test/RepositoryTest/ProductDataProviderTest.cs

7782
4
using System.IO;
4
using System.IO;
5
using Domain.Business;
5
using Domain.Business;
6
using HibernatingRhinos.NHibernate.Profiler.Appender;
6
using HibernatingRhinos.NHibernate.Profiler.Appender;
7
using Microsoft.Practices.Unity;
7
using Modules.Base;
8
using NHibernate;
8
using Modules.Unity;
9
using NUnit.Framework;
9
using NUnit.Framework;
10
using Repository.NHibernateDataAccess;
10
using Repository.NHibernateDataAccess;
11
using Repository.NHibernateDataAccess.Providers.Interfaces;
11
using Repository.NHibernateDataAccess.Providers.Interfaces;
12
using StructureMap;
13
using StructureMap.Attributes;
12
14
13
#endregion
15
#endregion
14
16
...
...
24
    {
26
    {
25
        private IProductDataProvider _provider;
27
        private IProductDataProvider _provider;
26
28
27
        [Dependency]
29
        [SetterProperty]
28
        public IProductDataProvider DataProvider
30
        public IProductDataProvider DataProvider
29
        {
31
        {
30
            set { _provider = value; }
32
            set { _provider = value; }
...
...
35
        [SetUp]
37
        [SetUp]
36
        public void MyTestInitialize()
38
        public void MyTestInitialize()
37
        {
39
        {
38
            //UnityTestContainer.Instance.BuildUp(GetType(), this);
40
            ObjectFactory.BuildUp(this);
39
        }
41
        }
40
42
41
        //
43
        //
...
...
49
            string configDir = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\Deploy\Development\");
51
            string configDir = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\Deploy\Development\");
50
            string testConfigDir = Path.Combine(Environment.CurrentDirectory, @"Config\");
52
            string testConfigDir = Path.Combine(Environment.CurrentDirectory, @"Config\");
51
            DeploymentItem.DeployConfigs(configDir, testConfigDir);
53
            DeploymentItem.DeployConfigs(configDir, testConfigDir);
54
55
            ObjectFactory.Initialize(factory => factory.AddRegistry<StructureMapRegistery>());
52
        }
56
        }
53
57
54
        #endregion
58
        #endregion
...
...
74
        }
78
        }
75
79
76
        [Test]
80
        [Test]
81
        [BusinessConversation]
77
        public void ProductDataProviderGetProduct()
82
        public void ProductDataProviderGetProduct()
78
        {
83
        {
79
            const int id = 9;
84
            const int id = 9;
...
...
87
            Assert.IsTrue(Product.Category.Id > 0);
92
            Assert.IsTrue(Product.Category.Id > 0);
88
        }
93
        }
89
94
90
        [Test]
95
        //[Test]
91
        public void ProductDataProviderGetProducts()
96
        //[BusinessConversation]
92
        {
97
        //public void ProductDataProviderGetProducts()
93
            var sessionManager = new NHibernateSessionManager();
98
        //{
94
            using (var sess = sessionManager.GetSession())
99
        //    var sessionManager = new NHibernateSessionManager();
95
            {
100
        //    using (var sess = sessionManager.GetSession())
96
                using (var tx = sess.BeginTransaction())
101
        //    {
97
                {
102
        //        using (var tx = sess.BeginTransaction())
98
                    //var Products = sess.CreateCriteria(typeof (Product))
103
        //        {
99
                    //    .SetCacheable(true)
104
        //            //var Products = sess.CreateCriteria(typeof (Product))
100
                    //    .SetCacheMode(CacheMode.Normal)
105
        //            //    .SetCacheable(true)
101
                    //    .List<Product>();
106
        //            //    .SetCacheMode(CacheMode.Normal)
107
        //            //    .List<Product>();
102
108
103
                    ////var Products = _provider.GetProducts();
109
        //            ////var Products = _provider.GetProducts();
104
                    //Assert.IsNotNull(Products);
110
        //            //Assert.IsNotNull(Products);
105
                    //Assert.IsTrue(Products.Count > 0);
111
        //            //Assert.IsTrue(Products.Count > 0);
106
                    //Assert.IsTrue(Products[0].Id > 0);
112
        //            //Assert.IsTrue(Products[0].Id > 0);
107
                    //Assert.IsNotNull(Products[0].Supplier);
113
        //            //Assert.IsNotNull(Products[0].Supplier);
108
                    //Assert.IsTrue(Products[0].Supplier.Id > 0);
114
        //            //Assert.IsTrue(Products[0].Supplier.Id > 0);
109
                    //Assert.IsNotNull(Products[0].Category);
115
        //            //Assert.IsNotNull(Products[0].Category);
110
                    //Assert.IsTrue(Products[0].Category.Id > 0);
116
        //            //Assert.IsTrue(Products[0].Category.Id > 0);
111
117
112
118
113
                    const int id = 9;
119
        //            const int id = 9;
114
                    var Product = sess.Get<Product>(id);
120
        //            var Product = sess.Get<Product>(id);
115
121
116
                    Assert.IsNotNull(Product);
122
        //            Assert.IsNotNull(Product);
117
                    Assert.IsTrue(Product.Id == id);
123
        //            Assert.IsTrue(Product.Id == id);
118
                    Assert.IsNotNull(Product.Supplier);
124
        //            Assert.IsNotNull(Product.Supplier);
119
                    Assert.IsTrue(Product.Supplier.Id > 0);
125
        //            Assert.IsTrue(Product.Supplier.Id > 0);
120
                    Assert.IsNotNull(Product.Category);
126
        //            Assert.IsNotNull(Product.Category);
121
                    Assert.IsTrue(Product.Category.Id > 0);
127
        //            Assert.IsTrue(Product.Category.Id > 0);
122
128
123
                    tx.Commit();
129
        //            tx.Commit();
124
                }                
130
        //        }
125
131
126
                sess.Flush();
132
        //        sess.Flush();
127
            }
133
        //    }
128
        }
134
        //}
129
135
130
        #endregion
136
        #endregion
131
137