当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.Dispose方法代码示例

本文整理汇总了C#中UnitOfWork.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Dispose方法的具体用法?C# UnitOfWork.Dispose怎么用?C# UnitOfWork.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnitOfWork的用法示例。


在下文中一共展示了UnitOfWork.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Dispose_Then_throw_exception_on_DbContext_get

        public void Dispose_Then_throw_exception_on_DbContext_get()
        {
            var uow1 = new UnitOfWork(_dbContextFactoryMock.Object);
            uow1.Dispose();

            Assert.Throws<ObjectDisposedException>(() => { var dbContext = uow1.DbContext; });
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:7,代码来源:UnitOfWorkTest.cs

示例2: PhonebooksGridView_RowInserting

        protected void PhonebooksGridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            ASPxGridView grid = sender as ASPxGridView;

            if (CustomerUtilities.IsLoggedIn() == true)
            {
                using (var uow = new UnitOfWork())
                {
                    Phonebook phonebook = new Phonebook(uow);
                    SetPhonebookValues(phonebook, e.NewValues);
                    phonebook.Customer = uow.GetObjectByKey<Customer>(CustomerUtilities.CurrentCustomer().Oid);

                    ValidationResult validation = new PhonebookValidator().Validate(phonebook);

                    if (validation.IsValid)
                    {
                        uow.CommitChanges();
                    }
                    else
                    {
                        e.Cancel = true;
                        uow.Dispose();
                    }
                }
            }
            else
            {
                Response.Redirect(UrlManager.Root);
            }

            EndEditing(grid, e);
        }
开发者ID:a1exb1,项目名称:farlon-data-consolidator-dotnet,代码行数:32,代码来源:Manage.aspx.cs

示例3: Dispose_Then_calls_DbContext_Dispose

        public void Dispose_Then_calls_DbContext_Dispose()
        {
            var uow = new UnitOfWork(_dbContextFactoryMock.Object);

            uow.Dispose();

            _dbContextMock.Verify(x => x.Dispose(), Times.Once);
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:8,代码来源:UnitOfWorkTest.cs

示例4: TestConnection

        public void TestConnection()
        {
            // Arrange
            var unitOfWork = new UnitOfWork();

            // Act
            unitOfWork.Context<SampleContext>().Users.Any();

            // Assert
            unitOfWork.Dispose();
        }
开发者ID:LojalnaJola,项目名称:SharpProject,代码行数:11,代码来源:CreateDatabaseTests.cs

示例5: Main

        static void Main(string[] args)
        {
            //Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

            var uow = new UnitOfWork(new MyContext());
            var clientRepository = new ClientRepository(uow);

            CriarCliente(clientRepository);

            uow.Dispose();
            Console.ReadKey();
        }
开发者ID:pedrobenevides,项目名称:EFPlayground,代码行数:12,代码来源:Program.cs

示例6: UnitOfWork_Dispose_Test

        public void UnitOfWork_Dispose_Test()
        {
            IDataContextAsync context = new NorthwindContext();
            IUnitOfWorkAsync unitOfWork = new UnitOfWork(context);

            // opening connection
            unitOfWork.BeginTransaction();
            unitOfWork.Commit();

            // calling dispose 1st time
            unitOfWork.Dispose();
            var isDisposed = (bool) GetInstanceField(typeof (UnitOfWork), unitOfWork, "_disposed");
            Assert.IsTrue(isDisposed);

            // calling dispose 2nd time, should not throw any excpetions
            unitOfWork.Dispose();
            context.Dispose();

            // calling dispose 3rd time, should not throw any excpetions
            context.Dispose();
            unitOfWork.Dispose();
        }
开发者ID:GFoley83,项目名称:URFUnitOfWorkAndRepositoriesFramework,代码行数:22,代码来源:UnitOfWorkTests.cs

示例7: When_multiple_instances_And_disposed_Then_multiple_DbContext_instances

        public void When_multiple_instances_And_disposed_Then_multiple_DbContext_instances()
        {
            var uow1 = new UnitOfWork(_dbContextFactoryMock.Object);
            var dbContext1 = uow1.DbContext;
            uow1.Dispose();

            var dbContextMock2 = new Mock<IDbContext>();
            _dbContextFactoryMock.Setup(x => x.Create()).Returns(dbContextMock2.Object);

            var uow2 =  new UnitOfWork(_dbContextFactoryMock.Object);
            Assert.AreNotEqual(dbContext1, uow2.DbContext);
        }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:12,代码来源:UnitOfWorkTest.cs

示例8: TearDown

 public void TearDown()
 {
     //Have to dispose to make sure that it is done after every test
     //If it is not disposed DbContext maybe available between tests which is bad idea
     var uow = new UnitOfWork(_dbContextFactoryMock.Object);
     uow.Dispose();
 }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:7,代码来源:UnitOfWorkTest.cs

示例9: Dispose_Context

        public void Dispose_Context()
        {
            TestingContext context = Substitute.For<TestingContext>();
            UnitOfWork unitOfWork = new UnitOfWork(context);

            unitOfWork.Dispose();

            context.Received().Dispose();
        }
开发者ID:zarinbal,项目名称:MVC5.Template,代码行数:9,代码来源:UnitOfWorkTests.cs

示例10: Dispose_DiposesContext

        public void Dispose_DiposesContext()
        {
            DbContext context = Substitute.For<DbContext>();
            UnitOfWork unitOfWork = new UnitOfWork(context);

            unitOfWork.Dispose();

            context.Received().Dispose();
        }
开发者ID:vothlizard,项目名称:MVC.Template,代码行数:9,代码来源:UnitOfWorkTests.cs

示例11: createUnitOfWork

        /// <summary>
        /// Creates the unit of work for package data.
        /// </summary>
        /// <returns>Unit of work</returns>
        private UnitOfWork createUnitOfWork()
        {
            tempFileName = Path.GetTempFileName();
            if (PackageData != null)
                File.WriteAllBytes(tempFileName, PackageData);
            else if (File.Exists(tempFileName))
                File.Delete(tempFileName);

            var connStr = AccessConnectionProvider.GetConnectionString(tempFileName);

            // create unit of work based on temporary ms access database
            IDisposable[] disposables;
            var dataStore = XpoDefault.GetConnectionProvider(connStr, AutoCreateOption.DatabaseAndSchema,
                out disposables);
            var dataLayer = new SimpleDataLayer(XafTypesInfo.XpoTypeInfoSource.XPDictionary, dataStore);
            var result = new UnitOfWork(dataLayer, disposables);

            string errorText;
            if(!verifyMarker(result, out errorText))
            {
                result.RollbackTransaction();
                result.Dispose();
                throw new InvalidPackageDataException(errorText);
            }
            // mark object changed
            if (PackageData == null)
                OnChanged();
            return result;
        }
开发者ID:xafdelta,项目名称:xafdelta,代码行数:33,代码来源:Package.cs


注:本文中的UnitOfWork.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。