Fixed tests

2.2-servicing
bubibubi 8 years ago
parent 86c69d31df
commit 8a6676904e

@ -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;

@ -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));
}
}
/// <summary>
/// Creates a prepared (or compiled) version of the command on the data source
/// </summary>

@ -6,8 +6,6 @@ namespace System.Data.Jet
{
class JetDataReader : DbDataReader
{
public JetDataReader(DbDataReader dataReader)
{
_wrappedDataReader = dataReader;

@ -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;
}
}
}
}

@ -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();
}

@ -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));
}
}

@ -71,6 +71,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="JetDataReader.cs" />
<Compile Include="JetParameterHelper.cs" />
<Compile Include="JetProviderFactory.cs" />
<Compile Include="JetProviderManifest.cs" />
<Compile Include="JetStoreSchemaDefinition\Column.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<Context>.GetContextOptions(Connection));
TestBase<Context>.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();
}

@ -10,7 +10,7 @@ namespace EFCore.Jet.Integration.Test
public class BooleanMaterializationTest2 : TestBase<Context>
{
[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()

@ -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();
}

@ -49,7 +49,7 @@ namespace EFCore.Jet.Integration.Test
protected override DbConnection GetConnection()
{
return SetUpCodeFirst.Connection;
return AssemblyInitialization.Connection;
}
}
}

@ -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);
}
}
}

@ -6,8 +6,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EFCore.Jet.Integration.Test
{
[TestClass]
public class DmlTest : TestBase<Context>
public abstract class DmlBaseTest : TestBase<Context>
{
[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();
}
}

@ -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();
}
}

@ -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();
}
}

@ -148,8 +148,9 @@
<Compile Include="BooleanMaterializationTest2.cs" />
<Compile Include="BooleanMaterializationTest1.cs" />
<Compile Include="CanonicalFunctionsTest2.cs" />
<Compile Include="DdlTest.cs" />
<Compile Include="DmlTest.cs" />
<Compile Include="DmlBaseTest.cs" />
<Compile Include="DmlSqlTest.cs" />
<Compile Include="DmlJetTest.cs" />
<Compile Include="Model04\SqlCeTest.cs" />
<Compile Include="Model37_2Contexts\SqlServerTest.cs" />
<Compile Include="Model37_2Contexts\SqlCeTest.cs" />
@ -197,13 +198,9 @@
<Compile Include="Model07\JetTest.cs" />
<Compile Include="Model07\Test.cs" />
<Compile Include="Model08\Context.cs" />
<Compile Include="Model08\File.cs" />
<Compile Include="Model08\FileMap.cs" />
<Compile Include="Model08\GalleryImage.cs" />
<Compile Include="Model08\GalleryImageMap.cs" />
<Compile Include="Model08\Model.cs" />
<Compile Include="Model08\Mappings.cs" />
<Compile Include="Model08\JetTest.cs" />
<Compile Include="Model08\PageImage.cs" />
<Compile Include="Model08\PageImageMap.cs" />
<Compile Include="Model08\Test.cs" />
<Compile Include="Model09\JetTest.cs" />
<Compile Include="Model09\Test.cs" />
@ -381,10 +378,6 @@
<Compile Include="Model68_sbyte\JetTest.cs" />
<Compile Include="Model68_sbyte\Model.cs" />
<Compile Include="Model68_sbyte\Test.cs" />
<Compile Include="Model67_DifferentProxies\Context.cs" />
<Compile Include="Model67_DifferentProxies\JetTest.cs" />
<Compile Include="Model67_DifferentProxies\Model.cs" />
<Compile Include="Model67_DifferentProxies\Test.cs" />
<Compile Include="Model66_StackOverflow_TooManyColumns\Context.cs" />
<Compile Include="Model66_StackOverflow_TooManyColumns\JetTest.cs" />
<Compile Include="Model66_StackOverflow_TooManyColumns\Model.cs" />
@ -415,7 +408,7 @@
<Compile Include="Model55_Unicode\Test.cs" />
<Compile Include="Model73_ValidationContext\README.cs" />
<Compile Include="Program.cs" />
<Compile Include="SetUpCodeFirst.cs" />
<Compile Include="AssemblyInitialization.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="JetProviderFactory\JetStoreSchemaDefinitionRetrieveTest.cs" />
<Compile Include="Properties\AssemblyInfo.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()

@ -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; }
}
}

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace EFCore.Jet.Integration.Test.Model08
{
public class FileMap : IEntityTypeConfiguration<File>
{
public FileMap()
{
}
public void Configure(EntityTypeBuilder<File> 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
}
}
}

