diff --git a/src/EFCore.Jet/Storage/Internal/JetDateTimeTypeMapping.cs b/src/EFCore.Jet/Storage/Internal/JetDateTimeTypeMapping.cs index bdfed57..71fb8e1 100644 --- a/src/EFCore.Jet/Storage/Internal/JetDateTimeTypeMapping.cs +++ b/src/EFCore.Jet/Storage/Internal/JetDateTimeTypeMapping.cs @@ -2,7 +2,6 @@ using System.Data; using System.Data.Common; -using System.Data.Jet; using System.Data.OleDb; using JetBrains.Annotations; using Microsoft.EntityFrameworkCore.Storage; diff --git a/src/System.Data.Jet/JetCommand.cs b/src/System.Data.Jet/JetCommand.cs index bed8014..afaef82 100644 --- a/src/System.Data.Jet/JetCommand.cs +++ b/src/System.Data.Jet/JetCommand.cs @@ -306,6 +306,7 @@ namespace System.Data.Jet int indexOfSkip; string newCommandText; ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText); + ApplyParameters(newCommandText, _WrappedCommand.Parameters, out newCommandText); if (skipCount != 0) { @@ -331,8 +332,6 @@ namespace System.Data.Jet } - - private int InternalExecuteNonQuery(string commandText) { @@ -341,6 +340,7 @@ namespace System.Data.Jet int indexOfSkip; string newCommandText; ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText); + ApplyParameters(newCommandText, _WrappedCommand.Parameters, out newCommandText); DbCommand command; command = (DbCommand)((ICloneable)this._WrappedCommand).Clone(); @@ -374,6 +374,7 @@ namespace System.Data.Jet command.CommandText = "Select @@identity"; object identity = command.ExecuteScalar(); int iIdentity = Convert.ToInt32(identity); + Console.WriteLine("@@identity = {0}", iIdentity); return Regex.Replace(commandText, "@@identity", iIdentity.ToString(System.Globalization.CultureInfo.InvariantCulture), RegexOptions.IgnoreCase); } return commandText; @@ -388,6 +389,7 @@ namespace System.Data.Jet command.CommandText = "Select @@guid"; object identity = command.ExecuteScalar(); int iIdentity = Convert.ToInt32(identity); + Console.WriteLine("@@guid = {0}", iIdentity); return Regex.Replace(commandText, "@@guid", iIdentity.ToString(System.Globalization.CultureInfo.InvariantCulture), RegexOptions.IgnoreCase); } return commandText; @@ -446,6 +448,16 @@ namespace System.Data.Jet } + private void ApplyParameters(string commandText, DbParameterCollection parameters, out string newCommandText) + { + newCommandText = commandText; + foreach (DbParameter parameter in parameters) + { + newCommandText = newCommandText.Replace(parameter.ParameterName, JetParameterHelper.GetParameterValue(parameter)); + } + } + + /// /// Creates a prepared (or compiled) version of the command on the data source /// diff --git a/src/System.Data.Jet/JetDataReader.cs b/src/System.Data.Jet/JetDataReader.cs index e171de0..3c39bf4 100644 --- a/src/System.Data.Jet/JetDataReader.cs +++ b/src/System.Data.Jet/JetDataReader.cs @@ -6,8 +6,6 @@ namespace System.Data.Jet { class JetDataReader : DbDataReader { - - public JetDataReader(DbDataReader dataReader) { _wrappedDataReader = dataReader; diff --git a/src/System.Data.Jet/JetParameterHelper.cs b/src/System.Data.Jet/JetParameterHelper.cs new file mode 100644 index 0000000..74e528d --- /dev/null +++ b/src/System.Data.Jet/JetParameterHelper.cs @@ -0,0 +1,115 @@ +using System; +using System.Data.Common; + +namespace System.Data.Jet +{ + static internal class JetParameterHelper + { + public static string GetParameterValueToDisplay(DbParameter parameter) + { + if (parameter.Value == DBNull.Value || parameter.Value == null) + return "null"; + else if (IsString(parameter)) + return String.Format("'{0}'", parameter.Value); + else if (IsDateTime(parameter)) + return String.Format("#{0:yyyy-MM-ddTHH:mm:ssZ}#", parameter.Value); + else if (IsTimeSpan(parameter)) + return String.Format("#{0:c}#", parameter.Value); + else if (IsGuid(parameter)) + return String.Format("{{{0}}}", parameter.Value); + else if (parameter.Value is Enum) + return String.Format("{0}({1})", Convert.ToInt32(parameter.Value), parameter.Value); + else + return String.Format("{0}", parameter.Value); + + } + + private static bool IsGuid(DbParameter parameter) + { + switch (parameter.DbType) + { + case DbType.Guid: + return true; + default: + return false; + } + } + + public static string GetParameterValue(DbParameter parameter) + { + if (parameter.Value == DBNull.Value || parameter.Value == null) + return "null"; + else if (IsString(parameter)) + return String.Format("'{0}'", ((string)parameter.Value).Replace("'", "''")); + else if (IsDateTime(parameter)) + return String.Format("#{0:MM/dd/yyyy HH:mm:ss}#", parameter.Value); + else if (IsTimeSpan(parameter)) + return String.Format("#{0:MM/dd/yyyy HH:mm:ss}#", JetConfiguration.TimeSpanOffset + (TimeSpan)parameter.Value); + else if (IsGuid(parameter)) + return String.Format("'{0}'", parameter.Value); + else if (IsNumeric(parameter)) + return String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", Convert.ToInt64(parameter.Value)); + else + return String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", parameter.Value); + } + + private static bool IsNumeric(DbParameter parameter) + { + switch (parameter.DbType) + { + case DbType.Byte: + case DbType.Int16: + case DbType.Int32: + case DbType.Int64: + case DbType.Object: + case DbType.SByte: + case DbType.UInt16: + case DbType.UInt32: + case DbType.UInt64: + return true; + default: + return false; + } + } + + + public static bool IsTimeSpan(DbParameter parameter) + { + switch (parameter.DbType) + { + case DbType.DateTimeOffset: + return true; + default: + return false; + } + } + + public static bool IsDateTime(DbParameter parameter) + { + switch (parameter.DbType) + { + case DbType.Date: + case DbType.DateTime: + case DbType.Time: + case DbType.DateTime2: + return true; + default: + return false; + } + } + + public static bool IsString(DbParameter parameter) + { + switch (parameter.DbType) + { + case DbType.AnsiString: + case DbType.String: + case DbType.AnsiStringFixedLength: + case DbType.StringFixedLength: + return true; + default: + return false; + } + } + } +} \ No newline at end of file diff --git a/src/System.Data.Jet/JetTransaction.cs b/src/System.Data.Jet/JetTransaction.cs index 9652eea..48a77a8 100644 --- a/src/System.Data.Jet/JetTransaction.cs +++ b/src/System.Data.Jet/JetTransaction.cs @@ -11,7 +11,7 @@ namespace System.Data.Jet public JetTransaction(DbTransaction wrappedTransaction, DbConnection connection) { - LogHelper.ShowCommandHeader("vvv BeginTransaction"); + LogHelper.ShowCommandHeader("\r\nvvv BeginTransaction (" + wrappedTransaction.IsolationLevel + ")"); WrappedTransaction = wrappedTransaction; _connection = connection; } @@ -34,7 +34,7 @@ namespace System.Data.Jet public override void Rollback() { - LogHelper.ShowCommandHeader("^^^ Commit"); + LogHelper.ShowCommandHeader("^^^ Rollback"); WrappedTransaction.Rollback(); } diff --git a/src/System.Data.Jet/LogHelper.cs b/src/System.Data.Jet/LogHelper.cs index 065984b..f5d3e73 100644 --- a/src/System.Data.Jet/LogHelper.cs +++ b/src/System.Data.Jet/LogHelper.cs @@ -22,59 +22,6 @@ static internal class LogHelper Console.WriteLine("{0}", command.CommandText); foreach (DbParameter parameter in command.Parameters) - Console.WriteLine("{0} = {1}", parameter.ParameterName, GetParameterValue(parameter)); - } - - private static string GetParameterValue(DbParameter parameter) - { - if (parameter.Value == DBNull.Value || parameter.Value == null) - return "null"; - else if (IsString(parameter)) - return String.Format("'{0}'", parameter.Value); - else if (IsDateTime(parameter)) - return String.Format("#{0:yyyy-MM-ddTHH:mm:ssZ}#", parameter.Value); - else if (IsTimeSpan(parameter)) - return String.Format("#{0:c}#", parameter.Value); - else - return String.Format("{0}", parameter.Value); - } - - private static bool IsTimeSpan(DbParameter parameter) - { - switch (parameter.DbType) - { - case DbType.DateTimeOffset: - return true; - default: - return false; - } - } - - private static bool IsDateTime(DbParameter parameter) - { - switch (parameter.DbType) - { - case DbType.Date: - case DbType.DateTime: - case DbType.Time: - case DbType.DateTime2: - return true; - default: - return false; - } - } - - private static bool IsString(DbParameter parameter) - { - switch (parameter.DbType) - { - case DbType.AnsiString: - case DbType.String: - case DbType.AnsiStringFixedLength: - case DbType.StringFixedLength: - return true; - default: - return false; - } + Console.WriteLine("{0}({1}) = {2}", parameter.ParameterName, parameter.DbType, JetParameterHelper.GetParameterValueToDisplay(parameter)); } } \ No newline at end of file diff --git a/src/System.Data.Jet/System.Data.Jet.csproj b/src/System.Data.Jet/System.Data.Jet.csproj index 291047b..865b912 100644 --- a/src/System.Data.Jet/System.Data.Jet.csproj +++ b/src/System.Data.Jet/System.Data.Jet.csproj @@ -71,6 +71,7 @@ Component + diff --git a/test/EFCore.Jet.Integration.Test/SetUpCodeFirst.cs b/test/EFCore.Jet.Integration.Test/AssemblyInitialization.cs similarity index 56% rename from test/EFCore.Jet.Integration.Test/SetUpCodeFirst.cs rename to test/EFCore.Jet.Integration.Test/AssemblyInitialization.cs index 1405d16..12c2ccb 100644 --- a/test/EFCore.Jet.Integration.Test/SetUpCodeFirst.cs +++ b/test/EFCore.Jet.Integration.Test/AssemblyInitialization.cs @@ -1,13 +1,12 @@ using System; using System.Data.Common; using System.Data.Jet; -using EFCore.Jet.Integration.Test.Model01; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace EFCore.Jet.Integration.Test { [TestClass] - public class SetUpCodeFirst + public class AssemblyInitialization { public static DbConnection Connection; @@ -21,19 +20,6 @@ namespace EFCore.Jet.Integration.Test Connection = Helpers.GetJetConnection(); - Context context = new Context(TestBase.GetContextOptions(Connection)); - TestBase.CreateTables(context); - - // Need to do more than just a connection - // We could also call context.Database.Initialize(false); - Student student = new Student() { StudentName = "db creation" }; - context.Students.Add(student); - context.SaveChanges(); - - - - context.Dispose(); - Helpers.DeleteSqlCeDatabase(); Helpers.CreateSqlCeDatabase(); } @@ -42,7 +28,8 @@ namespace EFCore.Jet.Integration.Test [AssemblyCleanup] static public void AssemblyCleanup() { - Connection.Dispose(); + if (Connection != null) + Connection.Dispose(); Helpers.DeleteSqlCeDatabase(); } diff --git a/test/EFCore.Jet.Integration.Test/BooleanMaterializationTest2.cs b/test/EFCore.Jet.Integration.Test/BooleanMaterializationTest2.cs index 796c869..2a348da 100644 --- a/test/EFCore.Jet.Integration.Test/BooleanMaterializationTest2.cs +++ b/test/EFCore.Jet.Integration.Test/BooleanMaterializationTest2.cs @@ -10,7 +10,7 @@ namespace EFCore.Jet.Integration.Test public class BooleanMaterializationTest2 : TestBase { [TestMethod] - public void Run() + public void BooleanMaterializationTest2Run() { // ReSharper disable once RedundantCast Console.WriteLine(Context.TableWithSeveralFieldsTypes.Select(c => new {MyNewProperty = (bool) true}).ToList().Count); @@ -18,7 +18,7 @@ namespace EFCore.Jet.Integration.Test protected override DbConnection GetConnection() { - return SetUpCodeFirst.Connection; + return AssemblyInitialization.Connection; } public override void CleanUp() diff --git a/test/EFCore.Jet.Integration.Test/CanonicalFunctionsTest2.cs b/test/EFCore.Jet.Integration.Test/CanonicalFunctionsTest2.cs index e7e11ee..d3e5124 100644 --- a/test/EFCore.Jet.Integration.Test/CanonicalFunctionsTest2.cs +++ b/test/EFCore.Jet.Integration.Test/CanonicalFunctionsTest2.cs @@ -34,8 +34,14 @@ namespace EFCore.Jet.Integration.Test Context.Students.Add(student); Context.SaveChanges(); - Assert.IsNotNull(Context.Students.Where(s => Context.Standards.Contains(s.Standard)).First()); - Assert.IsNotNull(Context.Students.Where(s => (new[] {1,2,3,4}).Contains(s.StudentId)).First()); + Assert.IsNotNull(Context.Students.Where(s => (new[] { 1, 2, 3, 4 }).Contains(s.StudentId)).First()); + + // SELECT WHERE IN SELECT NOT IMPLEMENTED + //Assert.IsNotNull(Context.Students.Where(s => Context.Standards.Contains(s.Standard)).First()); + + Assert.IsNotNull(Context.Students.First(stu => Context.Standards.Any(std => std.StandardId == stu.StudentId))); + + Context.Dispose(); } diff --git a/test/EFCore.Jet.Integration.Test/DataTypesTest.cs b/test/EFCore.Jet.Integration.Test/DataTypesTest.cs index 7de9ac6..8cdc185 100644 --- a/test/EFCore.Jet.Integration.Test/DataTypesTest.cs +++ b/test/EFCore.Jet.Integration.Test/DataTypesTest.cs @@ -49,7 +49,7 @@ namespace EFCore.Jet.Integration.Test protected override DbConnection GetConnection() { - return SetUpCodeFirst.Connection; + return AssemblyInitialization.Connection; } } } diff --git a/test/EFCore.Jet.Integration.Test/DdlTest.cs b/test/EFCore.Jet.Integration.Test/DdlTest.cs deleted file mode 100644 index d6489e1..0000000 --- a/test/EFCore.Jet.Integration.Test/DdlTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Data.Jet; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace EFCore.Jet.Integration.Test -{ - [TestClass] - public class DdlTest - { - [TestMethod] - public void CheckIfTablesExists() - { - bool exists = ((JetConnection)SetUpCodeFirst.Connection).TableExists("Students"); - Assert.IsTrue(exists); - } - } -} diff --git a/test/EFCore.Jet.Integration.Test/DmlTest.cs b/test/EFCore.Jet.Integration.Test/DmlBaseTest.cs similarity index 87% rename from test/EFCore.Jet.Integration.Test/DmlTest.cs rename to test/EFCore.Jet.Integration.Test/DmlBaseTest.cs index 6ee4086..b82fd63 100644 --- a/test/EFCore.Jet.Integration.Test/DmlTest.cs +++ b/test/EFCore.Jet.Integration.Test/DmlBaseTest.cs @@ -6,8 +6,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace EFCore.Jet.Integration.Test { - [TestClass] - public class DmlTest : TestBase + public abstract class DmlBaseTest : TestBase { [TestMethod] public void Insert() @@ -38,12 +37,25 @@ namespace EFCore.Jet.Integration.Test base.DisposeContext(); base.CreateContext(); + // Retrieve the student student = Context.Students.Where(s => s.StudentId == studentId).First(); + + /* + base.Connection.Open(); + string sql = "UPDATE [Students] SET [StudentName] = 'Student updated' WHERE [StudentId] = " + student.StudentId; + var command = base.Connection.CreateCommand(); + command.CommandText = sql; + command.ExecuteReader(); + */ + + // Update the student student.StudentName = "Student updated"; Context.SaveChanges(); + + base.DisposeContext(); // Retrieve the student and check that is the right student @@ -88,7 +100,6 @@ namespace EFCore.Jet.Integration.Test } - protected override DbConnection GetConnection() - => Helpers.GetJetConnection(); + } } diff --git a/test/EFCore.Jet.Integration.Test/DmlJetTest.cs b/test/EFCore.Jet.Integration.Test/DmlJetTest.cs new file mode 100644 index 0000000..4f6d165 --- /dev/null +++ b/test/EFCore.Jet.Integration.Test/DmlJetTest.cs @@ -0,0 +1,13 @@ +using System; +using System.Data.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EFCore.Jet.Integration.Test +{ + [TestClass] + public class DmlJetTest : DmlBaseTest + { + protected override DbConnection GetConnection() + => Helpers.GetJetConnection(); + } +} diff --git a/test/EFCore.Jet.Integration.Test/DmlSqlTest.cs b/test/EFCore.Jet.Integration.Test/DmlSqlTest.cs new file mode 100644 index 0000000..2fe0871 --- /dev/null +++ b/test/EFCore.Jet.Integration.Test/DmlSqlTest.cs @@ -0,0 +1,13 @@ +using System; +using System.Data.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace EFCore.Jet.Integration.Test +{ + //[TestClass] + public class DmlSqlTest : DmlBaseTest + { + protected override DbConnection GetConnection() + => Helpers.GetSqlServerConnection(); + } +} diff --git a/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj b/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj index af9a92f..3366fa2 100644 --- a/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj +++ b/test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj @@ -148,8 +148,9 @@ - - + + + @@ -197,13 +198,9 @@ - - - - + + - - @@ -381,10 +378,6 @@ - - - - @@ -415,7 +408,7 @@ - + diff --git a/test/EFCore.Jet.Integration.Test/Helpers.cs b/test/EFCore.Jet.Integration.Test/Helpers.cs index f96094f..4e89f81 100644 --- a/test/EFCore.Jet.Integration.Test/Helpers.cs +++ b/test/EFCore.Jet.Integration.Test/Helpers.cs @@ -94,6 +94,11 @@ namespace EFCore.Jet.Integration.Test } + private static string GetTestDirectory() + { + return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///", "")); + } + public static DbConnection GetJetConnection() { // Take care because according to this article @@ -119,7 +124,7 @@ namespace EFCore.Jet.Integration.Test //oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0"; //oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb"; oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0"; - oleDbConnectionStringBuilder.DataSource = @".\Empty.accdb"; + oleDbConnectionStringBuilder.DataSource = GetTestDirectory() + "\\Empty.accdb"; return oleDbConnectionStringBuilder.ToString(); } @@ -127,7 +132,7 @@ namespace EFCore.Jet.Integration.Test private static string GetSqlCeDatabaseFileName() { - return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///", "")) + "\\Data.sdf"; + return GetTestDirectory() + "\\Data.sdf"; } public static void CreateSqlCeDatabase() diff --git a/test/EFCore.Jet.Integration.Test/Model08/File.cs b/test/EFCore.Jet.Integration.Test/Model08/File.cs deleted file mode 100644 index 28a1561..0000000 --- a/test/EFCore.Jet.Integration.Test/Model08/File.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace EFCore.Jet.Integration.Test.Model08 -{ - public partial class File - { - public int Id { get; private set; } // PK - // Other properties - public string Description { get; set; } - } -} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model08/FileMap.cs b/test/EFCore.Jet.Integration.Test/Model08/FileMap.cs deleted file mode 100644 index 5169206..0000000 --- a/test/EFCore.Jet.Integration.Test/Model08/FileMap.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace EFCore.Jet.Integration.Test.Model08 -{ - public class FileMap : IEntityTypeConfiguration - { - public FileMap() - { - } - - public void Configure(EntityTypeBuilder builder) - { - // Primary Key - builder.HasKey(t => t.Id); - builder.Property(t => t.Id).ValueGeneratedOnAdd(); - builder.ToTable("Files"); - builder.Property(t => t.Id).HasColumnName("Id"); - // Other Properties go here - } - } -} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model08/GalleryImage.cs b/test/EFCore.Jet.Integration.Test/Model08/GalleryImage.cs deleted file mode 100644 index 8dcb140..0000000 --- a/test/EFCore.Jet.Integration.Test/Model08/GalleryImage.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EFCore.Jet.Integration.Test.Model08 -{ - public partial class GalleryImage : File - { - public string A { get; set; } - } -} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model08/GalleryImageMap.cs b/test/EFCore.Jet.Integration.Test/Model08/GalleryImageMap.cs deleted file mode 100644 index d5e3b77..0000000 --- a/test/EFCore.Jet.Integration.Test/Model08/GalleryImageMap.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace EFCore.Jet.Integration.Test.Model08 -{ - public class GalleryImageMap : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - // Primary Key - builder.HasKey(t => t.Id); - builder.ToTable("GalleryImages"); - builder.Property(t => t.Id).HasColumnName("Id"); - // Other properties go here - } - - } -} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model08/Mappings.cs b/test/EFCore.Jet.Integration.Test/Model08/Mappings.cs new file mode 100644 index 0000000..d58f63b --- /dev/null +++ b/test/EFCore.Jet.Integration.Test/Model08/Mappings.cs @@ -0,0 +1,63 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace EFCore.Jet.Integration.Test.Model08 +{ + public class FileMap : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + // Primary Key + builder.HasKey(t => t.Id); + builder.Property(t => t.Id).ValueGeneratedOnAdd(); + builder.ToTable("Files"); + builder.Property(t => t.Id).HasColumnName("Id"); + // Other Properties go here + } + } + + public class PageImageMap : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + + // Table & Column Mappings + builder.ToTable("PageImages"); + + // In EF Core this must be configured on the base type (see below for the error message) + // Primary Key + //builder.HasKey(t => t.Id); + // builder.Property(t => t.Id).HasColumnName("Id"); + + // Other properties go here + } + + } + + public class GalleryImageMap : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("GalleryImages"); + + // In EF core this must be configured on the base type (see below for the error message) + // Primary Key + //builder.HasKey(t => t.Id); + // builder.Property(t => t.Id).HasColumnName("Id"); + + // Other properties go here + } + + } +} + + +// Error message in case of wrong configuration +/* + * Initialization method EFCore.Jet.Integration.Test.Model08.Model08.Initialize threw exception.System.InvalidOperationException: + * System.InvalidOperationException: A key cannot be configured on 'GalleryImage' because it is a derived type.The key must be + * configured on the root type 'File'. If you did not intend for 'File' to be included in the model, ensure that it is not + * included in a DbSet property on your context, referenced in a configuration call to ModelBuilder, or referenced from a + * navigation property on a type that is included in the model.. + */ + diff --git a/test/EFCore.Jet.Integration.Test/Model08/Model.cs b/test/EFCore.Jet.Integration.Test/Model08/Model.cs new file mode 100644 index 0000000..e078753 --- /dev/null +++ b/test/EFCore.Jet.Integration.Test/Model08/Model.cs @@ -0,0 +1,19 @@ +namespace EFCore.Jet.Integration.Test.Model08 +{ + public class File + { + public int Id { get; private set; } // PK + // Other properties + public string Description { get; set; } + } + + public class GalleryImage : File + { + public string A { get; set; } + } + + public class PageImage : File + { + public string B { get; set; } + } +} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model08/PageImage.cs b/test/EFCore.Jet.Integration.Test/Model08/PageImage.cs deleted file mode 100644 index 6b43c55..0000000 --- a/test/EFCore.Jet.Integration.Test/Model08/PageImage.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace EFCore.Jet.Integration.Test.Model08 -{ - public partial class PageImage : File - { - public string B { get; set; } - } -} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model08/PageImageMap.cs b/test/EFCore.Jet.Integration.Test/Model08/PageImageMap.cs deleted file mode 100644 index 4d09589..0000000 --- a/test/EFCore.Jet.Integration.Test/Model08/PageImageMap.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace EFCore.Jet.Integration.Test.Model08 -{ - public class PageImageMap : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - // Primary Key - builder.HasKey(t => t.Id); - - // Table & Column Mappings - builder.ToTable("PageImages"); - builder.Property(t => t.Id).HasColumnName("Id"); - // Other properties go here - } - - } -} \ No newline at end of file diff --git a/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Mapping.cs b/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Mapping.cs index e031a0f..bc314af 100644 --- a/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Mapping.cs +++ b/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Mapping.cs @@ -22,8 +22,6 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT { public void Configure(EntityTypeBuilder builder) { - // Primary Key - builder.HasKey(s => s.Id); // Properties diff --git a/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Test.cs b/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Test.cs index f9ed723..c49401c 100644 --- a/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Test.cs +++ b/test/EFCore.Jet.Integration.Test/Model25_InheritTPT/Test.cs @@ -9,14 +9,14 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT [TestMethod] - public void Run() + public void Model25_InheritTPTRun() { var companies = new List { - new Company {Id = 1, Name = "X", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, - new Company {Id = 2, Name = "XX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, - new Company {Id = 3, Name = "XXX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, - new Company {Id = 4, Name = "XXXX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, + new Company {Name = "X", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, + new Company {Name = "XX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, + new Company {Name = "XXX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, + new Company {Name = "XXXX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, }; foreach (var item in companies) @@ -26,10 +26,10 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT var suppliers = new List { - new Supplier {Id = 1, CreatedOn = DateTime.Now, Company = companies[0], IsActive = true, UpdatedOn = DateTime.Now}, - new Supplier {Id = 2, CreatedOn = DateTime.Now, Company = companies[1], IsActive = true, UpdatedOn = DateTime.Now}, - new Supplier {Id = 3, CreatedOn = DateTime.Now, Company = companies[2], IsActive = true, UpdatedOn = DateTime.Now}, - new Supplier {Id = 4, CreatedOn = DateTime.Now, Company = companies[3], IsActive = true, UpdatedOn = DateTime.Now} + new Supplier {CreatedOn = DateTime.Now, Company = companies[0], IsActive = true, UpdatedOn = DateTime.Now}, + new Supplier {CreatedOn = DateTime.Now, Company = companies[1], IsActive = true, UpdatedOn = DateTime.Now}, + new Supplier {CreatedOn = DateTime.Now, Company = companies[2], IsActive = true, UpdatedOn = DateTime.Now}, + new Supplier {CreatedOn = DateTime.Now, Company = companies[3], IsActive = true, UpdatedOn = DateTime.Now} }; foreach (var item in suppliers) diff --git a/test/EFCore.Jet.Integration.Test/Model28/Context.cs b/test/EFCore.Jet.Integration.Test/Model28/Context.cs index ec5becd..bc6e05c 100644 --- a/test/EFCore.Jet.Integration.Test/Model28/Context.cs +++ b/test/EFCore.Jet.Integration.Test/Model28/Context.cs @@ -28,10 +28,13 @@ namespace EFCore.Jet.Integration.Test.Model28 .IsRequired() ; + // Is required must be inserted in foreign key field if there is one + /* modelBuilder.Entity() .Property(x => x.Advertisement) .IsRequired() ; + */ base.OnModelCreating(modelBuilder); diff --git a/test/EFCore.Jet.Integration.Test/Model56_SkipTake/Test.cs b/test/EFCore.Jet.Integration.Test/Model56_SkipTake/Test.cs index 48feede..4ce6c4d 100644 --- a/test/EFCore.Jet.Integration.Test/Model56_SkipTake/Test.cs +++ b/test/EFCore.Jet.Integration.Test/Model56_SkipTake/Test.cs @@ -98,7 +98,7 @@ namespace EFCore.Jet.Integration.Test.Model56_SkipTake for (int i = 0; i < entities.Count - 1; i++) { Entity entity = entities[i]; - Assert.AreEqual(-1, String.CompareOrdinal(entity.Description , entities[i + 1].Description)); + Assert.AreEqual(-1, String.Compare(entity.Description , entities[i + 1].Description)); } } diff --git a/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Model.cs b/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Model.cs index 9b83050..cf76329 100644 --- a/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Model.cs +++ b/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Model.cs @@ -44,7 +44,7 @@ namespace EFCore.Jet.Integration.Test.Model59_StackOverflow_TPT_TPH { A, B, - C + Caa } public enum DataCaptureActivityType diff --git a/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Test.cs b/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Test.cs index f180229c..0778d84 100644 --- a/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Test.cs +++ b/test/EFCore.Jet.Integration.Test/Model59_StackOverflow_TPT_TPH/Test.cs @@ -9,7 +9,8 @@ namespace EFCore.Jet.Integration.Test.Model59_StackOverflow_TPT_TPH public void Run() { { - Context.DataCaptureActivities.Add(new DataCaptureActivity() {Description = "Description"}); + Context.DataCaptureActivities.Add(new DataCaptureActivity() {Description = "Description", ActivityType = ActivityType.A}); + Context.DataCaptureActivities.Add(new DataCaptureActivity() { Description = "Description", ActivityType = ActivityType.B }); Context.SaveChanges(); } } diff --git a/test/EFCore.Jet.Integration.Test/Model67_DifferentProxies/README.cs b/test/EFCore.Jet.Integration.Test/Model67_DifferentProxies/README.cs new file mode 100644 index 0000000..e6eab37 --- /dev/null +++ b/test/EFCore.Jet.Integration.Test/Model67_DifferentProxies/README.cs @@ -0,0 +1,6 @@ +/* + +This test is based on lazy load that is not implemented in EF Core + + +*/ \ No newline at end of file diff --git a/test/System.Data.Jet.Test/AssemblyInitialization.cs b/test/System.Data.Jet.Test/AssemblyInitialization.cs new file mode 100644 index 0000000..690cb04 --- /dev/null +++ b/test/System.Data.Jet.Test/AssemblyInitialization.cs @@ -0,0 +1,35 @@ +using System; +using System.Data.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace System.Data.Jet.Test +{ + [TestClass] + public class AssemblyInitialization + { + + public static DbConnection Connection; + + [AssemblyInitialize] + static public void AssemblyInitialize(TestContext testContext) + { + + // This is the only reason why we include the Provider + JetConfiguration.ShowSqlStatements = true; + + Connection = Helpers.GetJetConnection(); + + } + + + [AssemblyCleanup] + static public void AssemblyCleanup() + { + if (Connection != null) + Connection.Dispose(); + + } + + + } +} diff --git a/test/System.Data.Jet.Test/DdlTest.cs b/test/System.Data.Jet.Test/DdlTest.cs new file mode 100644 index 0000000..928a7df --- /dev/null +++ b/test/System.Data.Jet.Test/DdlTest.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace System.Data.Jet.Test +{ + [TestClass] + public class DdlTest + { + [TestMethod] + public void CheckIfTablesExists() + { + + var queries = Helpers.GetQueries(System.Data.Jet.Test.Properties.Resources.CheckIfTableExistsTestQueries); + + using (var connection = Helpers.GetJetConnection()) + { + connection.Open(); + Helpers.Execute(connection, queries[0]); + + bool exists = ((JetConnection)AssemblyInitialization.Connection).TableExists("CheckIfTableExistsTable"); + Assert.IsTrue(exists); + + Helpers.Execute(connection, queries[1]); + } + + } + } +} diff --git a/test/System.Data.Jet.Test/Helpers.cs b/test/System.Data.Jet.Test/Helpers.cs index 2c28a47..30faa58 100644 --- a/test/System.Data.Jet.Test/Helpers.cs +++ b/test/System.Data.Jet.Test/Helpers.cs @@ -90,6 +90,10 @@ namespace System.Data.Jet.Test } + private static string GetTestDirectory() + { + return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:///", "")); + } public static DbConnection GetJetConnection() { @@ -116,7 +120,7 @@ namespace System.Data.Jet.Test //oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0"; //oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb"; oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0"; - oleDbConnectionStringBuilder.DataSource = @".\Empty.accdb"; + oleDbConnectionStringBuilder.DataSource = GetTestDirectory() + "\\Empty.accdb"; return oleDbConnectionStringBuilder.ToString(); } @@ -151,6 +155,17 @@ namespace System.Data.Jet.Test } public static DbDataReader Execute(DbConnection connection, string query) + { + return InternatExecute(connection, null, query); + } + + public static DbDataReader Execute(DbConnection connection, DbTransaction transaction, string query) + { + return InternatExecute(connection, transaction, query); + } + + + private static DbDataReader InternatExecute(DbConnection connection, DbTransaction transaction, string query) { string[] sqlParts = query.Split('\n'); string executionMethod = sqlParts[0]; @@ -159,6 +174,8 @@ namespace System.Data.Jet.Test sql += sqlParts[i] + "\r\n"; var command = connection.CreateCommand(); + if (transaction != null) + command.Transaction = transaction; command.CommandText = sql; @@ -174,6 +191,5 @@ namespace System.Data.Jet.Test else throw new Exception("Unknown execution method " + executionMethod); } - } } diff --git a/test/System.Data.Jet.Test/Properties/Resources.Designer.cs b/test/System.Data.Jet.Test/Properties/Resources.Designer.cs index b3d959b..f89dfc1 100644 --- a/test/System.Data.Jet.Test/Properties/Resources.Designer.cs +++ b/test/System.Data.Jet.Test/Properties/Resources.Designer.cs @@ -1,88 +1,109 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace System.Data.Jet.Test.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Data.Jet.Test.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to ExecuteNonQuery========== - ///CREATE TABLE [Standards] ( - /// [StandardId] int NOT NULL IDENTITY, - /// [Description] text NULL, - /// [StandardName] varchar(255) NULL, - /// CONSTRAINT [PK_Standards] PRIMARY KEY ([StandardId]) - ///); - /// - ///ExecuteDbDataReader========== - ///INSERT INTO [Students] ([Notes], [StandardId], [StudentName]) - ///VALUES (null, null, 'Student to update'); - ///SELECT [StudentId] - ///FROM [Students] - ///WHERE 1 = 1 AND [StudentId] = @@identity; - /// - ///ExecuteDbDataReader========== - ///SELECT TOP 1 [s].[StudentId], [s] [rest of string was truncated]";. - /// - internal static string UpdateTestQueries { - get { - return ResourceManager.GetString("UpdateTestQueries", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace System.Data.Jet.Test.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Data.Jet.Test.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to ExecuteNonQuery========== + ///CREATE TABLE [CheckIfTableExistsTable] ( + /// [StudentId] int NOT NULL IDENTITY, + /// [Notes] text NULL, + /// [StudentName] varchar(50) NOT NULL, + /// CONSTRAINT [PK_Students] PRIMARY KEY ([StudentId]) + ///); + /// + /// + ///ExecuteNonQuery========== + ///DROP TABLE [CheckIfTableExistsTable] + /// + ///. + /// + internal static string CheckIfTableExistsTestQueries { + get { + return ResourceManager.GetString("CheckIfTableExistsTestQueries", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to ExecuteNonQuery========== + ///CREATE TABLE [Students] ( + /// [StudentId] int NOT NULL IDENTITY, + /// [Notes] text NULL, + /// [StudentName] varchar(50) NOT NULL, + /// CONSTRAINT [PK_Students] PRIMARY KEY ([StudentId]) + ///); + /// + ///ExecuteDbDataReader========== + ///INSERT INTO [Students] ([Notes], [StudentName]) + ///VALUES (null, 'Student to update'); + ///SELECT [StudentId] + ///FROM [Students] + ///WHERE 1 = 1 AND [StudentId] = @@identity; + /// + ///ExecuteDbDataReader========== + ///SELECT TOP 1 [s].[StudentId], [s].[Notes], [s].[StudentName] /// [rest of string was truncated]";. + /// + internal static string UpdateTestQueries { + get { + return ResourceManager.GetString("UpdateTestQueries", resourceCulture); + } + } + } +} diff --git a/test/System.Data.Jet.Test/Properties/Resources.resx b/test/System.Data.Jet.Test/Properties/Resources.resx index 0228ea9..709ceb5 100644 --- a/test/System.Data.Jet.Test/Properties/Resources.resx +++ b/test/System.Data.Jet.Test/Properties/Resources.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\CheckIfTableExistsTestQueries.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + ..\Resources\UpdateTestQueries.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 diff --git a/test/System.Data.Jet.Test/Resources/CheckIfTableExistsTestQueries.txt b/test/System.Data.Jet.Test/Resources/CheckIfTableExistsTestQueries.txt new file mode 100644 index 0000000..9590bf5 --- /dev/null +++ b/test/System.Data.Jet.Test/Resources/CheckIfTableExistsTestQueries.txt @@ -0,0 +1,12 @@ +ExecuteNonQuery========== +CREATE TABLE [CheckIfTableExistsTable] ( + [StudentId] int NOT NULL IDENTITY, + [Notes] text NULL, + [StudentName] varchar(50) NOT NULL, + CONSTRAINT [PK_Students] PRIMARY KEY ([StudentId]) +); + + +ExecuteNonQuery========== +DROP TABLE [CheckIfTableExistsTable] + diff --git a/test/System.Data.Jet.Test/Resources/UpdateTestQueries.txt b/test/System.Data.Jet.Test/Resources/UpdateTestQueries.txt index 2643b67..55b2fef 100644 --- a/test/System.Data.Jet.Test/Resources/UpdateTestQueries.txt +++ b/test/System.Data.Jet.Test/Resources/UpdateTestQueries.txt @@ -25,4 +25,8 @@ WHERE [StudentId] = @@identity; ExecuteDbDataReader========== SELECT COUNT(*) FROM [Students] AS [s] -WHERE [s].[StudentName] = 'Student updated' \ No newline at end of file +WHERE [s].[StudentName] = 'Student updated' + +ExecuteNonQuery========== +DROP TABLE [Students] + diff --git a/test/System.Data.Jet.Test/System.Data.Jet.Test.csproj b/test/System.Data.Jet.Test/System.Data.Jet.Test.csproj index f656287..f8d562b 100644 --- a/test/System.Data.Jet.Test/System.Data.Jet.Test.csproj +++ b/test/System.Data.Jet.Test/System.Data.Jet.Test.csproj @@ -68,6 +68,7 @@ + @@ -76,6 +77,7 @@ True Resources.resx + @@ -101,6 +103,9 @@ + + + diff --git a/test/System.Data.Jet.Test/UpdateTest.cs b/test/System.Data.Jet.Test/UpdateTest.cs index a7be749..d65961a 100644 --- a/test/System.Data.Jet.Test/UpdateTest.cs +++ b/test/System.Data.Jet.Test/UpdateTest.cs @@ -9,29 +9,65 @@ namespace System.Data.Jet.Test { [TestMethod] public void UpdateTestRun() + { + var queries = Helpers.GetQueries(Properties.Resources.UpdateTestQueries); + Assert.AreEqual(6, queries.Length); + + using (var connection = Helpers.GetJetConnection()) + { + connection.Open(); + DbDataReader reader; + for (int index = 0; index < queries.Length - 2; index++) + { + string query = queries[index]; + reader = Helpers.Execute(connection, query); + if (reader != null) + reader.Dispose(); + } + reader = Helpers.Execute(connection, queries[4]); + reader.Read(); + Assert.AreEqual(1, reader.GetInt32(0)); + reader.Dispose(); + + Helpers.Execute(connection, queries[5]); + + + } + } + + + [TestMethod] + public void UpdateTestWithTransactionsRun() { JetConfiguration.ShowSqlStatements = true; var queries = Helpers.GetQueries(Properties.Resources.UpdateTestQueries); - Assert.AreEqual(5, queries.Length); + Assert.AreEqual(6, queries.Length); using (var connection = Helpers.GetJetConnection()) { connection.Open(); DbDataReader reader; - for (int index = 0; index < queries.Length - 1; index++) + for (int index = 0; index < queries.Length - 2; index++) { + DbTransaction transaction = connection.BeginTransaction(); string query = queries[index]; - reader = Helpers.Execute(connection, query); + reader = Helpers.Execute(connection, transaction, query); if (reader != null) reader.Dispose(); + transaction.Commit(); } reader = Helpers.Execute(connection, queries[4]); reader.Read(); Assert.AreEqual(1, reader.GetInt32(0)); reader.Dispose(); + Helpers.Execute(connection, queries[5]); + + } } + + } }