本文整理汇总了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; });
}
示例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);
}
示例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);
}
示例4: TestConnection
public void TestConnection()
{
// Arrange
var unitOfWork = new UnitOfWork();
// Act
unitOfWork.Context<SampleContext>().Users.Any();
// Assert
unitOfWork.Dispose();
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例9: Dispose_Context
public void Dispose_Context()
{
TestingContext context = Substitute.For<TestingContext>();
UnitOfWork unitOfWork = new UnitOfWork(context);
unitOfWork.Dispose();
context.Received().Dispose();
}
示例10: Dispose_DiposesContext
public void Dispose_DiposesContext()
{
DbContext context = Substitute.For<DbContext>();
UnitOfWork unitOfWork = new UnitOfWork(context);
unitOfWork.Dispose();
context.Received().Dispose();
}
示例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;
}