Skip to content

Commit

Permalink
Add unit tests for the SqliteStorageEngineBuilder class
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavien committed Dec 16, 2015
1 parent d03abde commit 003fbc9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/Openchain.Sqlite/SqliteStorageEngineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public class SqliteStorageEngineBuilder : IComponentBuilder<SqliteLedger>
private static readonly string columnAlreadyExistsMessage = "SQLite Error 1: 'duplicate column name: Name'";
private string filename;

public string Name { get; } = "Sqlite";

public SqliteStorageEngineBuilder(string filename)
{
this.filename = filename;
}
public string Name { get; } = "SQLite";

public SqliteStorageEngineBuilder()
{ }
Expand Down
59 changes: 59 additions & 0 deletions test/Openchain.Sqlite.Tests/SqliteStorageEngineBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2015 Coinprism, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Xunit;

namespace Openchain.Sqlite.Tests
{
public class SqliteStorageEngineBuilderTests
{
[Fact]
public void Name_Success()
{
Assert.Equal("SQLite", new SqliteStorageEngineBuilder().Name);
}

[Fact]
public async Task Build_Success()
{
Dictionary<string, string> parameters = new Dictionary<string, string>() { ["path"] = ":memory:" };
SqliteStorageEngineBuilder builder = new SqliteStorageEngineBuilder();

await builder.Initialize(parameters);

SqliteLedger ledger = builder.Build(null);

Assert.NotNull(ledger);
}

[Fact]
public async Task InitializeTables_CallTwice()
{
Dictionary<string, string> parameters = new Dictionary<string, string>() { ["path"] = ":memory:" };
SqliteStorageEngineBuilder builder = new SqliteStorageEngineBuilder();

await builder.Initialize(parameters);

SqliteLedger ledger = builder.Build(null);

await SqliteStorageEngineBuilder.InitializeTables(ledger.Connection);
await SqliteStorageEngineBuilder.InitializeTables(ledger.Connection);

Assert.Equal(ConnectionState.Open, ledger.Connection.State);
}
}
}

0 comments on commit 003fbc9

Please sign in to comment.