PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

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