本文整理汇总了C#中Persistence.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# Persistence.Commit方法的具体用法?C# Persistence.Commit怎么用?C# Persistence.Commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Persistence
的用法示例。
在下文中一共展示了Persistence.Commit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Commit_AzureBlobThrowsException_ShouldRollbackAllAndLog
public void Commit_AzureBlobThrowsException_ShouldRollbackAllAndLog(
[Frozen]Mock<ILogger> logger,
[Frozen]Mock<IEntityFrameworkContext> efContext,
[Frozen]Mock<IAzureQueueContext> aqContext,
[Frozen]Mock<IAzureTableContext> atContext,
[Frozen]Mock<IAzureBlobContext> abContext,
Persistence.UnitOfWork uow)
{
// Arrange
var exception = new Exception("Exception");
abContext.Setup(c => c.SaveChanges()).Throws(exception);
// Act
var assertException = Assert.Throws<Exception>(() => uow.Commit());
assertException.Message.Should().Be("Exception");
// Assert
logger.Verify(l => l.Log("Exception caught: Exception"), Times.Once);
abContext.Verify(c => c.SaveChanges(), Times.Once);
atContext.Verify(c => c.SaveChanges(), Times.Never);
aqContext.Verify(c => c.SaveChanges(), Times.Never);
efContext.Verify(c => c.SaveChanges(), Times.Never);
logger.Verify(l => l.Log("Azure Blob context commited."), Times.Never);
logger.Verify(l => l.Log("Azure Table context commited."), Times.Never);
logger.Verify(l => l.Log("Azure Queue context commited."), Times.Never);
logger.Verify(l => l.Log("Entity Framework context commited."), Times.Never);
aqContext.Verify(c => c.Rollback(), Times.Once);
atContext.Verify(c => c.Rollback(), Times.Once);
abContext.Verify(c => c.Rollback(), Times.Once);
logger.Verify(l => l.Log("Executing Azure Queue context rollback..."), Times.Once);
logger.Verify(l => l.Log("Executing Azure Table context rollback..."), Times.Once);
logger.Verify(l => l.Log("Executing Azure Blob context rollback..."), Times.Once);
}
示例2: Commit_Success_ShouldCommitAllAndLog
public void Commit_Success_ShouldCommitAllAndLog(
[Frozen]Mock<ILogger> logger,
[Frozen]Mock<IEntityFrameworkContext> efContext,
[Frozen]Mock<IAzureQueueContext> aqContext,
[Frozen]Mock<IAzureTableContext> atContext,
[Frozen]Mock<IAzureBlobContext> abContext,
Persistence.UnitOfWork uow)
{
// Arrange
// Act
uow.Commit();
// Assert
efContext.Verify(c => c.SaveChanges(), Times.Once);
aqContext.Verify(c => c.SaveChanges(), Times.Once);
atContext.Verify(c => c.SaveChanges(), Times.Once);
abContext.Verify(c => c.SaveChanges(), Times.Once);
logger.Verify(l => l.Log("Azure Blob context commited."), Times.Once);
logger.Verify(l => l.Log("Azure Table context commited."), Times.Once);
logger.Verify(l => l.Log("Azure Queue context commited."), Times.Once);
logger.Verify(l => l.Log("Entity Framework context commited."), Times.Once);
}