From 41e8dc129c0c0191f57b67b46d38e60fb78d4016 Mon Sep 17 00:00:00 2001 From: Rasmus Svendsen Date: Mon, 13 Feb 2017 18:53:21 +0100 Subject: [PATCH 1/4] Fix Dapper.Contrib alter caching keys issue #703 --- Dapper.Contrib/SqlMapperExtensions.cs | 6 ++--- Dapper.Tests.Contrib/TestSuite.Async.cs | 29 +++++++++++++++++++++++++ Dapper.Tests.Contrib/TestSuites.cs | 2 ++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Dapper.Contrib/SqlMapperExtensions.cs b/Dapper.Contrib/SqlMapperExtensions.cs index 0ca0087b4..0a6389650 100644 --- a/Dapper.Contrib/SqlMapperExtensions.cs +++ b/Dapper.Contrib/SqlMapperExtensions.cs @@ -63,7 +63,7 @@ private static List ComputedPropertiesCache(Type type) var computedProperties = TypePropertiesCache(type).Where(p => p.GetCustomAttributes(true).Any(a => a is ComputedAttribute)).ToList(); ComputedProperties[type.TypeHandle] = computedProperties; - return computedProperties; + return computedProperties.ToList(); } private static List ExplicitKeyPropertiesCache(Type type) @@ -77,7 +77,7 @@ private static List ExplicitKeyPropertiesCache(Type type) var explicitKeyProperties = TypePropertiesCache(type).Where(p => p.GetCustomAttributes(true).Any(a => a is ExplicitKeyAttribute)).ToList(); ExplicitKeyProperties[type.TypeHandle] = explicitKeyProperties; - return explicitKeyProperties; + return explicitKeyProperties.ToList(); } private static List KeyPropertiesCache(Type type) @@ -105,7 +105,7 @@ private static List KeyPropertiesCache(Type type) } KeyProperties[type.TypeHandle] = keyProperties; - return keyProperties; + return keyProperties.ToList(); } private static List TypePropertiesCache(Type type) diff --git a/Dapper.Tests.Contrib/TestSuite.Async.cs b/Dapper.Tests.Contrib/TestSuite.Async.cs index 9be5c726f..1e1b57971 100644 --- a/Dapper.Tests.Contrib/TestSuite.Async.cs +++ b/Dapper.Tests.Contrib/TestSuite.Async.cs @@ -13,8 +13,37 @@ namespace Dapper.Tests.Contrib { + [Table("ObjectW")] + public class ObjectW + { + [ExplicitKey] + public Guid ObjectWId { get; set; } + public string Name { get; set; } + } + public abstract partial class TestSuite { + [Fact] + public async Task Issue703() + { + using (var connection = GetOpenConnection()) + { + //update first (will fail) then insert + //added for bug #418/#703 + var objectW = new ObjectW + { + ObjectWId = Guid.NewGuid(), + Name = "Someone" + }; + var updates = await connection.UpdateAsync(objectW); + updates.IsFalse(); + + await connection.InsertAsync(objectW); + var list = await connection.GetAllAsync(); + list.Count().IsEqualTo(1); + } + } + /// /// Tests for issue #351 /// diff --git a/Dapper.Tests.Contrib/TestSuites.cs b/Dapper.Tests.Contrib/TestSuites.cs index 320d20eb0..600970d3b 100644 --- a/Dapper.Tests.Contrib/TestSuites.cs +++ b/Dapper.Tests.Contrib/TestSuites.cs @@ -56,6 +56,8 @@ static SqlServerTestSuite() connection.Execute(@"CREATE TABLE ObjectY (ObjectYId int not null, Name nvarchar(100) not null);"); dropTable("ObjectZ"); connection.Execute(@"CREATE TABLE ObjectZ (Id int not null, Name nvarchar(100) not null);"); + dropTable("ObjectW"); + connection.Execute(@"CREATE TABLE ObjectW (ObjectWId uniqueidentifier not null, Name nvarchar(100) not null);"); } } } From 4be8e3b28d03537e796581715389687f0b19d22a Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Sun, 1 Jul 2018 07:10:37 -0400 Subject: [PATCH 2/4] Fix bad merge --- Dapper.Tests.Contrib/TestSuite.Async.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Dapper.Tests.Contrib/TestSuite.Async.cs b/Dapper.Tests.Contrib/TestSuite.Async.cs index a07baa3af..64a464c4c 100644 --- a/Dapper.Tests.Contrib/TestSuite.Async.cs +++ b/Dapper.Tests.Contrib/TestSuite.Async.cs @@ -37,6 +37,7 @@ public async Task Issue703() await connection.InsertAsync(objectW); var list = await connection.GetAllAsync(); list.Count().IsEqualTo(1); + } [Fact] public async Task TypeWithGenericParameterCanBeInsertedAsync() From a66e34d9c270c0d17fa2e0a8e813e8a4745f952a Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Sun, 1 Jul 2018 07:16:51 -0400 Subject: [PATCH 3/4] Damn you, git --- Dapper.Tests.Contrib/TestSuite.Async.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Dapper.Tests.Contrib/TestSuite.Async.cs b/Dapper.Tests.Contrib/TestSuite.Async.cs index 64a464c4c..2153772a2 100644 --- a/Dapper.Tests.Contrib/TestSuite.Async.cs +++ b/Dapper.Tests.Contrib/TestSuite.Async.cs @@ -37,6 +37,7 @@ public async Task Issue703() await connection.InsertAsync(objectW); var list = await connection.GetAllAsync(); list.Count().IsEqualTo(1); + } } [Fact] From 62e75f0ddb6e12c321946509a10720be874a5f39 Mon Sep 17 00:00:00 2001 From: Nick Craver Date: Sun, 1 Jul 2018 07:40:23 -0400 Subject: [PATCH 4/4] Fix up tests PR pre-dates xunit move --- Dapper.Tests.Contrib/TestSuite.Async.cs | 6 +++--- Dapper.Tests.Contrib/TestSuites.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dapper.Tests.Contrib/TestSuite.Async.cs b/Dapper.Tests.Contrib/TestSuite.Async.cs index 2153772a2..aa368d45d 100644 --- a/Dapper.Tests.Contrib/TestSuite.Async.cs +++ b/Dapper.Tests.Contrib/TestSuite.Async.cs @@ -32,11 +32,11 @@ public async Task Issue703() Name = "Someone" }; var updates = await connection.UpdateAsync(objectW); - updates.IsFalse(); - + Assert.False(updates); + await connection.InsertAsync(objectW); var list = await connection.GetAllAsync(); - list.Count().IsEqualTo(1); + Assert.Single(list); } } diff --git a/Dapper.Tests.Contrib/TestSuites.cs b/Dapper.Tests.Contrib/TestSuites.cs index 9dbd674f7..afaa161b1 100644 --- a/Dapper.Tests.Contrib/TestSuites.cs +++ b/Dapper.Tests.Contrib/TestSuites.cs @@ -50,7 +50,7 @@ static SqlServerTestSuite() dropTable("Results"); connection.Execute("CREATE TABLE Results (Id int IDENTITY(1,1) not null, Name nvarchar(100) not null, [Order] int not null);"); dropTable("ObjectW"); - connection.Execute(@"CREATE TABLE ObjectW (ObjectWId uniqueidentifier not null, Name nvarchar(100) not null);"); + connection.Execute("CREATE TABLE ObjectW (ObjectWId uniqueidentifier not null, Name nvarchar(100) not null);"); dropTable("ObjectX"); connection.Execute("CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);"); dropTable("ObjectY"); @@ -103,7 +103,7 @@ static MySqlServerTestSuite() dropTable("Results"); connection.Execute("CREATE TABLE Results (Id int not null AUTO_INCREMENT PRIMARY KEY, Name nvarchar(100) not null, `Order` int not null);"); dropTable("ObjectW"); - connection.Execute(@"CREATE TABLE ObjectW (ObjectWId CHAR(38) not null, Name nvarchar(100) not null);"); + connection.Execute("CREATE TABLE ObjectW (ObjectWId CHAR(38) not null, Name nvarchar(100) not null);"); dropTable("ObjectX"); connection.Execute("CREATE TABLE ObjectX (ObjectXId nvarchar(100) not null, Name nvarchar(100) not null);"); dropTable("ObjectY");