本文整理汇总了C#中UnitOfWork.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.Complete方法的具体用法?C# UnitOfWork.Complete怎么用?C# UnitOfWork.Complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldProvideDifferentWaysOfComplete
public virtual void ShouldProvideDifferentWaysOfComplete()
{
using (var uow = new UnitOfWork(source))
{
Awaken(uow);
uow.Complete(
() =>
{
session.Received(0).Complete();
return "test";
}).Should().Be("test");
uow.Complete(
uow2 =>
{
// ReSharper disable AccessToDisposedClosure
uow2.Should().Be.SameInstanceAs(uow);
// ReSharper restore AccessToDisposedClosure
return "test2";
}).Should().Be("test2");
uow.Complete(100).Should().Be(100);
uow.Complete();
}
session.Received(1).Complete();
}
示例2: Add_Seller_To_Data_Store
public void Add_Seller_To_Data_Store()
{
//Arrange
using (var bc = new UnitOfWork())
{
var seller = new Seller
{
FirstName = "Michał",
LastName = "Rakel",
BankName = "mBank",
BankAccountNumber = "32 3245 5456 5435 3242 5456 1296",
NIP = "3234326576",
Address = new Address
{
City = "Kraków",
StreetAddress = "ul. Kredki 5/8a",
ZipCode = "31-063"
}
};
//Act
bc.People.Add(seller);
bc.Complete();
}
using (var bc = new UnitOfWork())
{
//Verify
bool exists = bc.People.GetBasicSellersData().Any();
Assert.IsTrue(exists);
}
}
示例3: Main
static void Main(string[] args)
{
using (var unitOfWork = new UnitOfWork(new NorthwindEntities()))
{
// Example 1 : Get single customer
var customer = unitOfWork.Customers.Get("Wolza");
// Example 2 : Get specific customers
var customers = unitOfWork.Customers.GetRecentCustomers(5);
// Example 3 : Remove customer and complete unit of work
unitOfWork.Customers.Remove(customer);
unitOfWork.Complete();
}
}
示例4: ActionShouldBeFilteredByType
public void ActionShouldBeFilteredByType()
{
var resolved = 0;
var called = 0;
var originalSettigs = new TypedHandlingSettings<SystemChecked>(
() =>
{
resolved++;
return new SpecEventHandler<SystemChecked>(ev => { called++; });
},
priority: 99);
var settigs = new DeferredHandlingSettings(originalSettigs, DelayUntil.PreCompleted);
using (var uow = new UnitOfWork())
{
settigs.Action(new object());
settigs.Action(new object());
resolved.Should().Be(0);
called.Should().Be(0);
uow.Complete();
resolved.Should().Be(0);
called.Should().Be(0);
}
resolved.Should().Be(0);
called.Should().Be(0);
using (var uow = new UnitOfWork())
{
settigs.Action(new SystemChecked());
settigs.Action(new SystemChecked());
resolved.Should().Be(0);
called.Should().Be(0);
uow.Complete();
resolved.Should().Be(2);
called.Should().Be(2);
}
resolved.Should().Be(2);
called.Should().Be(2);
}
示例5: Add_Invoice_To_Data_Store
public void Add_Invoice_To_Data_Store()
{
//Arrange
using (var bc = new UnitOfWork())
{
var newInvoice = new Invoice
{
IssueDate = new DateTime(2015, 5, 6),
Number = "1/2015",
PaymentMethod = PaymentMethod.Transfer,
SaleDate = new DateTime(2015, 5, 6),
PaymentDetails = new List<PaymentDetail>
{
new PaymentDetail
{
Description = "Czynsz za lokal ul. Marsa 3 maj",
MeasureUnit = "szt.",
PricePerUnit = 5300,
Quantity = 1
}
},
Buyer = bc.DataContext.People.OfType<Buyer>().First(),
Seller = bc.DataContext.People.OfType<Seller>().First(),
};
//Act
bc.Payments.Add(newInvoice);
bc.Complete();
}
using (var bc = new UnitOfWork())
{
bool exists = bc.DataContext.Payments.Any();
//Verify
Assert.IsTrue(exists);
}
}
示例6: BatchedEventsHandlersShouldBeUnique
public void BatchedEventsHandlersShouldBeUnique()
{
Events.OfType<SystemChecked>().BatchUntilCompleted();
Events.OfType<SystemChecked>().BatchUntilCompleted();
Events.OfType<SystemChecked>().BatchUntilCompleted();
Events.OfType<SystemChecked>().BatchUntilPreCompleted();
Events.OfType<SystemChecked>().BatchUntilPreCompleted();
Events.OfType<SystemChecked>().BatchUntilPreCompleted();
Events.OfType<SystemChecked>().BatchUntilFinished();
Events.OfType<SystemChecked>().BatchUntilFinished();
Events.OfType<SystemChecked>().BatchUntilFinished();
var called = 0;
using (Events.Subscribe<IEventBatch<SystemChecked>>(
ev =>
{
// ReSharper disable once AccessToModifiedClosure
called++;
}))
{
using (var uow = new UnitOfWork())
{
Events.Publish(new SystemChecked());
Events.Publish(new SystemChecked());
Events.Publish(new SystemChecked());
called.Should().Be(0);
uow.Complete();
called.Should().Be(2);
}
called.Should().Be(3);
}
}
示例7: ShouldThrowExceptionIfCompleteCalledAfterDispose
public virtual void ShouldThrowExceptionIfCompleteCalledAfterDispose()
{
Assert.That(
() =>
{
var uow = new UnitOfWork(source);
Awaken(uow);
((IDisposable)uow).Dispose();
uow.Complete();
},
Throws.Exception.With.Message.EqualTo("Unit of work has already been disposed(with success - 'False'), so it is not usable anymore."));
session.Received(1).Dispose();
session.Received(0).Complete();
}
示例8: ShouldThrowExceptionIfDeleteCalledAfterComplete
public virtual void ShouldThrowExceptionIfDeleteCalledAfterComplete()
{
Assert.That(
() =>
{
var uow = new UnitOfWork(source);
uow.Complete();
((IDisposable)uow).Dispose();
uow.MarkAsDeleted(new Customer());
},
Throws.Exception.With.Message.EqualTo(string.Format(InteractAfterComplete, true)));
Assert.That(
() =>
{
using (var uow = new UnitOfWork(source))
{
uow.Complete();
uow.MarkAsDeleted(new Customer());
}
},
Throws.Exception.With.Message.EqualTo(string.Format(InteractAfterComplete, true)));
Assert.That(
() =>
{
using (var uow = new UnitOfWork(source))
{
uow.Complete();
new Customer().AsDeletedIn(uow);
}
},
Throws.Exception.With.Message.EqualTo(string.Format(InteractAfterComplete, true)));
}
示例9: ShouldCallRealCompleteOnlyOnce
public virtual void ShouldCallRealCompleteOnlyOnce()
{
using (var uow = new UnitOfWork(source))
{
Awaken(uow);
uow.Complete();
uow.Complete();
uow.Complete(100);
uow.Complete(() => 100);
uow.Complete(u => 100);
}
session.Received(1).Complete();
}
示例10: FindInvoice_Returns_Invoice_From_Data_Store
public void FindInvoice_Returns_Invoice_From_Data_Store()
{
//Arrange
const string invoiceNumber = "1/2015";
int sellerId;
using (var bc = new UnitOfWork())
{
var seller = bc.DataContext.People.OfType<Seller>().First();
sellerId = seller.ID;
var newInvoice = new Invoice
{
IssueDate = new DateTime(2015, 5, 6),
Number = invoiceNumber,
PaymentMethod = PaymentMethod.Transfer,
SaleDate = new DateTime(2015, 5, 6),
PaymentDetails = new List<PaymentDetail>
{
new PaymentDetail
{
Description = "Czynsz za lokal ul. Marsa 3 maj",
MeasureUnit = "szt.",
PricePerUnit = 5300,
Quantity = 1
}
},
Buyer = bc.DataContext.People.OfType<Buyer>().First(),
Seller = bc.DataContext.People.OfType<Seller>().First(),
};
//Act
bc.Payments.Add(newInvoice);
bc.Complete();
}
using (var bc = new UnitOfWork())
{
var invoice = bc.Payments.FindInvoice(i=>i.Number==invoiceNumber && i.Seller.ID==sellerId);
//Verify
Assert.IsNotNull(invoice);
}
}
示例11: TestInitialize
public override void TestInitialize()
{
base.TestInitialize();
using (var bc = new UnitOfWork())
{
var newSeller = new Seller
{
FirstName = "Michał",
LastName = "Rakel",
BankName = "mBank",
BankAccountNumber = "32 3245 5456 5435 3242 5456 1296",
NIP = "3234326576",
Address = new Address
{
City = "Kraków",
StreetAddress = "ul. Kredki 5/8a",
ZipCode = "31-063"
}
};
bc.People.Add(newSeller);
var newBuyer = new Buyer
{
FirstName = "Michał",
LastName = "Braik",
CompanyName = "Ven",
NIP = "562504040",
Address = new Address
{
City = "Warszawa",
StreetAddress = "Tor wyścigowy 54",
ZipCode = "42-232"
}
};
newSeller.Buyers.Add(newBuyer);
bc.Complete();
}
}
示例12: GetShortenedPeople_Returns_Data
public void GetShortenedPeople_Returns_Data()
{
//Arrange
using (var bc = new UnitOfWork())
{
var seller = new Seller
{
FirstName = "Michał",
LastName = "Rakel",
BankName = "mBank",
BankAccountNumber = "32 3245 5456 5435 3242 5456 1296",
NIP = "3234326576",
Address = new Address
{
City = "Kraków",
StreetAddress = "ul. Kredki 5/8a",
ZipCode = "31-063"
}
};
bc.People.Add(seller);
var seller2 = new Seller
{
FirstName = "Paweł",
LastName = "Rakel",
BankName = "mBank",
BankAccountNumber = "43 3245 5456 5435 3242 5456 1296",
NIP = "3265326576",
Address = new Address
{
City = "Warszawa",
StreetAddress = "ul. Kredki 5/8a",
ZipCode = "31-063"
}
};
bc.People.Add(seller2);
bc.Complete();
//Act
var list = bc.People.GetBasicSellersData();
//Verify
Assert.IsTrue(list.Count() == 2);
}
}
示例13: OriginalActionShouldBeCalledWhenUnitOfWorkScopeFinishedSuccessfullyIfAppropriateStageIsSpecified
public void OriginalActionShouldBeCalledWhenUnitOfWorkScopeFinishedSuccessfullyIfAppropriateStageIsSpecified()
{
var resolved = 0;
var called = 0;
var originalSettigs = new TypedHandlingSettings<SystemChecked>(
() =>
{
// ReSharper disable once AccessToModifiedClosure
resolved++;
// ReSharper disable once AccessToModifiedClosure
return new SpecEventHandler<SystemChecked>(ev => { called++; });
},
priority: 99);
var settigs = new DeferredHandlingSettings(originalSettigs, DelayUntil.Finished);
using (var uow = new UnitOfWork())
{
settigs.Action(new SystemChecked());
settigs.Action(new SystemChecked());
resolved.Should().Be(0);
called.Should().Be(0);
uow.Complete();
resolved.Should().Be(0);
called.Should().Be(0);
}
resolved.Should().Be(2);
called.Should().Be(2);
resolved = 0;
called = 0;
try
{
using (var uow = new UnitOfWork("test"))
{
// ReSharper disable once UnusedVariable
var session = ((IWrapper)uow).WrappedObject;
settigs.Action(new SystemChecked());
settigs.Action(new SystemChecked());
resolved.Should().Be(0);
called.Should().Be(0);
uow.Complete();
}
}
catch (NotSupportedException)
{
}
resolved.Should().Be(0);
called.Should().Be(0);
}
示例14: DifferentSourcesShouldCreateSeparateScopeHierarchy
public virtual void DifferentSourcesShouldCreateSeparateScopeHierarchy()
{
AssertThatContextCountEqualTo(0);
using (new UnitOfWork(source1))
{
AssertThatContextCountEqualTo(1);
using (new UnitOfWork(source1, Require.New))
{
AssertThatContextCountEqualTo(2);
using (new UnitOfWork(source2))
{
AssertThatContextCountEqualTo(3);
using (new UnitOfWork(source1))
{
AssertThatContextCountEqualTo(3);
}
using (new UnitOfWork(source2))
{
using (new UnitOfWork(source1))
{
using (new UnitOfWork(source2))
{
AssertThatContextCountEqualTo(3);
}
AssertThatContextCountEqualTo(3);
}
AssertThatContextCountEqualTo(3);
}
AssertThatContextCountEqualTo(3);
using (new UnitOfWork(source2, Require.New))
{
AssertThatContextCountEqualTo(4);
}
AssertThatContextCountEqualTo(3);
}
AssertThatContextCountEqualTo(2);
}
AssertThatContextCountEqualTo(1);
}
AssertThatSupervisorDestroyed();
AssertThatContextCountEqualTo(0);
using (var uowla = new UnitOfWork(source1))
{
AssertThatContextCountEqualTo(1);
using (var uowlai2 = new UnitOfWork(source1))
{
AssertThatContextCountEqualTo(1);
using (new UnitOfWork(source2))
{
AssertThatContextCountEqualTo(2);
}
AssertThatContextCountEqualTo(1);
uowlai2.Complete();
}
AssertThatContextCountEqualTo(1);
uowla.Complete();
}
AssertThatSupervisorDestroyed();
}
示例15: EventBatchShouldBePublishedWhenUnitOfWorkScopeFinishedSuccessfullyIfAppropriateStageIsSpecified
public void EventBatchShouldBePublishedWhenUnitOfWorkScopeFinishedSuccessfullyIfAppropriateStageIsSpecified()
{
var called = 0;
IEventBatch<SystemChecked> batch = null;
using (Events.Subscribe<IEventBatch<SystemChecked>>(
ev =>
{
// ReSharper disable once AccessToModifiedClosure
called++;
batch = ev;
}))
{
var settigs = new BatchedHandlingSettings(typeof(SystemChecked), DelayUntil.Finished, 1000);
using (var uow = new UnitOfWork())
{
settigs.Action(new SystemChecked());
settigs.Action(new SystemChecked());
called.Should().Be(0);
batch.Should().Be.Null();
uow.Complete();
called.Should().Be(0);
batch.Should().Be.Null();
}
called.Should().Be(1);
batch.Should().Not.Be.Null();
batch.Events.Should().Have.Count.EqualTo(2);
called = 0;
batch = null;
try
{
using (var uow = new UnitOfWork("test"))
{
// ReSharper disable once UnusedVariable
var session = ((IWrapper)uow).WrappedObject;
settigs.Action(new SystemChecked());
settigs.Action(new SystemChecked());
called.Should().Be(0);
batch.Should().Be.Null();
uow.Complete();
}
}
catch (NotSupportedException)
{
}
called.Should().Be(0);
batch.Should().Be.Null();
}
}