本文整理汇总了C#中Moq.MockRepository.VerifyAll方法的典型用法代码示例。如果您正苦于以下问题:C# MockRepository.VerifyAll方法的具体用法?C# MockRepository.VerifyAll怎么用?C# MockRepository.VerifyAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moq.MockRepository
的用法示例。
在下文中一共展示了MockRepository.VerifyAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Install_should_install_if_a_package_has_not_been_installed_yet
public void Install_should_install_if_a_package_has_not_been_installed_yet()
{
// Arrange
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var proj = fixture.Freeze<Project>();
var pwPkg = new ProjectWidePackage("Prig", "2.0.0", proj);
var mocks = new MockRepository(MockBehavior.Strict);
{
var m = mocks.Create<IVsPackageInstallerServices>();
m.Setup(_ => _.IsPackageInstalledEx(proj, "Prig", "2.0.0")).Returns(false);
m.Setup(_ => _.IsPackageInstalled(proj, "Prig")).Returns(false);
fixture.Inject(m);
}
{
var m = mocks.Create<IVsPackageUninstaller>();
fixture.Inject(m);
}
{
var m = mocks.Create<IVsPackageInstaller>();
m.Setup(_ => _.InstallPackage(default(string), proj, "Prig", "2.0.0", false));
fixture.Inject(m);
}
var pwInstllr = fixture.NewProjectWideInstaller();
// Act
pwInstllr.Install(pwPkg);
// Assert
mocks.VerifyAll();
}
示例2: SerializeTest
public void SerializeTest()
{
var mockRepository = new MockRepository(MockBehavior.Strict);
var mockTimeSpan = mockRepository.Create<IStringSerializer<TimeSpan>>();
var mockDaysOfWeek = mockRepository.Create<IStringSerializer<DaysOfWeek>>();
var mockIEnumerableDateTime = mockRepository.Create<IStringSerializer<IEnumerable<DateTime>>>();
var timeSpanRuleInfoSerializer = new TimeSpanRuleInfoSerializer(mockTimeSpan.Object, mockDaysOfWeek.Object,
mockIEnumerableDateTime.Object);
var expMin = new TimeSpan(150);
var expMax = new TimeSpan(250);
var expDaysOfWeek = new DaysOfWeek(DayOfWeek.Monday, DayOfWeek.Thursday);
var expDateTimes = new[] {new DateTime(1), new DateTime(100), new DateTime(500)};
var exp = new TimeSpanRuleInfo(expMin, expMax, expDaysOfWeek, expDateTimes);
mockTimeSpan.Setup(x => x.Serialize(expMin)).Returns("150").Verifiable();
mockTimeSpan.Setup(x => x.Serialize(expMax)).Returns("250").Verifiable();
mockDaysOfWeek.Setup(x => x.Serialize(expDaysOfWeek)).Returns("1,4").Verifiable();
mockIEnumerableDateTime.Setup(x => x.Serialize(expDateTimes)).Returns("datetimes").Verifiable();
Assert.AreEqual("150\x001E250\x001E1,4\x001Edatetimes", timeSpanRuleInfoSerializer.Serialize(exp));
mockRepository.VerifyAll();
}
示例3: InvokeErrorTest
public async Task InvokeErrorTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null);
var ctx = mr.Create<IOwinContext>();
var logger = mr.Create<ILog>();
var exception = new Exception();
var request = mr.Create<IOwinRequest>();
ctx.SetupGet(x => x.Request).Returns(request.Object).Verifiable();
logger.Setup(x => x.Info(It.IsAny<string>())).Throws(exception);
request.SetupGet(x => x.Method).Returns("fasefaes").Verifiable();
request.SetupGet(x => x.Uri).Returns(new Uri("http://ya.ru")).Verifiable();
request.SetupGet(x => x.RemoteIpAddress).Returns("asefasergsdrg").Verifiable();
request.SetupGet(x => x.RemotePort).Returns(11).Verifiable();
var mw = new LoggerMiddleware(next.Object, logger.Object);
try
{
await mw.Invoke(ctx.Object);
}
catch (Exception e)
{
Assert.AreEqual(exception, e);
return;
}
finally
{
mr.VerifyAll();
}
Assert.Fail();
}
示例4: InvokeTest
public async Task InvokeTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware) null);
var ctx = mr.Create<IOwinContext>();
var logger = mr.Create<ILog>();
var exception = new Exception();
logger.Setup(x => x.Fatal(It.IsAny<object>(), exception)).Verifiable();
next.Setup(x => x.Invoke(ctx.Object)).Returns(async () =>
{
await Task.Delay(1);
throw exception;
}).Verifiable();
var mw = new ExceptionHandlerMiddleware(next.Object, logger.Object);
try
{
await mw.Invoke(ctx.Object);
}
catch (Exception e)
{
Assert.AreEqual(exception, e);
}
mr.VerifyAll();
}
示例5: InvokeTest
public async Task InvokeTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null);
var ctx = mr.Create<IOwinContext>();
var cidStore = mr.Create<ICorrelationIdStore>();
var response = mr.Create<IOwinResponse>();
var hDict = new HeaderDictionary(new Dictionary<string, string[]>());
var correlationId = new CorrelationId();
next.Setup(x => x.Invoke(ctx.Object)).Returns(Task.CompletedTask).Verifiable();
ctx.SetupGet(x => x.Response).Returns(response.Object).Verifiable();
response.SetupGet(x => x.Headers).Returns(hDict).Verifiable();
cidStore.Setup(x => x.Read()).Returns(correlationId).Verifiable();
Assert.AreEqual(0, hDict.Count);
var midleware = new SetCorrelationIdHeaderMiddleware(next.Object, cidStore.Object);
await midleware.Invoke(ctx.Object);
Assert.AreEqual(1, hDict.Count);
var actual = hDict["X-CORRELATIONID"];
Assert.AreEqual(correlationId.ToString(), actual);
mr.VerifyAll();
}
示例6: NotSpecification_IsSatisfiedBy_SpecificationTrue_False
public void NotSpecification_IsSatisfiedBy_SpecificationTrue_False()
{
var mockRepository = new MockRepository(MockBehavior.Strict);
var singleSpecification = mockRepository.CreateSpecificationMock<string>(true);
var specification = new NotSpecification<string>(singleSpecification);
Assert.AreEqual(false, specification.IsSatisfiedBy("test"));
mockRepository.VerifyAll();
}
开发者ID:aescharfenberg,项目名称:neverminddreams-patterns-specification,代码行数:8,代码来源:NotSpecificationTests.cs
示例7: Ensure_valid_prices_would_be_updated
public void Ensure_valid_prices_would_be_updated()
{
//Arrange.
var currentDate = DateTime.Today;
var price = new Price(10, currentDate.AddDays(-1));
var pricesToUpdate = new List<Price>{ price };
var repo = new MockRepository(MockBehavior.Loose);
var transactionMock = repo.Create<ITransaction>();
transactionMock
.Setup(x => x.Commit())
.Verifiable();
var queryMock = repo.Create<IQuery>();
queryMock
.Setup(x => x.SetParameter("currentDate", currentDate))
.Returns(queryMock.Object);
queryMock
.Setup(x => x.List<Price>())
.Returns(pricesToUpdate);
var sessionMock = repo.Create<ISession>();
sessionMock
.Setup(x => x.BeginTransaction())
.Returns(transactionMock.Object)
.Verifiable();
sessionMock
.Setup(x => x.CreateQuery("from Price p where p.ValidFrom <= :currentDate and :currentDate <= p.ValidTo"))
.Returns(queryMock.Object);
var sessionFactoryMock = repo.Create<ISessionManager>();
sessionFactoryMock
.Setup(x => x.OpenSession())
.Returns(sessionMock.Object);
var clockMock = repo.Create<IClock>();
clockMock
.SetupGet( x => x.Today)
.Returns(currentDate);
var rateProviderMock = repo.Create<IRateProvider>();
rateProviderMock
.Setup(x => x.GetRateOn(currentDate))
.Returns(32.5m);
var task = new UpdatePricesTask(sessionFactoryMock.Object, clockMock.Object, rateProviderMock.Object);
//Act.
task.Run();
//Assert.
Assert.That(price.LocalAmount, Is.EqualTo(325));
repo.VerifyAll();
}
示例8: AssertIsSatisfiedBy
private void AssertIsSatisfiedBy(bool leftSpecificationIsSatisfiedBy, bool rightSpecificationIsSatisfiedBy,
bool expected)
{
var mockRepository = new MockRepository(MockBehavior.Strict);
var leftSpecification = mockRepository.CreateSpecificationMock<string>(leftSpecificationIsSatisfiedBy);
var rightSpecification = leftSpecificationIsSatisfiedBy
? mockRepository.CreateSpecificationMock<string>()
: mockRepository.CreateSpecificationMock<string>(rightSpecificationIsSatisfiedBy);
var specification = new OrSpecification<string>(leftSpecification, rightSpecification);
Assert.AreEqual(expected, specification.IsSatisfiedBy("test"));
mockRepository.VerifyAll();
}
开发者ID:aescharfenberg,项目名称:neverminddreams-patterns-specification,代码行数:12,代码来源:OrSpecificationTests.cs
示例9: InvokeNullTest
public async Task InvokeNullTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware) null);
var ctx = mr.Create<IOwinContext>();
var logger = mr.Create<ILog>();
next.Setup(x => x.Invoke(ctx.Object)).Returns(() => null).Verifiable();
var mw = new ExceptionHandlerMiddleware(next.Object, logger.Object);
await mw.Invoke(ctx.Object);
mr.VerifyAll();
}
示例10: InvokeTest
public async Task InvokeTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null);
var ctx = mr.Create<IOwinContext>();
var wrappersManager = mr.Create<IWrappersManager>();
next.Setup(x => x.Invoke(ctx.Object)).Returns(Task.CompletedTask).Verifiable();
wrappersManager.Setup(x => x.InitializeAll()).Verifiable();
wrappersManager.Setup(x => x.DisposeAll()).Verifiable();
var mw = new InitializeWrappersMiddleware(next.Object, wrappersManager.Object);
await mw.Invoke(ctx.Object);
mr.VerifyAll();
}
示例11: InvokeTest
public async Task InvokeTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null);
var ctx = mr.Create<IOwinContext>();
var response = mr.Create<IOwinResponse>();
const string redirectToPage = "http://ya.ru";
ctx.SetupGet(x => x.Response).Returns(response.Object).Verifiable();
response.Setup(x => x.Redirect(redirectToPage)).Verifiable();
var midleware = new RedirectMiddleware(next.Object, redirectToPage);
await midleware.Invoke(ctx.Object);
mr.VerifyAll();
}
示例12: ShouldVerifyAll
public void ShouldVerifyAll()
{
try
{
var repository = new MockRepository(MockBehavior.Default);
var mock = repository.Create<IFoo>();
mock.Setup(foo => foo.Do());
repository.VerifyAll();
}
catch (MockException mex)
{
Assert.AreEqual(MockException.ExceptionReason.VerificationFailed, mex.Reason);
}
}
示例13: InvokeTest
public async Task InvokeTest()
{
var mr = new MockRepository(MockBehavior.Strict);
var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null);
var ctx = mr.Create<IOwinContext>();
var logger = mr.Create<ILog>();
var request = mr.Create<IOwinRequest>();
logger.Setup(x => x.Info(It.IsAny<string>())).Verifiable();
next.Setup(x => x.Invoke(ctx.Object)).Returns(Task.CompletedTask).Verifiable();
ctx.SetupGet(x => x.Request).Returns(request.Object).Verifiable();
request.SetupGet(x =>x.Method).Returns("fasefaes").Verifiable();
request.SetupGet(x =>x.Uri).Returns(new Uri("http://ya.ru")).Verifiable();
request.SetupGet(x =>x.RemoteIpAddress).Returns("asefasergsdrg").Verifiable();
request.SetupGet(x =>x.RemotePort).Returns(11).Verifiable();
var mw = new LoggerMiddleware(next.Object, logger.Object);
await mw.Invoke(ctx.Object);
mr.VerifyAll();
}
示例14: SafeTypeUsingTest
public void SafeTypeUsingTest()
{
var mockRepository = new MockRepository(MockBehavior.Strict);
Mock<ISqlTypeHelper> sqltypeHelperMock = mockRepository.Create<ISqlTypeHelper>();
Mock<ISqlNativeTypeStringCreator> sqlNativestringCreatorHelperMock =
mockRepository.Create<ISqlNativeTypeStringCreator>();
var sqlDescriptionAttributes = new Dictionary<PropertyInfo, SqlDescriptionAttribute>
{
{
typeof (Person).GetProperty("Id"), new SqlDescriptionAttribute("Id", SqlDbType.Int)
},
{
typeof (Person).GetProperty("Name"), new SqlDescriptionAttribute("Name", SqlDbType.NVarChar, 4000)
}
};
sqltypeHelperMock.Setup(x => x.Create(typeof (Person))).Returns(sqlDescriptionAttributes).Verifiable();
sqlNativestringCreatorHelperMock.Setup(x => x.Create("Id", SqlDbType.Int, null))
.Returns("\"Id\" int")
.Verifiable();
sqlNativestringCreatorHelperMock.Setup(x => x.Create("Name", SqlDbType.NVarChar, 4000))
.Returns("\"Name\" nvarchar(4000)")
.Verifiable();
using (IDbConnection con = new ConnectionFactory().Create())
{
string name;
dynamic res;
const string selectFromSysTypesWhereNameName = "select * from sys.types where name = @Name";
using (
var safeTypeUsing = new SafeTypeUsing<Person>(con, sqltypeHelperMock.Object,
sqlNativestringCreatorHelperMock.Object))
{
name = safeTypeUsing.TypeName;
res = con.Query(selectFromSysTypesWhereNameName, new {Name = name}).SingleOrDefault();
Assert.IsNotNull(res);
}
res = con.Query(selectFromSysTypesWhereNameName, new {Name = name}).SingleOrDefault();
Assert.IsNull(res);
}
mockRepository.VerifyAll();
}
示例15: RegisterToolsPath_should_set_tools_path_even_if_path_environment_variable_was_null
public void RegisterToolsPath_should_set_tools_path_even_if_path_environment_variable_was_null()
{
// Arrange
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var envRepos = new EnvironmentRepository();
var mocks = new MockRepository(MockBehavior.Strict);
{
var m = mocks.Create<Func<string, EnvironmentVariableTarget, string>>();
m.Setup(_ => _("ALLUSERSPROFILE", EnvironmentVariableTarget.Process)).Returns(@"C:\ProgramData");
m.Setup(_ => _("Path", EnvironmentVariableTarget.Process)).Returns(default(string));
m.Setup(_ => _("Path", EnvironmentVariableTarget.Machine)).Returns(default(string));
envRepos.EnvironmentGetEnvironmentVariable = m.Object;
}
{
var m = mocks.Create<Action<string, string, EnvironmentVariableTarget>>();
m.Setup(_ => _("Path", @"C:\ProgramData\chocolatey\lib\Prig\tools", EnvironmentVariableTarget.Process));
envRepos.EnvironmentSetEnvironmentVariable = m.Object;
}
{
var m = mocks.Create<Func<RegistryKey, string, bool, RegistryKey>>();
m.Setup(_ => _(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", true)).Returns(RegistryKeyMixin.DummyEnvironmentKey);
envRepos.RegistryKeyOpenSubKeyStringBoolean = m.Object;
}
{
var m = mocks.Create<Action<RegistryKey, string, object>>();
m.Setup(_ => _(RegistryKeyMixin.DummyEnvironmentKey, "Path", @"C:\ProgramData\chocolatey\lib\Prig\tools"));
envRepos.RegistryKeySetValue = m.Object;
}
// Act
envRepos.RegisterToolsPath();
// Assert
mocks.VerifyAll();
}