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


C# Mock.SetReturnsDefault方法代码示例

本文整理汇总了C#中Mock.SetReturnsDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.SetReturnsDefault方法的具体用法?C# Mock.SetReturnsDefault怎么用?C# Mock.SetReturnsDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.SetReturnsDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Given

 public void Given()
 {
     gateway = new Mock<Gateway>();
     gateway.SetReturnsDefault(true);
     obj = new Mock<StatefulObject>();
     obj.SetReturnsDefault(obj.Object);
 }
开发者ID:nelsestu,项目名称:objectflow,代码行数:7,代码来源:WhenTransitionIsBlocked.cs

示例2: when_finding_non_existing_assignment_then_returns_null

        public void when_finding_non_existing_assignment_then_returns_null()
        {
            var storage = new Mock<IBlobStorage>();
            storage.SetReturnsDefault<byte[]>(null);
            var dao = new OrderDao(() => new ConferenceRegistrationDbContext("OrderDaoFixture"), storage.Object, Mock.Of<ITextSerializer>());

            var dto = dao.FindOrderSeats(Guid.NewGuid());

            Assert.Null(dto);
        }
开发者ID:AlexShkorParalect,项目名称:cqrs-journey-code,代码行数:10,代码来源:OrderDaoFixture.cs

示例3: UseAutofacLifetimeScopeInjectorDoesntAddWrappedMiddlewareInstancesToAppBuilder

        public void UseAutofacLifetimeScopeInjectorDoesntAddWrappedMiddlewareInstancesToAppBuilder()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<TestMiddleware>();
            var container = builder.Build();
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.SetReturnsDefault(app.Object);

            app.Object.UseAutofacLifetimeScopeInjector(container);

            app.Verify(mock => mock.Use(It.IsAny<AutofacMiddleware<TestMiddleware>>(), It.IsAny<object[]>()), Times.Never);
        }
开发者ID:Xamarui,项目名称:Autofac.Owin,代码行数:13,代码来源:AutofacAppBuilderExtensionsFixture.cs

示例4: CreateShareLink_CreatedLinkAndToken

        public void CreateShareLink_CreatedLinkAndToken()
        {
            // arrange
            var pathHelper = new Mock<IPathHelper>();
            var hashService = new HashService();
            var shareService = new ShareService(pathHelper.Object, hashService);

            pathHelper.SetReturnsDefault("/user/share");

            // act
            var link = shareService.CreateShareLink("[email protected]");

            // assert
            link.Should().Contain("/user/share/[email protected]?key=");
        }
开发者ID:TGebreyes,项目名称:trackyt.net,代码行数:15,代码来源:ShareServiceTests.cs

示例5: RecordCalculation_ProvideCalcuation_Should_populate_stream_with_csv

        public void RecordCalculation_ProvideCalcuation_Should_populate_stream_with_csv()
        {
            var calculation = new Calculation { Answer = 2.1, Operation = "theOperation", Probability1 = 0.3, Probability2 = 0.6 };
            var memoryStream = new MemoryStream();
            var mockClock = new Mock<IClock>();

            mockClock.SetReturnsDefault(new DateTime(2000, 1, 10, 10, 12, 30));

            var logger = new Logger(memoryStream, mockClock.Object);
            logger.RecordCalculation(calculation);

            byte[] buffer = memoryStream.ToArray();
            var result = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
            Assert.AreEqual("10/01/2000 10:12:30,0.3,0.6,2.1,theOperation\r\n", result);
        }
开发者ID:cw1317,项目名称:miniProject,代码行数:15,代码来源:LoggerTests.cs

示例6: CanPerformActivityAsync_PassDelegateParameter_ReturnTrue

        public async Task CanPerformActivityAsync_PassDelegateParameter_ReturnTrue()
        {
            // Arrange
            var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>();
            mockPredicate.SetReturnsDefault(Task.FromResult(true));

            var user = new UserAuthorisation(userName);

            // Act
            var result = await user.CanPerformActivityAsync("READ", mockPredicate.Object);

            // Assert
            Assert.IsTrue(result);
            mockPredicate.Verify(p => p(user, "READ"), Times.Once);
        }
开发者ID:grantcolley,项目名称:dipsecure,代码行数:15,代码来源:AsyncUserAuthorisationTest.cs

示例7: ValidateShareKey_WrongKey

        public void ValidateShareKey_WrongKey()
        {
            var pathHelper = new Mock<IPathHelper>();
            var hashService = new HashService();
            var shareService = new ShareService(pathHelper.Object, hashService);

            pathHelper.SetReturnsDefault("/user/share");

            var key = "dd12113dcb92ffeb0d7afaf0261fAAAA";

            // act
            var result = shareService.ValidateShareKey("[email protected]", key);

            // assert
            result.Should().Be.False();
        }
开发者ID:TGebreyes,项目名称:trackyt.net,代码行数:16,代码来源:ShareServiceTests.cs

示例8: CanPerformActivity_MockDelegate_ReturnTrue

        public void CanPerformActivity_MockDelegate_ReturnTrue()
        {
            // Arrange
            var mockCanPerformActivityHandler = new Mock<Func<UserAuthorisation,string, bool>>();
            mockCanPerformActivityHandler.SetReturnsDefault(true);

            var user = new UserAuthorisation(userName)
                .AddCanPerformActivityDelegate(mockCanPerformActivityHandler.Object);

            // Act
            var result = user.CanPerformActivity("READ");

            // Assert
            Assert.IsTrue(result);
            mockCanPerformActivityHandler.Verify(u => u(user, "READ"), Times.Once);
        }
