Skip to content

Commit 844da3d

Browse files
committed
Test coverage increased - over 80%
1 parent 4ad55df commit 844da3d

24 files changed

+1047
-104
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace Simple.Data.Ado.Test
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data.SqlClient;
6+
using NUnit.Framework;
7+
8+
[TestFixture]
9+
public class AdoAdapterExceptionTest
10+
{
11+
[Test]
12+
public void EmptyConstructorShouldSetAdapterType()
13+
{
14+
var actual = new AdoAdapterException();
15+
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
16+
}
17+
18+
[Test]
19+
public void SingleStringConstructorShouldSetMessageAndAdapterType()
20+
{
21+
var actual = new AdoAdapterException("Foo");
22+
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
23+
Assert.AreEqual("Foo", actual.Message);
24+
}
25+
26+
[Test]
27+
public void StringAndExceptionConstructorShouldSetMessageAndInnerExceptionAndAdapterType()
28+
{
29+
var inner = new Exception();
30+
var actual = new AdoAdapterException("Foo", inner);
31+
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
32+
Assert.AreEqual("Foo", actual.Message);
33+
Assert.AreSame(inner, actual.InnerException);
34+
}
35+
36+
[Test]
37+
public void StringAndDbCommandConstructorShouldSetMessageAndCommandTextAndAdapterType()
38+
{
39+
var command = new SqlCommand("Bar");
40+
var actual = new AdoAdapterException("Foo", command);
41+
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
42+
Assert.AreEqual("Foo", actual.Message);
43+
Assert.AreEqual(command.CommandText, actual.CommandText);
44+
}
45+
46+
[Test]
47+
public void StringAndDictionaryConstructorShouldSetCommandTextAndParametersAndAdapterType()
48+
{
49+
var param = new Dictionary<string, object> { { "P", "quux" } };
50+
var actual = new AdoAdapterException("Foo", param);
51+
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
52+
Assert.AreEqual("Foo", actual.CommandText);
53+
Assert.AreEqual("quux", actual.Parameters["P"]);
54+
}
55+
56+
[Test]
57+
public void StringAndStringAndDictionaryConstructorShouldSetMessageAndCommandTextAndParametersAndAdapterType()
58+
{
59+
var param = new Dictionary<string, object> { { "P", "quux" } };
60+
var actual = new AdoAdapterException("Foo", "Bar", param);
61+
Assert.AreEqual(typeof(AdoAdapter), actual.AdapterType);
62+
Assert.AreEqual("Foo", actual.Message);
63+
Assert.AreEqual("Bar", actual.CommandText);
64+
Assert.AreEqual("quux", actual.Parameters["P"]);
65+
}
66+
}
67+
}

Simple.Data.Ado.Test/Simple.Data.Ado.Test.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -52,6 +52,7 @@
5252
</Reference>
5353
</ItemGroup>
5454
<ItemGroup>
55+
<Compile Include="AdoAdapterExceptionTest.cs" />
5556
<Compile Include="Properties\AssemblyInfo.cs" />
5657
<Compile Include="TableCollectionTest.cs" />
5758
<Compile Include="TestCustomInserter.cs" />

Simple.Data.Ado/ProviderHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ private static string GetFileExtension(string filename)
7070

7171
private static IConnectionProvider ComposeProvider()
7272
{
73-
return MefHelper.Compose<IConnectionProvider>();
73+
return Composer.Default.Compose<IConnectionProvider>();
7474
}
7575

7676
private static IConnectionProvider ComposeProvider(string extension)
7777
{
78-
return MefHelper.Compose<IConnectionProvider>(extension);
78+
return Composer.Default.Compose<IConnectionProvider>(extension);
7979
}
8080

8181
public IConnectionProvider GetProviderByConnectionName(string connectionName)

Simple.Data.BehaviourTest/SchemaQualifiedTableTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ public void TestFindByDynamicTwoColumns()
107107
}
108108

109109
[Test]
110-
[Ignore]
111110
public void TestFindAllByDynamic()
112111
{
113112
var mockDatabase = new MockDatabase();
114113
dynamic database = CreateDatabase(mockDatabase);
115-
database.foo.Users.FindAllByName("Foo");
116-
Assert.AreEqual("select [foo].[Users].* from [foo].[Users] where [foo].[Users].[name] = @p1".ToLowerInvariant(), mockDatabase.Sql.ToLowerInvariant());
114+
database.foo.Users.FindAllByName("Foo").ToList();
115+
Assert.AreEqual("select [foo].[Users].[Id],[foo].[Users].[Name],[foo].[Users].[Password],[foo].[Users].[Age] from [foo].[Users] where [foo].[Users].[name] = @p1".ToLowerInvariant(), mockDatabase.Sql.ToLowerInvariant());
117116
Assert.AreEqual("Foo", mockDatabase.Parameters[0]);
118117
}
119118

Simple.Data.SqlCe40Test/SchemaTests/DatabaseSchemaTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ public void TestPrimaryKey()
4141
}
4242

