Fixed tests

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

@ -2,7 +2,6 @@
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Data.Jet;
using System.Data.OleDb; using System.Data.OleDb;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;

@ -306,6 +306,7 @@ namespace System.Data.Jet
int indexOfSkip; int indexOfSkip;
string newCommandText; string newCommandText;
ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText); ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText);
ApplyParameters(newCommandText, _WrappedCommand.Parameters, out newCommandText);
if (skipCount != 0) if (skipCount != 0)
{ {
@ -331,8 +332,6 @@ namespace System.Data.Jet
} }
private int InternalExecuteNonQuery(string commandText) private int InternalExecuteNonQuery(string commandText)
{ {
@ -341,6 +340,7 @@ namespace System.Data.Jet
int indexOfSkip; int indexOfSkip;
string newCommandText; string newCommandText;
ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText); ParseSkipTop(commandText, out topCount, out skipCount, out indexOfSkip, out newCommandText);
ApplyParameters(newCommandText, _WrappedCommand.Parameters, out newCommandText);
DbCommand command; DbCommand command;
command = (DbCommand)((ICloneable)this._WrappedCommand).Clone(); command = (DbCommand)((ICloneable)this._WrappedCommand).Clone();
@ -374,6 +374,7 @@ namespace System.Data.Jet
command.CommandText = "Select @@identity"; command.CommandText = "Select @@identity";
object identity = command.ExecuteScalar(); object identity = command.ExecuteScalar();
int iIdentity = Convert.ToInt32(identity); int iIdentity = Convert.ToInt32(identity);
Console.WriteLine("@@identity = {0}", iIdentity);
return Regex.Replace(commandText, "@@identity", iIdentity.ToString(System.Globalization.CultureInfo.InvariantCulture), RegexOptions.IgnoreCase); return Regex.Replace(commandText, "@@identity", iIdentity.ToString(System.Globalization.CultureInfo.InvariantCulture), RegexOptions.IgnoreCase);
} }
return commandText; return commandText;
@ -388,6 +389,7 @@ namespace System.Data.Jet
command.CommandText = "Select @@guid"; command.CommandText = "Select @@guid";
object identity = command.ExecuteScalar(); object identity = command.ExecuteScalar();
int iIdentity = Convert.ToInt32(identity); int iIdentity = Convert.ToInt32(identity);
Console.WriteLine("@@guid = {0}", iIdentity);
return Regex.Replace(commandText, "@@guid", iIdentity.ToString(System.Globalization.CultureInfo.InvariantCulture), RegexOptions.IgnoreCase); return Regex.Replace(commandText, "@@guid", iIdentity.ToString(System.Globalization.CultureInfo.InvariantCulture), RegexOptions.IgnoreCase);
} }
return commandText; 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> /// <summary>
/// Creates a prepared (or compiled) version of the command on the data source /// Creates a prepared (or compiled) version of the command on the data source
/// </summary> /// </summary>