开发者ID:grantcolley,项目名称:dipsecure,代码行数:16,代码来源:UserAuthorisationTest.cs

示例9: SendAfterOpenDoesBehavesCorrectlyForConfiguredQueuingBehavior

        public void SendAfterOpenDoesBehavesCorrectlyForConfiguredQueuingBehavior(QueuingBehavior queuingBehavior, int expectedCounter)
        {
            var perfCounters = new Mock<IPerformanceCounterManager>();
            var queueLengthCounter = new Mock<IPerformanceCounter>();
            var counterIncrementCount = 0;
            queueLengthCounter.Setup(c => c.Increment()).Callback(() => counterIncrementCount++);
            perfCounters.DefaultValue = DefaultValue.Mock;
            perfCounters.SetReturnsDefault(new NoOpPerformanceCounter());
            perfCounters.SetupAllProperties();
            perfCounters.Setup(pc => pc.ScaleoutSendQueueLength).Returns(queueLengthCounter.Object);

            var stream = new ScaleoutStream(new TraceSource("Queue"), "0", queuingBehavior, 1000, perfCounters.Object);

            stream.Send(_ => TaskAsyncHelper.Empty, null);

            stream.Open();

            stream.Send(_ => TaskAsyncHelper.Empty, null).Wait();

            Assert.Equal(expectedCounter, counterIncrementCount);
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:21,代码来源:ScaleoutStreamFacts.cs

示例10: Should_Delete_Media_With_Access_Rules

        public void Should_Delete_Media_With_Access_Rules()
        {
            RunActionInTransaction(session =>
                {
                    var uow = new DefaultUnitOfWork(session);
                    var repository = new DefaultRepository(uow);
                    var accessControlService = new Mock<IAccessControlService>().Object;
                    var commandContext = new Mock<ICommandContext>().Object;
                    var cmsConfiguration = Container.Resolve<ICmsConfiguration>();
                    var httpContextAccessor = new Mock<IHttpContextAccessor>();
                    httpContextAccessor.SetReturnsDefault("http://wwww.bcms.com/uploads/trash");

                    var file = TestDataProvider.CreateNewMediaFileWithAccessRules(3);
                    session.SaveOrUpdate(file);
                    session.Flush();
                    session.Clear();

                    var mediaService = new DefaultMediaService(repository, uow, accessControlService, cmsConfiguration);
                    var command = new DeleteMediaCommand(mediaService);
                    command.Repository = repository;
                    command.UnitOfWork = uow;
                    command.Context = commandContext;

                    var result = command.Execute(new DeleteMediaCommandRequest
                                        {
                                            Id = file.Id,
                                            Version = file.Version
                                        });

                    Assert.IsTrue(result);

                    session.Clear();

                    var deletedFile = session.Query<MediaFile>().FirstOrDefault(f => f.Id == file.Id && !f.IsDeleted);
                    Assert.IsNull(deletedFile);
                });
        }
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:37,代码来源:DeleteMediaCommandTest.cs

示例11: ReturnsDefaultValueOnProperty

		public void ReturnsDefaultValueOnProperty()
		{
			var mock = new Mock<IFoo>();
			mock.SetReturnsDefault(int.MinValue);

			Assert.Equal(int.MinValue, mock.Object.Value);
		}
开发者ID:CharlieBP,项目名称:moq4,代码行数:7,代码来源:ReturnsFixture.cs

示例12: ReturnsDefaultValueType

		public void ReturnsDefaultValueType()
		{
			var mock = new Mock<IFoo>();
			mock.SetReturnsDefault(true);

			Assert.Equal(true, mock.Object.ReturnBool());
		}
开发者ID:CharlieBP,项目名称:moq4,代码行数:7,代码来源:ReturnsFixture.cs

示例13: ReturnsDefaultReferenceValue

		public void ReturnsDefaultReferenceValue()
		{
			var mock = new Mock<IFoo>();
			mock.SetReturnsDefault<IList<int>>(new List<int>());

			Assert.NotNull(mock.Object.ReturnIntList());
		}
开发者ID:CharlieBP,项目名称:moq4,代码行数:7,代码来源:ReturnsFixture.cs

示例14: UseMiddlewareFromContainerRequiresInjectorRegistrationFirst

        public void UseMiddlewareFromContainerRequiresInjectorRegistrationFirst()
        {
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.SetReturnsDefault(app.Object);

            Assert.Throws<InvalidOperationException>(() => app.Object.UseMiddlewareFromContainer<TestMiddleware>());
        }
开发者ID:Xamarui,项目名称:Autofac.Owin,代码行数:8,代码来源:AutofacAppBuilderExtensionsFixture.cs

示例15: IsInRoleAsync_AddDelegateDuringInitialisation_ReturnTrue

        public async Task IsInRoleAsync_AddDelegateDuringInitialisation_ReturnTrue()
        {
            // Arrange
            var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>();
            mockPredicate.SetReturnsDefault(Task.FromResult(true));

            var user = new UserAuthorisation(userName)
                .AddAsyncIsInRoleDelegate(mockPredicate.Object);

            // Act
            var result = await user.IsInRoleAsync("DATAREADER");

            // Assert
            Assert.IsTrue(result);
            mockPredicate.Verify(p => p(user, "DATAREADER"), Times.Once);
        }
开发者ID:grantcolley,项目名称:dipsecure,代码行数:16,代码来源:AsyncUserAuthorisationTest.cs


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