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


C# MockRepository.VerifyAll方法代码示例

本文整理汇总了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();
        }
开发者ID:umaranis,项目名称:Prig,代码行数:34,代码来源:ProjectWideInstallerTest.cs

示例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();
        }
开发者ID:riberk,项目名称:TimespanFactory,代码行数:26,代码来源:TimeSpanRuleInfoSerializerTests.cs

示例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();
 }
开发者ID:riberk,项目名称:Rib.Common,代码行数:30,代码来源:LoggerMiddlewareTests.cs

示例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();
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:27,代码来源:ExceptionHandlerMiddlewareTests.cs

示例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();
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:25,代码来源:SetCorrelationIdHeaderMiddlewareTests.cs

示例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();
        }
开发者ID:solyutor,项目名称:EffectiveTesting,代码行数:58,代码来源:TestWithMocks.cs

示例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();
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:14,代码来源:ExceptionHandlerMiddlewareTests.cs

示例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();
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:14,代码来源:InitializeWrappersMiddlewareTests.cs

示例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();
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:15,代码来源:RedirectMiddlewareTests.cs

示例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);
			}
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:16,代码来源:MockRepositoryFixture.cs

示例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();
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:19,代码来源:LoggerMiddlewareTests.cs

示例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();
        }
开发者ID:riberk,项目名称:CommonCC,代码行数:43,代码来源:SafeTypeUsingTests.cs

示例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();
        }
开发者ID:umaranis,项目名称:Prig,代码行数:38,代码来源:EnvironmentRepositoryTest.cs


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