@ -1,7 +0,0 @@
namespace EFCore.Jet.Integration.Test.Model08
{
public partial class GalleryImage : File
{
public string A { get; set; }
}
}

@ -1,18 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace EFCore.Jet.Integration.Test.Model08
{
public class GalleryImageMap : IEntityTypeConfiguration<GalleryImage>
{
public void Configure(EntityTypeBuilder<GalleryImage> builder)
{
// Primary Key
builder.HasKey(t => t.Id);
builder.ToTable("GalleryImages");
builder.Property(t => t.Id).HasColumnName("Id");
// Other properties go here
}
}
}

@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace EFCore.Jet.Integration.Test.Model08
{
public class FileMap : IEntityTypeConfiguration<File>
{
public void Configure(EntityTypeBuilder<File> 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<PageImage>
{
public void Configure(EntityTypeBuilder<PageImage> 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<GalleryImage>
{
public void Configure(EntityTypeBuilder<GalleryImage> 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..
*/

@ -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; }
}
}

@ -1,7 +0,0 @@
namespace EFCore.Jet.Integration.Test.Model08
{
public partial class PageImage : File
{
public string B { get; set; }
}
}

@ -1,20 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace EFCore.Jet.Integration.Test.Model08
{
public class PageImageMap : IEntityTypeConfiguration<PageImage>
{
public void Configure(EntityTypeBuilder<PageImage> 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
}
}
}

@ -22,8 +22,6 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT
{
public void Configure(EntityTypeBuilder<Supplier> builder)
{
// Primary Key
builder.HasKey(s => s.Id);
// Properties

@ -9,14 +9,14 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT
[TestMethod]
public void Run()
public void Model25_InheritTPTRun()
{
var companies = new List<Company>
{
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<Supplier>
{
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)

@ -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<AdImage>()
.Property(x => x.Advertisement)
.IsRequired()
;
*/
base.OnModelCreating(modelBuilder);

@ -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));
}
}

@ -44,7 +44,7 @@ namespace EFCore.Jet.Integration.Test.Model59_StackOverflow_TPT_TPH
{
A,
B,
C
Caa
}
public enum DataCaptureActivityType

@ -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();
}
}

@ -0,0 +1,6 @@
/*
This test is based on lazy load that is not implemented in EF Core
*/

@ -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();
}
}
}

@ -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]);
}
}
}
}

@ -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);
}
}
}

@ -1,88 +1,109 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace System.Data.Jet.Test.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 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, &apos;Student to update&apos;);
///SELECT [StudentId]
///FROM [Students]
///WHERE 1 = 1 AND [StudentId] = @@identity;
///
///ExecuteDbDataReader==========
///SELECT TOP 1 [s].[StudentId], [s] [rest of string was truncated]&quot;;.
/// </summary>
internal static string UpdateTestQueries {
get {
return ResourceManager.GetString("UpdateTestQueries", resourceCulture);
}
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace System.Data.Jet.Test.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// 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]
///
///.
/// </summary>
internal static string CheckIfTableExistsTestQueries {
get {
return ResourceManager.GetString("CheckIfTableExistsTestQueries", resourceCulture);
}
}
/// <summary>
/// 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, &apos;Student to update&apos;);
///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]&quot;;.
/// </summary>
internal static string UpdateTestQueries {
get {
return ResourceManager.GetString("UpdateTestQueries", resourceCulture);
}
}
}
}

@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="CheckIfTableExistsTestQueries" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\CheckIfTableExistsTestQueries.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="UpdateTestQueries" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\UpdateTestQueries.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>

@ -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]

@ -25,4 +25,8 @@ WHERE [StudentId] = @@identity;
ExecuteDbDataReader==========
SELECT COUNT(*)
FROM [Students] AS [s]
WHERE [s].[StudentName] = 'Student updated'
WHERE [s].[StudentName] = 'Student updated'
ExecuteNonQuery==========
DROP TABLE [Students]

@ -68,6 +68,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DdlTest.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="JetStoreSchemaDefinitionRetrieveTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -76,6 +77,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="AssemblyInitialization.cs" />
<Compile Include="UpdateTest.cs" />
</ItemGroup>
<ItemGroup>
@ -101,6 +103,9 @@
<ItemGroup>
<None Include="Resources\UpdateTestQueries.txt" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\CheckIfTableExistsTestQueries.txt" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

@ -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]);
}
}
}
}

Loading…
Cancel
Save