4343
[Test]
44-
[Ignore]
4544
public void TestForeignKey()
4645
{
4746
var foreignKey = Schema.FindTable("Orders").ForeignKeys.Single();
48-
Assert.AreEqual("Customers", foreignKey.MasterTable);
49-
Assert.AreEqual("Orders", foreignKey.DetailTable);
47+
Assert.AreEqual("Customers", foreignKey.MasterTable.Name);
48+
Assert.AreEqual("Orders", foreignKey.DetailTable.Name);
5049
Assert.AreEqual("CustomerId", foreignKey.Columns[0]);
5150
Assert.AreEqual("CustomerId", foreignKey.UniqueColumns[0]);
5251
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
namespace Simple.Data.UnitTest
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class AdapterFactoryTest
9+
{
10+
private static AdapterFactory CreateTarget()
11+
{
12+
return new CachingAdapterFactory(new StubComposer());
13+
}
14+
15+
[Test]
16+
[ExpectedException(typeof(ArgumentException))]
17+
public void CreateWithAnonymousObjectWithoutConnectionStringThrowsArgumentException()
18+
{
19+
CreateTarget().Create(new { X = "" });
20+
}
21+
22+
[Test]
23+
public void CreateWithName()
24+
{
25+
var actual = CreateTarget().Create("Stub", null);
26+
Assert.IsNotNull(actual);
27+
}
28+
}
29+
30+
class StubComposer : Composer
31+
{
32+
public override T Compose<T>()
33+
{
34+
return (T) Create();
35+
}
36+
37+
public override T Compose<T>(string contractName)
38+
{
39+
return (T)Create();
40+
}
41+
42+
private object Create()
43+
{
44+
return new StubAdapter();
45+
}
46+
}
47+
48+
class StubAdapter : Adapter
49+
{
50+
public override IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria)
51+
{
52+
throw new NotImplementedException();
53+
}
54+
55+
public override IEnumerable<IDictionary<string, object>> RunQuery(SimpleQuery query)
56+
{
57+
throw new NotImplementedException();
58+
}
59+
60+
public override IDictionary<string, object> Insert(string tableName, IDictionary<string, object> data)
61+
{
62+
throw new NotImplementedException();
63+
}
64+
65+
public override int Update(string tableName, IDictionary<string, object> data, SimpleExpression criteria)
66+
{
67+
throw new NotImplementedException();
68+
}
69+
70+
public override int Delete(string tableName, SimpleExpression criteria)
71+
{
72+
throw new NotImplementedException();
73+
}
74+
75+
public override IEnumerable<string> GetKeyFieldNames(string tableName)
76+
{
77+
throw new NotImplementedException();
78+
}
79+
}
80+
}
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Linq;
43
using System.Text;
54
using System.Threading;
@@ -27,34 +26,4 @@ public void ShouldCallCleanup()
2726
Assert.True(cleanedUp);
2827
}
2928
}
30-
31-
[TestFixture]
32-
public class MaybeTest
33-
{
34-
35-
[Test]
36-
public void MaybeNoneShouldBeFalse()
37-
{
38-
Assert.False(Maybe<int>.None.HasValue);
39-
}
40-
41-
[Test]
42-
public void MaybeSomeShouldBeTrue()
43-
{
44-
Assert.True(Maybe<int>.Some(1).HasValue);
45-
}
46-
47-
[Test]
48-
public void IteratorShouldRun()
49-
{
50-
int n = 0;
51-
Func<Maybe<int>> iterator = () => ++n < 10 ? n : Maybe<int>.None;
52-
Maybe<int> maybe;
53-
while ((maybe = iterator()).HasValue)
54-
{
55-
Assert.AreEqual(n, maybe.Value);
56-
}
57-
Assert.False(maybe.HasValue);
58-
}
59-
}
6029
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
namespace Simple.Data.UnitTest
2+
{
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class ConcreteCollectionTypeCreatorTest
9+
{
10+
private IEnumerable<dynamic> Items()
11+
{
12+
yield return "Foo";
13+
yield return "Bar";
14+
}
15+
16+
[Test]
17+
public void ListTest()
18+
{
19+
object result;
20+
ConcreteCollectionTypeCreator.TryCreate(typeof (List<string>), Items(), out result);
21+
Assert.IsNotNull(result);
22+
23+
var list = result as List<string>;
24+
25+
Assert.IsNotNull(list);
26+
Assert.AreEqual(2, list.Count);
27+
Assert.IsTrue(list.Contains("Foo"));
28+
Assert.IsTrue(list.Contains("Bar"));
29+
}
30+
31+
[Test]
32+
public void SetTest()
33+
{
34+
object result;
35+
ConcreteCollectionTypeCreator.TryCreate(typeof(HashSet<string>), Items(), out result);
36+
Assert.IsNotNull(result);
37+
38+
var @set = result as HashSet<string>;
39+
40+
Assert.IsNotNull(@set);
41+
Assert.AreEqual(2, @set.Count);
42+
Assert.IsTrue(@set.Contains("Foo"));
43+
Assert.IsTrue(@set.Contains("Bar"));
44+
}
45+
46+
[Test]
47+
public void ArrayListTest()
48+
{
49+
object result;
50+
ConcreteCollectionTypeCreator.TryCreate(typeof(ArrayList), Items(), out result);
51+
Assert.IsNotNull(result);
52+
53+
var list = result as ArrayList;
54+
55+
Assert.IsNotNull(list);
56+
Assert.AreEqual(2, list.Count);
57+
Assert.IsTrue(list.Contains("Foo"));
58+
Assert.IsTrue(list.Contains("Bar"));
59+
}
60+
}
61+
}

Simple.Data.UnitTest/DataRecordExtensionsTest.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)