11using NUnit . Framework ;
2+ using Shouldly ;
23
34namespace SqlInliner . Tests ;
45
@@ -23,11 +24,11 @@ public void ViewWithLeftOuterJoin_Inlines()
2324 const string viewSql = "CREATE VIEW dbo.VTest AS SELECT p.Id, p.FirstName, o.Amount FROM dbo.VPeople p LEFT OUTER JOIN dbo.VOrders o ON p.Id = o.PersonId" ;
2425
2526 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
26- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
27- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
28- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.Orders" ) ) ;
29- Assert . IsFalse ( inliner . Result . ConvertedSql . Contains ( "dbo.VPeople" ) ) ;
30- Assert . IsFalse ( inliner . Result . ConvertedSql . Contains ( "dbo.VOrders" ) ) ;
27+ inliner . Errors . Count . ShouldBe ( 0 ) ;
28+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
29+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.Orders" ) ;
30+ inliner . Result . ConvertedSql . ShouldNotContain ( "dbo.VPeople" ) ;
31+ inliner . Result . ConvertedSql . ShouldNotContain ( "dbo.VOrders" ) ;
3132 }
3233
3334 [ Test ]
@@ -36,9 +37,9 @@ public void ViewWithRightOuterJoin_Inlines()
3637 const string viewSql = "CREATE VIEW dbo.VTest AS SELECT p.Id, p.FirstName, o.Amount FROM dbo.VPeople p RIGHT OUTER JOIN dbo.VOrders o ON p.Id = o.PersonId" ;
3738
3839 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
39- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
40- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
41- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.Orders" ) ) ;
40+ inliner . Errors . Count . ShouldBe ( 0 ) ;
41+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
42+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.Orders" ) ;
4243 }
4344
4445 [ Test ]
@@ -47,9 +48,9 @@ public void ViewWithFullOuterJoin_Inlines()
4748 const string viewSql = "CREATE VIEW dbo.VTest AS SELECT p.Id, p.FirstName, o.Amount FROM dbo.VPeople p FULL OUTER JOIN dbo.VOrders o ON p.Id = o.PersonId" ;
4849
4950 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
50- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
51- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
52- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.Orders" ) ) ;
51+ inliner . Errors . Count . ShouldBe ( 0 ) ;
52+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
53+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.Orders" ) ;
5354 }
5455
5556 [ Test ]
@@ -65,10 +66,10 @@ FROM dbo.VPeople p
6566 INNER JOIN dbo.VProducts pr ON o.Id = pr.Id" ;
6667
6768 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
68- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
69- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
70- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.Orders" ) ) ;
71- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.Products" ) ) ;
69+ inliner . Errors . Count . ShouldBe ( 0 ) ;
70+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
71+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.Orders" ) ;
72+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.Products" ) ;
7273 }
7374
7475 [ Test ]
@@ -81,11 +82,13 @@ public void ThreeLevelNesting_Inlines()
8182
8283 const string viewSql = "CREATE VIEW dbo.VLevel4 AS SELECT l3.Id FROM dbo.VLevel3 l3" ;
8384
85+ var options = InlinerOptions . Recommended ( ) ;
86+ options . StripUnusedJoins = false ;
8487 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
85- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
86- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
87- Assert . IsFalse ( inliner . Result . ConvertedSql . Contains ( "VLevel2" ) ) ;
88- Assert . IsFalse ( inliner . Result . ConvertedSql . Contains ( "VLevel3" ) ) ;
88+ inliner . Errors . Count . ShouldBe ( 0 ) ;
89+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
90+ inliner . Result . ConvertedSql . ShouldNotContain ( "VLevel2" ) ;
91+ inliner . Result . ConvertedSql . ShouldNotContain ( "VLevel3" ) ;
8992 }
9093
9194 [ Test ]
@@ -97,8 +100,8 @@ public void ViewWithSubquery_Inlines()
97100 FROM dbo.VPeople p" ;
98101
99102 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
100- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
101- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
103+ inliner . Errors . Count . ShouldBe ( 0 ) ;
104+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
102105 }
103106
104107 [ Test ]
@@ -111,8 +114,8 @@ FROM dbo.VPeople p
111114 GROUP BY p.Id, p.FirstName" ;
112115
113116 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
114- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
115- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
117+ inliner . Errors . Count . ShouldBe ( 0 ) ;
118+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
116119 }
117120
118121 [ Test ]
@@ -121,8 +124,8 @@ public void ViewWithOrderBy_Inlines()
121124 const string viewSql = "CREATE VIEW dbo.VTest AS SELECT TOP 100 p.Id, p.FirstName FROM dbo.VPeople p ORDER BY p.FirstName" ;
122125
123126 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
124- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
125- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
127+ inliner . Errors . Count . ShouldBe ( 0 ) ;
128+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
126129 }
127130
128131 [ Test ]
@@ -134,19 +137,21 @@ public void ViewWithCaseStatement_Inlines()
134137 FROM dbo.VPeople p" ;
135138
136139 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
137- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
138- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
140+ inliner . Errors . Count . ShouldBe ( 0 ) ;
141+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
139142 }
140143
141144 [ Test ]
142145 public void ViewWithDistinct_Inlines ( )
143146 {
144147 const string viewSql = "CREATE VIEW dbo.VTest AS SELECT DISTINCT p.LastName FROM dbo.VPeople p" ;
145148
149+ var options = InlinerOptions . Recommended ( ) ;
150+ options . StripUnusedJoins = false ;
146151 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
147- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
148- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
149- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "DISTINCT" ) ) ;
152+ inliner . Errors . Count . ShouldBe ( 0 ) ;
153+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
154+ inliner . Result . ConvertedSql . ShouldContain ( "DISTINCT" ) ;
150155 }
151156
152157 [ Test ]
@@ -158,7 +163,7 @@ FROM dbo.VPeople p
158163 WHERE p.IsActive = 1 AND p.LastName IS NOT NULL" ;
159164
160165 var inliner = new DatabaseViewInliner ( connection , viewSql , options ) ;
161- Assert . AreEqual ( 0 , inliner . Errors . Count ) ;
162- Assert . IsTrue ( inliner . Result . ConvertedSql . Contains ( "dbo.People" ) ) ;
166+ inliner . Errors . Count . ShouldBe ( 0 ) ;
167+ inliner . Result . ConvertedSql . ShouldContain ( "dbo.People" ) ;
163168 }
164- }
169+ }
0 commit comments