using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Data.Linq;
using System.Data.SqlClient;
using Technewlogic.Stasy.Test.Model;
using Technewlogic.Stasy.SyncProvider;
using Technewlogic.Stasy.Framework.Proxy;
using Technewlogic.Stasy.Framework.MetaModel;
using Technewlogic.Stasy.SyncProvider.SqlCE;
using System.IO;
namespace Technewlogic.Stasy.Test.ProviderTests
{
[TestFixture]
public class SqlCE
{
private const string _path = "Test.sdf";
private Engine<CrmContext> _engine;
private CrmContext _context;
private SqlCESyncProvider _syncProvider;
//private OrderTypeCompositor _standardCompositor;
//private OrderType _lowPriority;
//private OrderType _highPriority;
//private Customer _sundk;
//private Customer _pizzaInder;
//private Order _cmms;
//private Order _timeFlies;
//private Order _billingSystem;
//private Material _hardware;
//private Material _pizzaOfen;
//private Material _mehl;
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
if (File.Exists(_path))
File.Delete(_path);
_syncProvider = new SqlCESyncProvider(_path);
_context = new CrmContext();
_engine = EngineFactory.CreateEngine(_syncProvider, _context);
}
[SetUp]
public void SetUp()
{
// TODO
//throw new NotImplementedException();
//_linqContext.Customers.DeleteAllOnSubmit(_linqContext.Customers);
//_linqContext.Materials.DeleteAllOnSubmit(_linqContext.Materials);
//_linqContext.Orders.DeleteAllOnSubmit(_linqContext.Orders);
//_linqContext.OrderTypes.DeleteAllOnSubmit(_linqContext.OrderTypes);
//_linqContext.OrderTypeCompositors.DeleteAllOnSubmit(_linqContext.OrderTypeCompositors);
//_linqContext.SubmitChanges();
//#region Create Data
//#region OrderTypeCompositors
//_standardCompositor = new OrderTypeCompositor()
//{
// Name = "StandardCompositor"
//};
//_linqContext.OrderTypeCompositors.InsertOnSubmit(_standardCompositor);
//#endregion
//#region OrderTypes
//_lowPriority = new OrderType()
//{
// Name = "LowPriority",
// Priority = 1,
// Version = 1,
// _orderTypeCompositorKey = _standardCompositor._key
//};
//_linqContext.OrderTypes.InsertOnSubmit(_lowPriority);
//_highPriority = new OrderType()
//{
// Name = "HighPriority",
// Priority = 10,
// Version = 1,
// _orderTypeCompositorKey = _standardCompositor._key
//};
//_linqContext.OrderTypes.InsertOnSubmit(_highPriority);
//#endregion
//#region Customers
//_sundk = new Customer()
//{
// AccountNumber = 1,
// Name = "S&K Anlagentechnik"
//};
//_linqContext.Customers.InsertOnSubmit(_sundk);
//_pizzaInder = new Customer()
//{
// AccountNumber = 2,
// Name = "Pizza Express"
//};
//_linqContext.Customers.InsertOnSubmit(_pizzaInder);
//#endregion
//#region Orders
//_cmms = new Order()
//{
// _customerKey = _sundk._key,
// OrderID = "a-4711",
// _orderTypeKey = _highPriority._key,
// Price = 15000.0f,
// ShippingDate = DateTime.Now.AddYears(5).Date
//};
//_linqContext.Orders.InsertOnSubmit(_cmms);
//_timeFlies = new Order()
//{
// _customerKey = _sundk._key,
// OrderID = "a-0815",
// _orderTypeKey = _highPriority._key,
// Price = 1500.0f,
// ShippingDate = DateTime.Now.AddMonths(-3).Date
//};
//_linqContext.Orders.InsertOnSubmit(_timeFlies);
//_billingSystem = new Order()
//{
// _customerKey = _pizzaInder._key,
// OrderID = "ind-123",
// _orderTypeKey = _lowPriority._key,
// Price = 5.0f,
// ShippingDate = DateTime.Now.Date
//};
//_linqContext.Orders.InsertOnSubmit(_billingSystem);
//#endregion
//#region Materials
//_hardware = new Material()
//{
// DefinitionID = "HW-01",
// Name = "Ganz langsamer Server",
// _orderKey = _cmms._key
//};
//_linqContext.Materials.InsertOnSubmit(_hardware);
//_pizzaOfen = new Material()
//{
// DefinitionID = "OF-01",
// Name = "Pizzaofen",
// _orderKey = _billingSystem._key
//};
//_linqContext.Materials.InsertOnSubmit(_pizzaOfen);
//_mehl = new Material()
//{
// DefinitionID = "M-01",
// Name = "Mehl (minderwertig)",
// _orderKey = _billingSystem._key
//};
//_linqContext.Materials.InsertOnSubmit(_mehl);
//#endregion
//_linqContext.SubmitChanges();
//#endregion
//_crmContext = new CrmContext(new LinqToSqlSyncProvider<LinqToSqlContext>());
}
// TODO: Serialisierung von Properties (private, automatic, in baseclass, etc.)
[Test]
public void Dummy()
{
var newCustomerName = "Test Customer";
var newCustomer = _engine.CreateInstance<Customer>();
newCustomer.Name = newCustomerName;
newCustomer.AccountNumber = 123;
_context.Customers.Add(newCustomer);
_engine.Persist();
_syncProvider.Close();
var newSyncProvider = new SqlCESyncProvider(_path);
var newContext = new CrmContext();
var newEngine = EngineFactory.CreateEngine(newSyncProvider, newContext);
var checkNewCustomer = newContext.Customers
.Single(it => it.Name == newCustomerName);
}
}
}