PageRenderTime 359ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/System.Data.Linq/src/DbLinq/Test/Providers/DataLoadOptions_Test.cs

https://bitbucket.org/danipen/mono
C# | 131 lines | 117 code | 13 blank | 1 comment | 6 complexity | 362a63548c7844b661b9b9f427f63e4b MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Text;
  5using NUnit.Framework;
  6using Test_NUnit;
  7
  8using nwind;
  9
 10#if MONO_STRICT
 11using System.Data.Linq;
 12#else
 13using DbLinq.Data.Linq;
 14#endif
 15
 16namespace nwind
 17{
 18    public partial class Customer
 19    {
 20        public object ExtraneousMethod()
 21        {
 22            return null;
 23        }
 24    }
 25}
 26
 27// test ns 
 28#if MYSQL
 29    namespace Test_NUnit_MySql
 30#elif ORACLE && ODP
 31    namespace Test_NUnit_OracleODP
 32#elif ORACLE
 33    namespace Test_NUnit_Oracle
 34#elif POSTGRES
 35    namespace Test_NUnit_PostgreSql
 36#elif SQLITE
 37    namespace Test_NUnit_Sqlite
 38#elif INGRES
 39    namespace Test_NUnit_Ingres
 40#elif MSSQL && L2SQL
 41    namespace Test_NUnit_MsSql_Strict
 42#elif MSSQL
 43    namespace Test_NUnit_MsSql
 44#elif FIREBIRD
 45    namespace Test_NUnit_Firebird
 46#endif
 47{
 48    [TestFixture]
 49    public class DataLoadOptions_Test : TestBase
 50    {
 51        static object ThrowException()
 52        {
 53            throw new ApplicationException();
 54        }
 55
 56        [Test]
 57        [ExpectedException(typeof(InvalidOperationException))]
 58        public void LoadWith_BadExpression1()
 59        {
 60            new DataLoadOptions().LoadWith<Customer>(cc => cc.ExtraneousMethod());
 61        }
 62
 63        [Test]
 64        [ExpectedException(typeof(InvalidOperationException))]
 65        public void LoadWith_BadExpression2()
 66        {
 67            new DataLoadOptions().LoadWith<Customer>(cc => 1);
 68        }
 69
 70        [Test]
 71        [ExpectedException(typeof(InvalidOperationException))]
 72        public void LoadWith_BadExpression3()
 73        {
 74            new DataLoadOptions().LoadWith<Customer>(cc => ThrowException());
 75        }
 76
 77        [Test]
 78        [ExpectedException(typeof(InvalidOperationException))]
 79        public void LoadWith_BadExpression4()
 80        {
 81            new DataLoadOptions().LoadWith<Customer>(cc => cc.Orders.Select(o => o));
 82        }
 83
 84        [Test]
 85        [ExpectedException(typeof(InvalidOperationException))]
 86        public void LoadWith_BadExpression5()
 87        {
 88            new DataLoadOptions().LoadWith<Order> (o => o.Customer.Orders);
 89        }
 90
 91#if !DEBUG && (MSSQL && !L2SQL)
 92        [Explicit]
 93#endif
 94        [Test]
 95        [ExpectedException(typeof(InvalidOperationException))]
 96        public void LoadWith_BadCycles1()
 97        {
 98            var lo = new DataLoadOptions();
 99            lo.LoadWith<Customer>(c => c.Orders);
100            lo.LoadWith<Order>(o => o.Customer);
101        }
102
103#if !DEBUG && (MSSQL && !L2SQL)
104        [Explicit]
105#endif
106        [Test]
107        [ExpectedException(typeof(InvalidOperationException))]
108        public void LoadWith_BadCycles2()
109        {
110            var lo = new DataLoadOptions();
111            lo.LoadWith<Order>(o => o.Customer);
112            lo.LoadWith<Customer>(c => c.Orders);
113        }
114
115        [Test]
116        public void LoadWith_Good1()
117        {
118            var lo = new DataLoadOptions();
119            lo.LoadWith<Customer>(c => c.Orders);
120            lo.LoadWith<Order>(o => o.Employee);
121        }
122
123        [Test]
124        public void LoadWith_Good2()
125        {
126            var lo = new DataLoadOptions();
127            lo.LoadWith<Order>(o => o.Employee);
128            lo.LoadWith<Customer>(c => c.Orders);
129        }
130    }
131}