public void TestAddOrUpdate() { //add DateTime dtRegistration = DateTime.Now.Date.AddDays(-2).AddHours(12.50); User user = new User("Jake", 27, dtRegistration); userRepo.AddOrUpdate(user); unitOfwork.Save(); User userInDb = userRepo.FindByName("Jake"); Assert.AreEqual(user.Name, userInDb.Name); //update userInDb.Age = 29; userRepo.AddOrUpdate(userInDb); //add categories to db foreach (var item in categories) { categoryRepo.AddOrUpdate(item); } unitOfwork.Save(); //assign the category to products and add to db foreach (var item in products) { if (item.Name.Contains("Sumsung")) { item.Category = categories[1]; } else { item.Category = categories[0]; } productRepo.AddOrUpdate(item); } unitOfwork.Save(); //add products to stores Store rozetkaStore = stores[0]; rozetkaStore.Products.Add(products[0]); rozetkaStore.Products.Add(products[2]); rozetkaStore.Products.Add(products[1]); Store mobidickStore = stores[1]; mobidickStore.Products.Add(products[0]); mobidickStore.Products.Add(products[3]); mobidickStore.Products.Add(products[2]); //add stores to db storeRepo.AddOrUpdate(rozetkaStore); storeRepo.AddOrUpdate(mobidickStore); unitOfwork.Save(); unitOfwork.Dispose(); }
protected override void Dispose(bool disposing) { IUnitOfWork database = new EFUnitOfWork(); database.Dispose(); base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { _unitOfWork.Dispose(); } base.Dispose(disposing); }
static void Main(string[] args) { EFUnitOfWork test = new EFUnitOfWork("CallCenterDb"); foreach (var item in test.PhoneCalls.GetAll(null, SortOrder.Asc)) { //Console.WriteLine(String.Format("Id = {0}, Duration = {1}", item.Id, item.DurationSeconds)); } test.Dispose(); }
public virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { uof.Dispose(); } this.disposed = true; } }
public void Dispose_disposes_all_open_IEFSession_instances() { var resolver = MockRepository.GenerateMock<IEFSessionResolver>(); resolver.Stub(x => x.GetSessionKeyFor<string>()).Return(Guid.NewGuid()); resolver.Stub(x => x.GetSessionKeyFor<int>()).Return(Guid.NewGuid()); resolver.Stub(x => x.OpenSessionFor<string>()).Return(MockRepository.GenerateStub<IEFSession>()); resolver.Stub(x => x.OpenSessionFor<int>()).Return(MockRepository.GenerateStub<IEFSession>()); var unitOfWork = new EFUnitOfWork(resolver); unitOfWork.GetSession<string>(); unitOfWork.GetSession<int>(); unitOfWork.Dispose(); resolver.OpenSessionFor<string>().AssertWasCalled(x => x.Dispose()); resolver.OpenSessionFor<int>().AssertWasCalled(x => x.Dispose()); }
private void StartTask(object sender, FileSystemEventArgs e) { Task task = new Task(() => { var orders = _parser.ManualParse(e.FullPath); foreach (var order in orders) { Thread.Sleep(50); IUnitOfWork uow = new EFUnitOfWork(); IOrderService service = new OrderService(uow); try { lock (_lockObj) { if (!_cancelToken.IsCancellationRequested) { service.AddOrder(order); _logger.Info($"{order.Product} added from file {e.Name}\t Task - {Task.CurrentId}"); } else { _logger.Info("Task stopped"); break; } } } catch (Exception) { _logger.Info("Can't add record to database"); throw new InvalidOperationException("Can't add record to database"); } finally { service.Dispose(); uow.Dispose(); } } if (!_cancelToken.IsCancellationRequested) { _directoryHandler.Move(e.FullPath, e.Name); } }, _cancelToken.Token); task.Start(_taskScheduler); }
public void Dispose_disposes_all_open_IEFSession_instances() { var resolver = MockRepository.GenerateMock <IEFSessionResolver>(); resolver.Stub(x => x.GetSessionKeyFor <string>()).Return(Guid.NewGuid()); resolver.Stub(x => x.GetSessionKeyFor <int>()).Return(Guid.NewGuid()); resolver.Stub(x => x.OpenSessionFor <string>()).Return(MockRepository.GenerateStub <IEFSession>()); resolver.Stub(x => x.OpenSessionFor <int>()).Return(MockRepository.GenerateStub <IEFSession>()); var unitOfWork = new EFUnitOfWork(resolver); unitOfWork.GetSession <string>(); unitOfWork.GetSession <int>(); unitOfWork.Dispose(); resolver.OpenSessionFor <string>().AssertWasCalled(x => x.Dispose()); resolver.OpenSessionFor <int>().AssertWasCalled(x => x.Dispose()); }
public void Dispose_disposes_all_open_IEFSession_instances() { var resolver = new Mock<IEFSessionResolver>(); resolver.Setup(x => x.GetSessionKeyFor<string>()).Returns(Guid.NewGuid()); resolver.Setup(x => x.GetSessionKeyFor<int>()).Returns(Guid.NewGuid()); var session = new Mock<IEFSession>(); resolver.Setup(x => x.OpenSessionFor<string>()).Returns(session.Object); resolver.Setup(x => x.OpenSessionFor<int>()).Returns(session.Object); var unitOfWork = new EFUnitOfWork(resolver.Object); unitOfWork.GetSession<string>(); unitOfWork.GetSession<int>(); unitOfWork.Dispose(); resolver.Object.OpenSessionFor<string>(); session.Verify(x => x.Dispose()); session.Verify(x => x.Dispose()); }
static void Main(string[] args) { System.Console.WriteLine("###NHibernate###"); NHUnitOfWork uowNH = new NHUnitOfWork(); CustomerService customerServiceNH = new CustomerService(uowNH, new NHRepository <Customer>(uowNH)); try { CustomerDto customerDto = customerServiceNH.Add("NH First Name", Guid.NewGuid().ToString().Substring(0, 7)); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } finally { uowNH.Dispose(); } System.Console.WriteLine("###Entity Framework###"); EFUnitOfWork uowEF = new EFUnitOfWork(); CustomerService customerServiceEF = new CustomerService(uowEF, new EFRepository <Customer>(uowEF)); try { CustomerDto customerDto = customerServiceEF.Add("EF First Name", Guid.NewGuid().ToString().Substring(0, 7)); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } finally { uowEF.Dispose(); } }
public void Dispose() { _database.Dispose(); }
public void TestCleanup() { _dbContext = null; _uow.Dispose(); }
public void TestCleanup() { _uow.Dispose(); }
public void Dispose() { UnitOfWork?.Dispose(); Context?.Dispose(); _Factory?.Dispose(); }
public void Dispose() { uow.Dispose(); }
public void Dispose() { _UnitOfWork?.Dispose(); _Context?.Dispose(); }