Skip to content

Commit 4a525ba

Browse files
committed
More tests for SqlCe40
1 parent 35d2b23 commit 4a525ba

10 files changed

Lines changed: 130 additions & 47 deletions

Simple.Data.SqlCe40/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
// The following GUID is for the ID of the typelib if this project is exposed to COM
1212
[assembly: Guid("2aa66263-94ee-46d5-bb0f-bae22bcec3e8")]
13+
14+
[assembly: InternalsVisibleTo("Simple.Data.SqlCe40Test")]

Simple.Data.SqlCe40/SqlCe40ConnectionProvider.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,6 @@ public string GetIdentityFunction()
5959
return "@@IDENTITY";
6060
}
6161

62-
public bool TryGetNewRowSelect(Table table, out string selectSql)
63-
{
64-
var identityColumn = table.Columns.FirstOrDefault(col => col.IsIdentity);
65-
66-
if (identityColumn == null)
67-
{
68-
selectSql = null;
69-
return false;
70-
}
71-
72-
selectSql = "select * from " + table.QualifiedName + " where " + identityColumn.QuotedName +
73-
" = @@IDENTITY";
74-
return true;
75-
}
76-
7762
public bool SupportsCompoundStatements
7863
{
7964
get { return false; }

Simple.Data.SqlCe40/SqlCe40QueryPager.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,5 @@ public string ApplyPaging(string sql, string skipParameterName, string takeParam
2424

2525
return string.Format("{0} OFFSET {1} ROWS FETCH NEXT {2} ROWS ONLY", sql, skipParameterName, takeParameterName);
2626
}
27-
28-
private static string ExtractOrderBy(string columns, ref string fromEtc)
29-
{
30-
string orderBy;
31-
int index = fromEtc.IndexOf("ORDER BY", StringComparison.InvariantCultureIgnoreCase);
32-
if (index > -1)
33-
{
34-
orderBy = fromEtc.Substring(index).Trim();
35-
fromEtc = fromEtc.Remove(index).Trim();
36-
}
37-
else
38-
{
39-
orderBy = "ORDER BY " + columns.Split(',').First().Trim();
40-
}
41-
return orderBy;
42-
}
4327
}
4428
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Simple.Data.SqlCe40Test
7+
{
8+
using Ado;
9+
using NUnit.Framework;
10+
using SqlCe40;
11+
12+
[TestFixture]
13+
class ConnectionProviderTest
14+
{
15+
[Test]
16+
public void SqlCeDoesNotSupportStoredProcedures()
17+
{
18+
IConnectionProvider target = new SqlCe40ConnectionProvider();
19+
Assert.IsFalse(target.SupportsStoredProcedures);
20+
Assert.Throws<NotSupportedException>(() => target.GetProcedureExecutor(null, null));
21+
}
22+
23+
[Test]
24+
public void SqlCeDoesNotSupportCompoundStatements()
25+
{
26+
IConnectionProvider target = new SqlCe40ConnectionProvider();
27+
Assert.IsFalse(target.SupportsCompoundStatements);
28+
}
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Simple.Data.SqlCe40Test
2+
{
3+
using System;
4+
using System.Linq;
5+
using NUnit.Framework;
6+
using Simple.Data.SqlCe40;
7+
8+
[TestFixture]
9+
public class SchemaProviderTest
10+
{
11+
[Test]
12+
public void NullConnectionProviderCausesException()
13+
{
14+
Assert.Throws<ArgumentNullException>(() => new SqlCe40SchemaProvider(null));
15+
}
16+
17+
[Test]
18+
public void ProceduresIsEmpty()
19+
{
20+
Assert.AreEqual(0, new SqlCe40SchemaProvider(new SqlCe40ConnectionProvider()).GetStoredProcedures().Count());
21+
}
22+
}
23+
}

Simple.Data.SqlCe40Test/Simple.Data.SqlCe40Test.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@
7373
</CodeAnalysisDependentAssemblyPaths>
7474
</ItemGroup>
7575
<ItemGroup>
76+
<Compile Include="ConnectionProviderTest.cs" />
7677
<Compile Include="FindTests.cs" />
7778
<Compile Include="InsertTests.cs" />
7879
<Compile Include="NorthwindTests.cs" />
7980
<Compile Include="OrderDetailTests.cs" />
8081
<Compile Include="Properties\AssemblyInfo.cs" />
8182
<Compile Include="QueryTest.cs" />
83+
<Compile Include="SchemaProviderTest.cs" />
8284
<Compile Include="SqlCe40QueryPagerTest.cs" />
8385
<Compile Include="SchemaTests\DatabaseSchemaTests.cs" />
8486
<Compile Include="User.cs" />
@@ -148,7 +150,8 @@ copy "..\..\packages\SqlServerCompact.4.0.8482.1\NativeBinaries\amd64\*.dll" "$(
148150
</PropertyGroup>-->
149151
<PropertyGroup Condition="'$(SolutionDir)' == '' or '$(SolutionDir)' == '*undefined*'">
150152
<SolutionDir>..\..\</SolutionDir>
151-
</PropertyGroup> <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
153+
</PropertyGroup>
154+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
152155
Other similar extension points exist, see Microsoft.Common.targets.
153156
<Target Name="BeforeBuild">
154157
</Target>

Simple.Data.UnitTest/ConcreteCollectionTypeCreatorTest.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Simple.Data.UnitTest
22
{
3+
using System;
34
using System.Collections;
45
using System.Collections.Generic;
56
using NUnit.Framework;
@@ -57,5 +58,56 @@ public void ArrayListTest()
5758
Assert.IsTrue(list.Contains("Foo"));
5859
Assert.IsTrue(list.Contains("Bar"));
5960
}
61+
62+
[Test]
63+
public void TryConvertElementShouldConvertStringToEnum()
64+
{
65+
var testCreator = new TestCreator();
66+
object result;
67+
Assert.IsTrue(testCreator.TestTryConvertElement(typeof(TestEnum), "Value", out result));
68+
Assert.AreEqual(TestEnum.Value, result);
69+
}
70+
71+
[Test]
72+
public void TryConvertElementShouldConvertIntToEnum()
73+
{
74+
var testCreator = new TestCreator();
75+
object result;
76+
Assert.IsTrue(testCreator.TestTryConvertElement(typeof(TestEnum), 1, out result));
77+
Assert.AreEqual(TestEnum.Value, result);
78+
}
79+
80+
[Test]
81+
public void TryConvertElementShouldConvertIntToNullableInt()
82+
{
83+
var testCreator = new TestCreator();
84+
object result;
85+
Assert.IsTrue(testCreator.TestTryConvertElement(typeof(int?), 1, out result));
86+
Assert.AreEqual(1, result);
87+
}
88+
89+
enum TestEnum
90+
{
91+
None = 0,
92+
Value = 1
93+
}
94+
}
95+
96+
class TestCreator : ConcreteCollectionTypeCreator.Creator
97+
{
98+
public override bool IsCollectionType(Type type)
99+
{
100+
return typeof (ICollection).IsAssignableFrom(type);
101+
}
102+
103+
public override bool TryCreate(Type type, IEnumerable items, out object result)
104+
{
105+
throw new NotImplementedException();
106+
}
107+
108+
public bool TestTryConvertElement(Type type, object value, out object result)
109+
{
110+
return TryConvertElement(type, value, out result);
111+
}
60112
}
61113
}

Simple.Data/ConcreteCollectionTypeCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static bool TryCreate(Type type, IEnumerable items, out object result)
2727
return _creators.First(c => c.IsCollectionType(type)).TryCreate(type, items, out result);
2828
}
2929

30-
private abstract class Creator
30+
internal abstract class Creator
3131
{
3232
public abstract bool IsCollectionType(Type type);
3333

Simple.Data/SimpleQuery.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace Simple.Data
1212
{
13+
using System.Threading.Tasks;
14+
1315
public class SimpleQuery : DynamicObject, IEnumerable
1416
{
1517
private DataStrategy _dataStrategy;
@@ -177,17 +179,14 @@ public SimpleQuery Take(int take)
177179
return new SimpleQuery(this, takeCount: take);
178180
}
179181

180-
protected IEnumerable<dynamic> Records
182+
protected IEnumerable<dynamic> Run()
181183
{
182-
get
183-
{
184-
return _adapter.RunQuery(this).Select(d => new SimpleRecord(d, _tableName, _dataStrategy));
185-
}
184+
return _adapter.RunQuery(this).Select(d => new SimpleRecord(d, _tableName, _dataStrategy));
186185
}
187186

188187
public IEnumerator GetEnumerator()
189188
{
190-
return Records.GetEnumerator();
189+
return Run().GetEnumerator();
191190
}
192191

193192
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
@@ -325,12 +324,12 @@ private SimpleQuery ParseThenBy(string methodName)
325324

326325
public IEnumerable<T> Cast<T>()
327326
{
328-
return Records.Select(item => (T)item);
327+
return Run().Select(item => (T)item);
329328
}
330329

331330
public IEnumerable<T> OfType<T>()
332331
{
333-
foreach (var item in Records)
332+
foreach (var item in Run())
334333
{
335334
bool success = true;
336335
T cast;
@@ -352,12 +351,12 @@ public IEnumerable<T> OfType<T>()
352351

353352
public IList<dynamic> ToList()
354353
{
355-
return Records.ToList();
354+
return Run().ToList();
356355
}
357356

358357
public dynamic[] ToArray()
359358
{
360-
return Records.ToArray();
359+
return Run().ToArray();
361360
}
362361

363362
public dynamic ToScalar()
@@ -443,12 +442,12 @@ public T ToScalarOrDefault<T>()
443442

444443
public dynamic First()
445444
{
446-
return Records.First();
445+
return Run().First();
447446
}
448447

449448
public dynamic FirstOrDefault()
450449
{
451-
return Records.FirstOrDefault();
450+
return Run().FirstOrDefault();
452451
}
453452

454453
public T First<T>()
@@ -473,12 +472,12 @@ public T FirstOrDefault<T>(Func<T, bool> predicate)
473472

474473
public dynamic Single()
475474
{
476-
return Records.First();
475+
return Run().First();
477476
}
478477

479478
public dynamic SingleOrDefault()
480479
{
481-
return Records.FirstOrDefault();
480+
return Run().FirstOrDefault();
482481
}
483482

484483
public T Single<T>()
@@ -548,5 +547,10 @@ public IObservable<dynamic> AsObservable()
548547
}
549548

550549
private Func<IObservable<dynamic>> _asObservableImplementation;
550+
551+
public Task<IEnumerable<dynamic>> RunTask()
552+
{
553+
return Task.Factory.StartNew<IEnumerable<dynamic>>(Run);
554+
}
551555
}
552556
}

Simple.Data_mm_cache.bin

-23.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)