@ -6,8 +6,6 @@ namespace System.Data.Jet
{ {
class JetDataReader : DbDataReader class JetDataReader : DbDataReader
{ {
public JetDataReader(DbDataReader dataReader) public JetDataReader(DbDataReader dataReader)
{ {
_wrappedDataReader = 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) public JetTransaction(DbTransaction wrappedTransaction, DbConnection connection)
{ {
LogHelper.ShowCommandHeader("vvv BeginTransaction"); LogHelper.ShowCommandHeader("\r\nvvv BeginTransaction (" + wrappedTransaction.IsolationLevel + ")");
WrappedTransaction = wrappedTransaction; WrappedTransaction = wrappedTransaction;
_connection = connection; _connection = connection;
} }
@ -34,7 +34,7 @@ namespace System.Data.Jet
public override void Rollback() public override void Rollback()
{ {
LogHelper.ShowCommandHeader("^^^ Commit"); LogHelper.ShowCommandHeader("^^^ Rollback");
WrappedTransaction.Rollback(); WrappedTransaction.Rollback();
} }

@ -22,59 +22,6 @@ static internal class LogHelper
Console.WriteLine("{0}", command.CommandText); Console.WriteLine("{0}", command.CommandText);
foreach (DbParameter parameter in command.Parameters) foreach (DbParameter parameter in command.Parameters)
Console.WriteLine("{0} = {1}", parameter.ParameterName, GetParameterValue(parameter)); Console.WriteLine("{0}({1}) = {2}", parameter.ParameterName, parameter.DbType, JetParameterHelper.GetParameterValueToDisplay(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;
}
} }
} }

@ -71,6 +71,7 @@
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="JetDataReader.cs" /> <Compile Include="JetDataReader.cs" />
<Compile Include="JetParameterHelper.cs" />
<Compile Include="JetProviderFactory.cs" /> <Compile Include="JetProviderFactory.cs" />
<Compile Include="JetProviderManifest.cs" /> <Compile Include="JetProviderManifest.cs" />
<Compile Include="JetStoreSchemaDefinition\Column.cs" /> <Compile Include="JetStoreSchemaDefinition\Column.cs" />

@ -1,13 +1,12 @@
using System; using System;
using System.Data.Common; using System.Data.Common;
using System.Data.Jet; using System.Data.Jet;
using EFCore.Jet.Integration.Test.Model01;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EFCore.Jet.Integration.Test namespace EFCore.Jet.Integration.Test
{ {
[TestClass] [TestClass]
public class SetUpCodeFirst public class AssemblyInitialization
{ {
public static DbConnection Connection; public static DbConnection Connection;
@ -21,19 +20,6 @@ namespace EFCore.Jet.Integration.Test
Connection = Helpers.GetJetConnection(); 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.DeleteSqlCeDatabase();
Helpers.CreateSqlCeDatabase(); Helpers.CreateSqlCeDatabase();
} }
@ -42,6 +28,7 @@ namespace EFCore.Jet.Integration.Test
[AssemblyCleanup] [AssemblyCleanup]
static public void AssemblyCleanup() static public void AssemblyCleanup()
{ {
if (Connection != null)
Connection.Dispose(); Connection.Dispose();
Helpers.DeleteSqlCeDatabase(); Helpers.DeleteSqlCeDatabase();

@ -10,7 +10,7 @@ namespace EFCore.Jet.Integration.Test
public class BooleanMaterializationTest2 : TestBase<Context> public class BooleanMaterializationTest2 : TestBase<Context>
{ {
[TestMethod] [TestMethod]
public void Run() public void BooleanMaterializationTest2Run()
{ {
// ReSharper disable once RedundantCast // ReSharper disable once RedundantCast
Console.WriteLine(Context.TableWithSeveralFieldsTypes.Select(c => new {MyNewProperty = (bool) true}).ToList().Count); 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() protected override DbConnection GetConnection()
{ {
return SetUpCodeFirst.Connection; return AssemblyInitialization.Connection;
} }
public override void CleanUp() public override void CleanUp()

@ -34,8 +34,14 @@ namespace EFCore.Jet.Integration.Test
Context.Students.Add(student); Context.Students.Add(student);
Context.SaveChanges(); 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(); Context.Dispose();
} }

@ -49,7 +49,7 @@ namespace EFCore.Jet.Integration.Test
protected override DbConnection GetConnection() 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 namespace EFCore.Jet.Integration.Test
{ {
[TestClass] public abstract class DmlBaseTest : TestBase<Context>
public class DmlTest : TestBase<Context>
{ {
[TestMethod] [TestMethod]
public void Insert() public void Insert()
@ -38,12 +37,25 @@ namespace EFCore.Jet.Integration.Test
base.DisposeContext(); base.DisposeContext();
base.CreateContext(); base.CreateContext();
// Retrieve the student // Retrieve the student
student = Context.Students.Where(s => s.StudentId == studentId).First(); 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 // Update the student
student.StudentName = "Student updated"; student.StudentName = "Student updated";
Context.SaveChanges(); Context.SaveChanges();
base.DisposeContext(); base.DisposeContext();
// Retrieve the student and check that is the right student // 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="BooleanMaterializationTest2.cs" />
<Compile Include="BooleanMaterializationTest1.cs" /> <Compile Include="BooleanMaterializationTest1.cs" />
<Compile Include="CanonicalFunctionsTest2.cs" /> <Compile Include="CanonicalFunctionsTest2.cs" />
<Compile Include="DdlTest.cs" /> <Compile Include="DmlBaseTest.cs" />
<Compile Include="DmlTest.cs" /> <Compile Include="DmlSqlTest.cs" />
<Compile Include="DmlJetTest.cs" />
<Compile Include="Model04\SqlCeTest.cs" /> <Compile Include="Model04\SqlCeTest.cs" />
<Compile Include="Model37_2Contexts\SqlServerTest.cs" /> <Compile Include="Model37_2Contexts\SqlServerTest.cs" />
<Compile Include="Model37_2Contexts\SqlCeTest.cs" /> <Compile Include="Model37_2Contexts\SqlCeTest.cs" />
@ -197,13 +198,9 @@
<Compile Include="Model07\JetTest.cs" /> <Compile Include="Model07\JetTest.cs" />
<Compile Include="Model07\Test.cs" /> <Compile Include="Model07\Test.cs" />
<Compile Include="Model08\Context.cs" /> <Compile Include="Model08\Context.cs" />
<Compile Include="Model08\File.cs" /> <Compile Include="Model08\Model.cs" />
<Compile Include="Model08\FileMap.cs" /> <Compile Include="Model08\Mappings.cs" />
<Compile Include="Model08\GalleryImage.cs" />
<Compile Include="Model08\GalleryImageMap.cs" />
<Compile Include="Model08\JetTest.cs" /> <Compile Include="Model08\JetTest.cs" />
<Compile Include="Model08\PageImage.cs" />
<Compile Include="Model08\PageImageMap.cs" />
<Compile Include="Model08\Test.cs" /> <Compile Include="Model08\Test.cs" />
<Compile Include="Model09\JetTest.cs" /> <Compile Include="Model09\JetTest.cs" />
<Compile Include="Model09\Test.cs" /> <Compile Include="Model09\Test.cs" />
@ -381,10 +378,6 @@
<Compile Include="Model68_sbyte\JetTest.cs" /> <Compile Include="Model68_sbyte\JetTest.cs" />
<Compile Include="Model68_sbyte\Model.cs" /> <Compile Include="Model68_sbyte\Model.cs" />
<Compile Include="Model68_sbyte\Test.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\Context.cs" />
<Compile Include="Model66_StackOverflow_TooManyColumns\JetTest.cs" /> <Compile Include="Model66_StackOverflow_TooManyColumns\JetTest.cs" />
<Compile Include="Model66_StackOverflow_TooManyColumns\Model.cs" /> <Compile Include="Model66_StackOverflow_TooManyColumns\Model.cs" />
@ -415,7 +408,7 @@
<Compile Include="Model55_Unicode\Test.cs" /> <Compile Include="Model55_Unicode\Test.cs" />
<Compile Include="Model73_ValidationContext\README.cs" /> <Compile Include="Model73_ValidationContext\README.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="SetUpCodeFirst.cs" /> <Compile Include="AssemblyInitialization.cs" />
<Compile Include="Helpers.cs" /> <Compile Include="Helpers.cs" />
<Compile Include="JetProviderFactory\JetStoreSchemaDefinitionRetrieveTest.cs" /> <Compile Include="JetProviderFactory\JetStoreSchemaDefinitionRetrieveTest.cs" />
<Compile Include="Properties\AssemblyInfo.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() public static DbConnection GetJetConnection()
{ {
// Take care because according to this article // Take care because according to this article
@ -119,7 +124,7 @@ namespace EFCore.Jet.Integration.Test
//oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0"; //oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
//oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb"; //oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb";
oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0"; oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
oleDbConnectionStringBuilder.DataSource = @".\Empty.accdb"; oleDbConnectionStringBuilder.DataSource = GetTestDirectory() + "\\Empty.accdb";
return oleDbConnectionStringBuilder.ToString(); return oleDbConnectionStringBuilder.ToString();
} }
@ -127,7 +132,7 @@ namespace EFCore.Jet.Integration.Test
private static string GetSqlCeDatabaseFileName() 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() 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) public void Configure(EntityTypeBuilder<Supplier> builder)
{ {
// Primary Key
builder.HasKey(s => s.Id);
// Properties // Properties

@ -9,14 +9,14 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT
[TestMethod] [TestMethod]
public void Run() public void Model25_InheritTPTRun()
{ {
var companies = new List<Company> var companies = new List<Company>
{ {
new Company {Id = 1, Name = "X", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now}, new Company {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 {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 {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 = "XXXX", CreatedOn = DateTime.Now, IsActive = true, UpdatedOn = DateTime.Now},
}; };
foreach (var item in companies) foreach (var item in companies)
@ -26,10 +26,10 @@ namespace EFCore.Jet.Integration.Test.Model25_InheritTPT
var suppliers = new List<Supplier> var suppliers = new List<Supplier>
{ {
new Supplier {Id = 1, CreatedOn = DateTime.Now, Company = companies[0], IsActive = true, UpdatedOn = DateTime.Now}, new Supplier {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 {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 {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[3], IsActive = true, UpdatedOn = DateTime.Now}
}; };
foreach (var item in suppliers) foreach (var item in suppliers)

@ -28,10 +28,13 @@ namespace EFCore.Jet.Integration.Test.Model28
.IsRequired() .IsRequired()
; ;
// Is required must be inserted in foreign key field if there is one
/*
modelBuilder.Entity<AdImage>() modelBuilder.Entity<AdImage>()
.Property(x => x.Advertisement) .Property(x => x.Advertisement)
.IsRequired() .IsRequired()
; ;
*/
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);

@ -98,7 +98,7 @@ namespace EFCore.Jet.Integration.Test.Model56_SkipTake
for (int i = 0; i < entities.Count - 1; i++) for (int i = 0; i < entities.Count - 1; i++)
{ {
Entity entity = entities[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, A,
B, B,
C Caa
} }
public enum DataCaptureActivityType public enum DataCaptureActivityType

@ -9,7 +9,8 @@ namespace EFCore.Jet.Integration.Test.Model59_StackOverflow_TPT_TPH
public void Run() 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(); 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() public static DbConnection GetJetConnection()
{ {
@ -116,7 +120,7 @@ namespace System.Data.Jet.Test
//oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0"; //oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
//oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb"; //oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb";
oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0"; oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
oleDbConnectionStringBuilder.DataSource = @".\Empty.accdb"; oleDbConnectionStringBuilder.DataSource = GetTestDirectory() + "\\Empty.accdb";
return oleDbConnectionStringBuilder.ToString(); return oleDbConnectionStringBuilder.ToString();
} }
@ -151,6 +155,17 @@ namespace System.Data.Jet.Test
} }
public static DbDataReader Execute(DbConnection connection, string query) 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[] sqlParts = query.Split('\n');
string executionMethod = sqlParts[0]; string executionMethod = sqlParts[0];
@ -159,6 +174,8 @@ namespace System.Data.Jet.Test
sql += sqlParts[i] + "\r\n"; sql += sqlParts[i] + "\r\n";
var command = connection.CreateCommand(); var command = connection.CreateCommand();
if (transaction != null)
command.Transaction = transaction;
command.CommandText = sql; command.CommandText = sql;
@ -174,6 +191,5 @@ namespace System.Data.Jet.Test
else else
throw new Exception("Unknown execution method " + executionMethod); throw new Exception("Unknown execution method " + executionMethod);
} }
} }
} }

@ -62,22 +62,43 @@ namespace System.Data.Jet.Test.Properties {
/// <summary> /// <summary>
/// Looks up a localized string similar to ExecuteNonQuery========== /// Looks up a localized string similar to ExecuteNonQuery==========
///CREATE TABLE [Standards] ( ///CREATE TABLE [CheckIfTableExistsTable] (
/// [StandardId] int NOT NULL IDENTITY, /// [StudentId] int NOT NULL IDENTITY,
/// [Description] text NULL, /// [Notes] text NULL,
/// [StandardName] varchar(255) NULL, /// [StudentName] varchar(50) NOT NULL,
/// CONSTRAINT [PK_Standards] PRIMARY KEY ([StandardId]) /// 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========== ///ExecuteDbDataReader==========
///INSERT INTO [Students] ([Notes], [StandardId], [StudentName]) ///INSERT INTO [Students] ([Notes], [StudentName])
///VALUES (null, null, &apos;Student to update&apos;); ///VALUES (null, &apos;Student to update&apos;);
///SELECT [StudentId] ///SELECT [StudentId]
///FROM [Students] ///FROM [Students]
///WHERE 1 = 1 AND [StudentId] = @@identity; ///WHERE 1 = 1 AND [StudentId] = @@identity;
/// ///
///ExecuteDbDataReader========== ///ExecuteDbDataReader==========
///SELECT TOP 1 [s].[StudentId], [s] [rest of string was truncated]&quot;;. ///SELECT TOP 1 [s].[StudentId], [s].[Notes], [s].[StudentName] /// [rest of string was truncated]&quot;;.
/// </summary> /// </summary>
internal static string UpdateTestQueries { internal static string UpdateTestQueries {
get { get {

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

@ -26,3 +26,7 @@ ExecuteDbDataReader==========
SELECT COUNT(*) SELECT COUNT(*)
FROM [Students] AS [s] 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" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DdlTest.cs" />
<Compile Include="Helpers.cs" /> <Compile Include="Helpers.cs" />
<Compile Include="JetStoreSchemaDefinitionRetrieveTest.cs" /> <Compile Include="JetStoreSchemaDefinitionRetrieveTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@ -76,6 +77,7 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="AssemblyInitialization.cs" />
<Compile Include="UpdateTest.cs" /> <Compile Include="UpdateTest.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -101,6 +103,9 @@
<ItemGroup> <ItemGroup>
<None Include="Resources\UpdateTestQueries.txt" /> <None Include="Resources\UpdateTestQueries.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="Resources\CheckIfTableExistsTestQueries.txt" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

@ -9,29 +9,65 @@ namespace System.Data.Jet.Test
{ {
[TestMethod] [TestMethod]
public void UpdateTestRun() 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; JetConfiguration.ShowSqlStatements = true;
var queries = Helpers.GetQueries(Properties.Resources.UpdateTestQueries); var queries = Helpers.GetQueries(Properties.Resources.UpdateTestQueries);
Assert.AreEqual(5, queries.Length); Assert.AreEqual(6, queries.Length);
using (var connection = Helpers.GetJetConnection()) using (var connection = Helpers.GetJetConnection())
{ {
connection.Open(); connection.Open();
DbDataReader reader; 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]; string query = queries[index];
reader = Helpers.Execute(connection, query); reader = Helpers.Execute(connection, transaction, query);
if (reader != null) if (reader != null)
reader.Dispose(); reader.Dispose();
transaction.Commit();
} }
reader = Helpers.Execute(connection, queries[4]); reader = Helpers.Execute(connection, queries[4]);
reader.Read(); reader.Read();
Assert.AreEqual(1, reader.GetInt32(0)); Assert.AreEqual(1, reader.GetInt32(0));
reader.Dispose(); reader.Dispose();
Helpers.Execute(connection, queries[5]);
} }
} }
} }
} }

Loading…
Cancel
Save