All Projects → UnoSD → Moq.dapper

UnoSD / Moq.dapper

Licence: gpl-2.0
Moq extensions for Dapper methods.

Projects that are alternatives of or similar to Moq.dapper

Slickone
A Quick Enterprise Web Framework for Information System 企业级Web快速开发框架
Stars: ✭ 87 (-16.35%)
Mutual labels:  dapper
Devel Cover
Code coverage metrics for Perl
Stars: ✭ 91 (-12.5%)
Mutual labels:  test
Cize
🔌 Continuous integration with the simplest solution
Stars: ✭ 100 (-3.85%)
Mutual labels:  test
Test Each
🤖 Repeat tests. Repeat tests. Repeat tests.
Stars: ✭ 89 (-14.42%)
Mutual labels:  test
Dotnetcore Microservices Poc
Very simplified insurance sales system made in a microservices architecture using .NET Core
Stars: ✭ 1,304 (+1153.85%)
Mutual labels:  dapper
Webtimesheetmanagement
Basic TimeSheet Management Application in ASP.NET MVC 5
Stars: ✭ 93 (-10.58%)
Mutual labels:  dapper
Sample Dotnet Core Cqrs Api
Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture.
Stars: ✭ 1,273 (+1124.04%)
Mutual labels:  dapper
Gltf Asset Generator
Tool for generating various glTF assets for importer validation
Stars: ✭ 103 (-0.96%)
Mutual labels:  test
Packcheck
Universal build and CI testing for Haskell packages
Stars: ✭ 91 (-12.5%)
Mutual labels:  test
Ntf
Network Testing Framework
Stars: ✭ 96 (-7.69%)
Mutual labels:  test
Tyu
Unit test with no initial configuration.
Stars: ✭ 89 (-14.42%)
Mutual labels:  test
Rebar3
Erlang build tool that makes it easy to compile and test Erlang applications and releases.
Stars: ✭ 1,295 (+1145.19%)
Mutual labels:  test
Faux Jax
NO MORE MAINTAINED: Intercept and respond to requests in the browser (AJAX) and Node.js (http(s) module)
Stars: ✭ 93 (-10.58%)
Mutual labels:  test
Scalatestplus Play
ScalaTest + Play
Stars: ✭ 88 (-15.38%)
Mutual labels:  test
Esbuild Jest
A Jest transformer using esbuild
Stars: ✭ 100 (-3.85%)
Mutual labels:  test
A11y.css
This CSS file intends to warn developers about possible risks and mistakes that exist in HTML code. It can also be used to roughly evaluate a site's quality by simply including it as an external stylesheet.
Stars: ✭ 1,277 (+1127.88%)
Mutual labels:  test
React Pinpoint
An open source utility library for measuring React component render times.
Stars: ✭ 93 (-10.58%)
Mutual labels:  test
Spek
🎏 Function builder BDD testing framework in Swift
Stars: ✭ 104 (+0%)
Mutual labels:  test
Atoum
The modern, simple and intuitive PHP unit testing framework.
Stars: ✭ 1,382 (+1228.85%)
Mutual labels:  test
Kotlinfixture
Fixtures for Kotlin providing generated values for unit testing
Stars: ✭ 94 (-9.62%)
Mutual labels:  test

Moq.Dapper

Moq extensions for Dapper methods.

NuGet Version and Downloads count

Example usage

Mocking a call to Query with a simple type:

[Test]
public void QueryGeneric()
{
    var connection = new Mock<IDbConnection>();

    var expected = new[] { 7, 77, 777 };

    connection.SetupDapper(c => c.Query<int>(It.IsAny<string>(), null, null, true, null, null))
              .Returns(expected);

    var actual = connection.Object.Query<int>("", null, null, true, null, null).ToList();

    Assert.That(actual.Count, Is.EqualTo(expected.Length));
    Assert.That(actual, Is.EquivalentTo(expected));
}

Mocking a call to Query with a complex type:

[Test]
public void QueryGenericComplexType()
{
    var connection = new Mock<IDbConnection>();

    var expected = new[]
    {
        new ComplexType { StringProperty = "String1", IntegerProperty = 7 },
        new ComplexType { StringProperty = "String2", IntegerProperty = 77 },
        new ComplexType { StringProperty = "String3", IntegerProperty = 777 }
    };

    connection.SetupDapper(c => c.Query<ComplexType>(It.IsAny<string>(), null, null, true, null, null))
              .Returns(expected);

    var actual = connection.Object.Query<ComplexType>("", null, null, true, null, null).ToList();

    Assert.That(actual.Count, Is.EqualTo(expected.Length));

    foreach (var complexObject in expected)
    {
        var match = actual.Where(co => co.StringProperty == complexObject.StringProperty && co.IntegerProperty == complexObject.IntegerProperty);

        Assert.That(match.Count, Is.EqualTo(1));
    }
}

Mocking a call to ExecuteScalar:

[Test]
public void ExecuteScalar()
{
    var connection = new Mock<IDbConnection>();

    const int expected = 77;

    connection.SetupDapper(c => c.ExecuteScalar<int>(It.IsAny<string>(), null, null, null, null))
              .Returns(expected);

    var actual = connection.Object.ExecuteScalar<int>("", null, null, null);

    Assert.That(actual, Is.EqualTo(expected));
}

Mocking a call to QueryAsync

[Test]
public async Task QueryAsyncGeneric()
{
    var connection = new Mock<DbConnection>();

    var expected = new[] { 7, 77, 777 };

    connection.SetupDapperAsync(c => c.QueryAsync<int>(It.IsAny<string>(), null, null, null, null))
              .ReturnsAsync(expected);

    var actual = (await connection.Object.QueryAsync<int>("", null, null, null, null)).ToList();

    Assert.That(actual.Count, Is.EqualTo(expected.Length));
    Assert.That(actual, Is.EquivalentTo(expected));
}

Mocking a call to ExecuteScalarAsync:

[Test]
public void ExecuteScalarAsync()
{
    var connection = new Mock<DbConnection>();
    
    const string expected = "Hello";

    connection.SetupDapperAsync(c => c.ExecuteScalarAsync<object>(It.IsAny<string>(), null, null, null, null))
              .ReturnsAsync(expected);

    var actual = connection.Object
                           .ExecuteScalarAsync<object>("")
                           .GetAwaiter()
                           .GetResult();

    Assert.That(actual, Is.EqualTo(expected));
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].