Skip to content

Commit

Permalink
Merge pull request #55 from abe545/fix-double-ats
Browse files Browse the repository at this point in the history
PR for Release 2.2.4
  • Loading branch information
abe545 committed Dec 5, 2015
2 parents 064590f + 4fe53c0 commit 8659639
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static TSP WithParameter<TSP, TValue>(this TSP sp, string name, TValue va
Contract.Requires(!string.IsNullOrWhiteSpace(name));
Contract.Ensures(Contract.Result<TSP>() != null);

return (TSP)sp.CloneWith(new InputParameter(name, value));
return (TSP)sp.CloneWith(new InputParameter(name, value, typeof(TValue).InferDbType()));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void TransferOutputValue(object value)

public override string ToString()
{
return string.Format("[InOut] @{0} = '{1}'", ParameterName, Value ?? "{null}");
return string.Format("[InOut] @{0} = '{1}'", ParameterName.StartsWith("@") ? ParameterName.Substring(1) : ParameterName, Value ?? "{null}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public IDbDataParameter CreateDbDataParameter(IDbCommand command)

public override string ToString()
{
return string.Format("@{0} = '{1}'", ParameterName, Value ?? "{null}");
return string.Format("@{0} = '{1}'", ParameterName.StartsWith("@") ? ParameterName.Substring(1) : ParameterName, Value ?? "{null}");
}

private DbType GetDbType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void TransferOutputValue(object value)

public override string ToString()
{
return string.Format("[Out] @{0}", ParameterName);
return string.Format("[Out] @{0}", ParameterName.StartsWith("@") ? ParameterName.Substring(1) : ParameterName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public IDbDataParameter CreateDbDataParameter(IDbCommand command)

public override string ToString()
{
return string.Format("@{0} = IEnumerable<{1}> ({2} items)", ParameterName, valueType, GetValueCount());
return string.Format("@{0} = IEnumerable<{1}> ({2} items)", ParameterName.StartsWith("@") ? ParameterName.Substring(1) : ParameterName, valueType, GetValueCount());
}

private int GetValueCount()
Expand Down
12 changes: 6 additions & 6 deletions CodeOnlyStoredProcedures.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A library for easily calling Stored Procedures in .NET. Works great with Entity Framework Code First models.
Code Only Stored Procedures will not create any Stored Procedures on your database. Instead, its aim is to make it easy to call your existing stored procedures by writing simple code.</description>
<releaseNotes>2.2.3
<releaseNotes>2.2.4
Fixed bug where calling ToString on a stored procedure could print parameters with a double @.
Fixed bug where the fluent syntax would not infer the type of its parameters from the compile time generic parameter type.

2.2.3
Fixed bug where dynamic stored procedures wouldn't close their connections.

2.2.2
Expand Down Expand Up @@ -53,11 +57,7 @@ Added ability to specify an implementation of an interface, so a StoredProcedure
Added better exception when a model is missing a public parameterless constructor.

1.2.0
Added a much cleaner syntax for calling stored procedures, by using dynamic objects.

1.1.0
Improved exceptions so that it is easier to determine why the data returned doesn't map to your model correctly.
Now ignores read-only properties, so they don't have to be attributed with [NotMapped]</releaseNotes>
Added a much cleaner syntax for calling stored procedures, by using dynamic objects.</releaseNotes>
<tags>StoredProcedure EntityFramework EF</tags>
<dependencies>
<group targetFramework=".NETFramework4.0">
Expand Down
12 changes: 6 additions & 6 deletions CodeOnlyTests-NET40/CodeOnlyTests-NET40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.3.5.0\lib\net40\FluentAssertions.dll</HintPath>
<Reference Include="FluentAssertions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.1.0\lib\net40\FluentAssertions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentAssertions.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.3.5.0\lib\net40\FluentAssertions.Core.dll</HintPath>
<Reference Include="FluentAssertions.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.1.0\lib\net40\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
Expand All @@ -64,8 +64,8 @@
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1507.118, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
4 changes: 2 additions & 2 deletions CodeOnlyTests-NET40/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net40" />
<package id="FluentAssertions" version="3.5.0" targetFramework="net40" />
<package id="FluentAssertions" version="4.1.0" targetFramework="net40" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" />
<package id="Moq" version="4.2.1507.0118" targetFramework="net40" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net40" />
</packages>
12 changes: 6 additions & 6 deletions CodeOnlyTests/CodeOnlyTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.3.5.0\lib\net45\FluentAssertions.dll</HintPath>
<Reference Include="FluentAssertions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.1.0\lib\net45\FluentAssertions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentAssertions.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.3.5.0\lib\net45\FluentAssertions.Core.dll</HintPath>
<Reference Include="FluentAssertions.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.1.0\lib\net45\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Moq, Version=4.2.1507.118, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
15 changes: 15 additions & 0 deletions CodeOnlyTests/StoredProcedureExtensionsTests.WithParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,20 @@ public void TestWithParameterClonesStoredProcedureWithResultType()
var param = toTest.Parameters.Should().ContainSingle(p => p.ParameterName == "Foo", "because we added one Parameter").Which;
param.Should().BeOfType<InputParameter>().Which.Value.Should().Be("Bar", "because it was passed to WithInputParameter");
}

[TestMethod]
public void TestWithParameter_InfersTheDbType()
{
var orig = new StoredProcedure("Test");

var toTest = orig.WithParameter("Foo", "Bar");

toTest.Should().NotBeSameAs(orig, "because StoredProcedures should be immutable");
orig.Parameters.Should().BeEmpty("because StoredProcedures should be immutable");

var param = toTest.Parameters.Should().ContainSingle(p => p.ParameterName == "Foo", "because we added one Parameter").Which;
param.Should().BeOfType<InputParameter>().Which.Value.Should().Be("Bar", "because it was passed to WithInputParameter");
param.Should().BeOfType<InputParameter>().Which.DbType.Should().Be(DbType.String, "because the DbType should be inferred if possible");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,11 @@ public void NullValueToStringReturnsCorrectString()
{
new InputOutputParameter("Foo", o => { }, null).ToString().Should().Be("[InOut] @Foo = '{null}'");
}

[TestMethod]
public void ToStringDoesNotDisplayExtraAts()
{
new InputOutputParameter("@Foo", o => { }, "Bar").ToString().Should().Be("[InOut] @Foo = 'Bar'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,11 @@ public void NullValueToStringReturnsCorrectString()
{
new InputParameter("Foo", null).ToString().Should().Be("@Foo = '{null}'");
}

[TestMethod]
public void ToStringDoesNotDisplayExtraAts()
{
new InputParameter("@Foo", "Bar").ToString().Should().Be("@Foo = 'Bar'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ public void ToStringRepresentsTheParameter()
{
new OutputParameter("Foo", o => { }).ToString().Should().Be("[Out] @Foo");
}

[TestMethod]
public void ToStringDoesNotDisplayExtraAts()
{
new OutputParameter("@Foo", o => { }).ToString().Should().Be("[Out] @Foo");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public void ToStringRepresentsTheParameter()
.Should().Be(string.Format("@Foo = IEnumerable<{0}> (1 items)", typeof(TVP)));
}

[TestMethod]
public void ToStringDoesNotDisplayExtraAts()
{
new TableValuedParameter("@Foo", new[] { new TVP(42) }, typeof(TVP), "CustomInt", "Schema").ToString()
.Should().Be(string.Format("@Foo = IEnumerable<{0}> (1 items)", typeof(TVP)));
}

private class TVP
{
public int Int { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions CodeOnlyTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentAssertions" version="3.5.0" targetFramework="net45" />
<package id="Moq" version="4.2.1507.0118" targetFramework="net45" />
<package id="FluentAssertions" version="4.1.0" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
</packages>
31 changes: 31 additions & 0 deletions SmokeTests/DynamicSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,37 @@ Tuple<bool, string> SingleColumnSingleRowTimeSpanSync(IDbConnection db)

return Tuple.Create(true, "");
}

// THIS DOESN'T WORK... Not sure if it can ever be enabled. Maybe if null parameters aren't actually passed to the sproc?
//[SmokeTest("Dynamic Syntax Single Column Single Row with nullable parameter")]
Tuple<bool, string> SingleColumnSingleRowTimeSpanSyncWithNullableParameter(IDbConnection db)
{
var d1 = DateTime.Now.AddHours(-1);
DateTime? d2 = null;
TimeSpan result = db.Execute(Program.timeout).usp_TimeDifference(date1: d1, date2: d2);

if ((result - System.TimeSpan.FromHours(1)).Duration() > TimeSpan.FromSeconds(1))
return Tuple.Create(false, string.Format("expected value at least {0}, but returned {1}", TimeSpan.FromHours(1), result));

return Tuple.Create(true, "");
}

[SmokeTest("Dynamic Syntax Single Column Single Row with nullable parameter via anonymous type")]
Tuple<bool, string> SingleColumnSingleRowTimeSpanSyncWithNullableParameterViaAnonymousType(IDbConnection db)
{
var d1 = DateTime.Now.AddHours(-1);
DateTime? d2 = null;
TimeSpan result = db.Execute(Program.timeout).usp_TimeDifference(new
{
date1 = d1,
date2 = d2
});

if ((result - System.TimeSpan.FromHours(1)).Duration() > TimeSpan.FromSeconds(1))
return Tuple.Create(false, string.Format("expected value at least {0}, but returned {1}", TimeSpan.FromHours(1), result));

return Tuple.Create(true, "");
}

[SmokeTest("Dynamic Syntax Single Column Single Row (Await)")]
async Task<Tuple<bool, string>> SingleColumnSingleRowTimeSpanAsync(IDbConnection db)
Expand Down
61 changes: 61 additions & 0 deletions SmokeTests/FluentSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,67 @@ Task<Tuple<bool, string>> SingleColumnSingleRowUntypedTimeSpanTask(IDbConnection
return Tuple.Create(true, "");
});
}

[SmokeTest("Fluent Syntax Single Column Single Row with nullable parameter (Task)")]
Task<Tuple<bool, string>> SingleColumnSingleRowTimeSpanTaskWithNullableParameter(IDbConnection db)
{
var d1 = DateTime.Now.AddHours(-1);
DateTime? d2 = null;

var results = StoredProcedure.Create("usp_TimeDifference")
.WithParameter("date1", d1)
.WithParameter("date2", d2)
.WithResults<TimeSpan>()
.ExecuteAsync(db, Program.timeout);


return results.ContinueWith(r =>
{
var res = r.Result.Single();
if ((res - System.TimeSpan.FromHours(1)).Duration() > TimeSpan.FromSeconds(1))
return Tuple.Create(false, string.Format("expected {0}, but returned {1}", TimeSpan.FromHours(1), res));

return Tuple.Create(true, "");
});
}

[SmokeTest("Fluent Syntax Single Column Single Row with nullable parameter (Await)")]
async Task<Tuple<bool, string>> SingleColumnSingleRowTimeSpanASyncWithNullableParameter(IDbConnection db)
{
var d1 = DateTime.Now.AddHours(-1);
DateTime? d2 = null;

var results = await StoredProcedure.Create("usp_TimeDifference")
.WithParameter("date1", d1)
.WithParameter("date2", d2)
.WithResults<TimeSpan>()
.ExecuteAsync(db, Program.timeout);

var res = results.Single();
if ((res - System.TimeSpan.FromHours(1)).Duration() > TimeSpan.FromSeconds(1))
return Tuple.Create(false, string.Format("expected {0}, but returned {1}", TimeSpan.FromHours(1), res));

return Tuple.Create(true, "");
}

[SmokeTest("Fluent Syntax Single Column Single Row with nullable parameter (Await)")]
Tuple<bool, string> SingleColumnSingleRowTimeSpanSyncWithNullableParameter(IDbConnection db)
{
var d1 = DateTime.Now.AddHours(-1);
DateTime? d2 = null;

var results = StoredProcedure.Create("usp_TimeDifference")
.WithParameter("date1", d1)
.WithParameter("date2", d2)
.WithResults<TimeSpan>()
.Execute(db, Program.timeout);

var res = results.Single();
if ((res - System.TimeSpan.FromHours(1)).Duration() > TimeSpan.FromSeconds(1))
return Tuple.Create(false, string.Format("expected {0}, but returned {1}", TimeSpan.FromHours(1), res));

return Tuple.Create(true, "");
}

private class TimespanResult
{
Expand Down
Binary file modified SmokeTests/Smoke.mdf
Binary file not shown.
Binary file modified SmokeTests/Smoke_log.ldf
Binary file not shown.
9 changes: 6 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
version: 2.2.3.{build}
version: 2.2.4.{build}
skip_tags: false

# Operating system (build VM template)
os: Visual Studio 2013

branches:
# blacklist gh-pages, since the documentation branch shouldn't be built
except:
- gh-pages

environment:
releaseVersion: 2.2.3
packageVersion: 2.2.3
releaseVersion: 2.2.4
packageVersion: 2.2.4-pre

assembly_info:
patch: true
Expand Down

0 comments on commit 8659639

Please sign in to comment.