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


C# AutoMoqer.SetInstance方法代码示例

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


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

示例1: Setup

        public void Setup()
        {
            testContainer = new UnityContainer();
            autoMocker = new AutoMoqer(this.testContainer);
            createProjectViewModelMock = new Mock<ICreateProjectViewModel>();
            navigationServiceMock = new Mock<INavigationService>();
            navigationServiceMock.SetupAllProperties();
            userServiceMock  = new Mock<IUserService>();
            viewModelFactoryMock = new Mock<IViewModelFactory>();

            autoMocker.SetInstance(createProjectViewModelMock.Object);
            autoMocker.SetInstance(navigationServiceMock.Object);
            autoMocker.SetInstance(userServiceMock.Object);
            autoMocker.SetInstance(viewModelFactoryMock.Object);
        }
开发者ID:joomnet,项目名称:SkillSignal,代码行数:15,代码来源:ApplicationViewModelTests.cs

示例2: ReportsComicsImported

        public void ReportsComicsImported()
        {
            var mocker = new AutoMoqer();

            var lastExplosmComic = new Comic();
            var newExplosmComic1 = new Comic();
            var newExplosmComic2 = new Comic();

            var explosm = new Mock<IComicDownloader>();
            explosm.Setup(m => m.GetNewComicsSince(lastExplosmComic))
                .Returns(new[] { newExplosmComic1, newExplosmComic2 });

            mocker.GetMock<IComicsRepository>()
                .Setup(m => m.GetLastImportedComic(ComicType.Explosm))
                .Returns(lastExplosmComic)
                .Verifiable();

            var registry = new ComicConfigRegistry();
            registry.Add(new ComicConfig(ComicType.Explosm, explosm.Object));

            // ReSharper disable once RedundantTypeArgumentsOfMethod
            mocker.SetInstance<ComicConfigRegistry>(registry);

            var process = mocker.Create<ImportProcess>();
            process.Run();

            Check.That(process.ImportedComics.Count).IsEqualTo(2);
        }
开发者ID:akatakritos,项目名称:Comics,代码行数:28,代码来源:ImportProcessTests.cs

示例3: UsesRegistryToGetNewComics

        public void UsesRegistryToGetNewComics()
        {
            var mocker = new AutoMoqer();

            var lastExplosmComic = new Comic();
            var newExplosmComic1 = new Comic();
            var newExplosmComic2 = new Comic();

            var explosm = new Mock<IComicDownloader>();
            explosm.Setup(m => m.GetNewComicsSince(lastExplosmComic))
                .Returns(new[] { newExplosmComic1, newExplosmComic2 });

            mocker.GetMock<IComicsRepository>()
                .Setup(m => m.GetLastImportedComic(ComicType.Explosm))
                .Returns(lastExplosmComic)
                .Verifiable();

            var registry = new ComicConfigRegistry();
            registry.Add(new ComicConfig(ComicType.Explosm, explosm.Object));

            // ReSharper disable once RedundantTypeArgumentsOfMethod
            mocker.SetInstance<ComicConfigRegistry>(registry);

            mocker.Create<ImportProcess>()
                .Run();

            mocker.GetMock<IComicsRepository>().VerifyAll();
            mocker.GetMock<IComicsRepository>()
                .Verify(m => m.InsertComic(newExplosmComic1), Times.Once);
            mocker.GetMock<IComicsRepository>()
                .Verify(m => m.InsertComic(newExplosmComic2), Times.Once);
        }
开发者ID:akatakritos,项目名称:Comics,代码行数:32,代码来源:ImportProcessTests.cs

示例4: Setup

 public void Setup()
 {
     _autoMoqer = new AutoMoqer();
     _memoryDatabaseProvider = new MemoryDatabaseProvider();
     _memoryDatabaseProvider.SetKeyColumn("Users", "Id");
     _autoMoqer.SetInstance<IDatabaseProvider>(_memoryDatabaseProvider);
 }
开发者ID:Hasshashin,项目名称:dotnet-mvc-boilerplate,代码行数:7,代码来源:UserServiceTests.cs

示例5: Setup

        public void Setup()
        {
            _mocker = new AutoMoqer();

            var mockFileSystem = new MockFileSystem();
            _mocker.SetInstance<IFileSystem>(mockFileSystem);

            // GetMock of the abstract class before create to prevent automoq bugs
            _mocker.GetMock<FileSystemWatcherBase>();

            _instance = _mocker.Create<DirectoryWatcher>();

            // Mocked files
            var content = new byte[] {1, 1, 1};
            _expectedFileLength = content.Length;
            _expectedWriteDate = DateTime.Now.ToUniversalTime();

            var nameWithPath = mockFileSystem.Path.Combine(Path, FileName);
            mockFileSystem.AddFile(nameWithPath, new MockFileData(content)
            {
                LastWriteTime = _expectedWriteDate
            });

            _trackedFile = new TrackedFile();
            _mocker.GetMock<ITrackedFileStore>()
                   .Setup(x => x.GetTrackedFileByFullPath(nameWithPath))
                   .Returns(_trackedFile);
        }
开发者ID:KallDrexx,项目名称:Backplan,代码行数:28,代码来源:DirectoryWatcherTests.cs

示例6: HomeControllerTests

        public HomeControllerTests()
        {
            _mocker = new AutoMoqer();

            _registry = new ComicConfigRegistry();
            _mocker.SetInstance(_registry);

            _latestDilbert = RegisterComic(ComicType.Dilbert);
            _latestExplosm = RegisterComic(ComicType.Explosm);
        }
开发者ID:akatakritos,项目名称:Comics,代码行数:10,代码来源:HomeControllerTests.cs

示例7: can_create_parent_object_when_setInstance_is_called_on_child

        public void can_create_parent_object_when_setInstance_is_called_on_child()
        {
            var autoMoq = new AutoMoqer();

            // the second line works... seems to be an issue calling Create twice?
            var child = autoMoq.Create<Child>();
            //var child = new Mock<IChild>().Object;
            autoMoq.SetInstance<IChild>(child);

            var parent = autoMoq.Create<Parent>();
            Assert.IsNotNull(parent);
        }
开发者ID:darrencauthon,项目名称:AutoMoq,代码行数:12,代码来源:CallingCreateTwice.cs

示例8: EnsureApplicationIsApproved

        public void EnsureApplicationIsApproved()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Username).Returns("username");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.Password);
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ConsumerId = 1, ClientId = "clientid", Secret = "clientsecret" });
            mocker.GetMock<IResourceOwnerRepository>().Setup(x => x.GetByUsername(1, "username")).Returns(new ResourceOwnerImpl { ResourceOwnerId = 2, Username = "username", Password = "password".ToHash() });
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password");
            mocker.SetInstance<IOAuthIssuer>(new OAuthIssuer());

            var authorizer = mocker.Resolve<PasswordTokenRequestAuthorizer>();

            var token = authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);

            mocker.GetMock<IResourceOwnerRepository>().Verify(x => x.ApproveConsumer(2, 1), Times.Once());
        }
开发者ID:chrismcv,项目名称:OAuth2Provider,代码行数:19,代码来源:PasswordTokenRequestAuthorizerTest.cs

示例9: ReturnsAuthorizedToken

        public void ReturnsAuthorizedToken()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Username).Returns("username");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.Password);
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ConsumerId = 1, ClientId = "clientid", Secret = "clientsecret" });
            mocker.GetMock<IResourceOwnerRepository>().Setup(x => x.GetByUsername(1, "username")).Returns(new ResourceOwnerImpl { ResourceOwnerId = 2, Username = "username", Password = "password".ToHash() });
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password");
            mocker.GetMock<IConfiguration>().Setup(x => x.AccessTokenExpirationLength).Returns(3600);
            mocker.SetInstance<IOAuthIssuer>(new OAuthIssuer());

            var authorizer = mocker.Resolve<PasswordTokenRequestAuthorizer>();

            var token = authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);

            mocker.GetMock<IResourceOwnerRepository>().Verify(x => x.ApproveConsumer(2, 1), Times.Once());
            Assert.IsNotNull(token);
            Assert.IsNotNull(token.AccessToken);
            Assert.AreEqual(3600, token.ExpiresIn);
            Assert.IsNotNull(token.RefreshToken);
        }
开发者ID:vishal-h,项目名称:OAuth2Provider,代码行数:24,代码来源:RefreshTokenRequestAuthorizerTest.cs

示例10: Setup

        public void Setup()
        {
            _mocker = new AutoMoqer();

            // GetMock of the abstract class before create to prevent automoq bugs
            _mocker.GetMock<FileSystemWatcherBase>();

            _fileSystem = new MockFileSystem();
            _fileSystem.AddDirectory(BaseDirectory);
            _mocker.SetInstance<IFileSystem>(_fileSystem);
        }
开发者ID:KallDrexx,项目名称:Backplan,代码行数:11,代码来源:DirectoryCrawlerTests.cs

示例11: Registering_instance_for_Interface_injects_that_Instance

        public void Registering_instance_for_Interface_injects_that_Instance()
        {
            //Arrange
            var mocker = new AutoMoqer();

            var instance = new Dependency();

            mocker.SetInstance<IDependency>(instance);

            //Act
            var result = mocker.Create<ClassWithDependencies>().Dependency;

            //Assert
            Assert.AreEqual(instance, result);
        }
开发者ID:nzaugg,项目名称:AutoMoq,代码行数:15,代码来源:EnsureMoqTests.cs

示例12: Create_with_constant_concerete_dependency_uses_constant

        public void Create_with_constant_concerete_dependency_uses_constant()
        {
            //Arrange
            var mocker = new AutoMoqer();

            var constant = new VirtualDependency() { PropValue = Guid.NewGuid().ToString() };

            mocker.SetInstance(constant);

            //Act
            var result = mocker.Create<ClassWithVirtualDependencies>().GetVirtualProperty();

            //Assert
            Assert.AreEqual((object) constant.PropValue, result);
        }
开发者ID:nzaugg,项目名称:AutoMoq,代码行数:15,代码来源:EnsureMoqTests.cs

示例13: WhenConsumerIsNolongerApproved_ThenThrowsException

        public void WhenConsumerIsNolongerApproved_ThenThrowsException()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.RefreshToken);
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ConsumerId = 12, ClientId = "clientid", Secret = "clientsecret" });
            mocker.GetMock<IResourceOwnerRepository>().Setup(x => x.IsConsumerApproved(10, 12)).Returns(false);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.SetInstance<IOAuthIssuer>(new OAuthIssuer());
            var issuer = new OAuthIssuer();

            var authorizer = mocker.Resolve<RefreshTokenRequestAuthorizer>();

            var token = issuer.GenerateRefreshToken(new TokenData { ConsumerId = 12, ResourceOwnerId = 10, Timestamp = 1 });
            mocker.GetMock<IOAuthRequest>().Setup(x => x.RefreshToken).Returns(token);

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.UnauthorizedClient, ex.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(ex.ErrorDescription));
            }
        }
开发者ID:vishal-h,项目名称:OAuth2Provider,代码行数:28,代码来源:RefreshTokenRequestAuthorizerTest.cs

示例14: WhenDataIsValid_ThenNewTokenIsCreated

        public void WhenDataIsValid_ThenNewTokenIsCreated()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.RefreshToken);
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns(new ConsumerImpl { ConsumerId = 12, ClientId = "clientid", Secret = "clientsecret" });
            mocker.GetMock<IResourceOwnerRepository>().Setup(x => x.IsConsumerApproved(10, 12)).Returns(true);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.SetInstance<IOAuthIssuer>(new OAuthIssuer());
            var issuer = new OAuthIssuer();

            var authorizer = mocker.Resolve<RefreshTokenRequestAuthorizer>();

            var token = issuer.GenerateRefreshToken(new TokenData { ConsumerId = 12, ResourceOwnerId = 10, Timestamp = 1 });
            mocker.GetMock<IOAuthRequest>().Setup(x => x.RefreshToken).Returns(token);

            var newToken = authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsNotNull(newToken);

            var accessTokenData = issuer.DecodeAccessToken(newToken.AccessToken);
            Assert.IsNotNull(accessTokenData);
            Assert.AreEqual(10, accessTokenData.ResourceOwnerId);
            Assert.IsTrue(accessTokenData.Timestamp > DateTimeOffset.UtcNow.AddMinutes(-5).Ticks);

            var refreshTokenData = issuer.DecodeRefreshToken(newToken.RefreshToken);
            Assert.IsNotNull(refreshTokenData);
            Assert.AreEqual(12, refreshTokenData.ConsumerId);
            Assert.AreEqual(10, refreshTokenData.ResourceOwnerId);
            Assert.IsTrue(refreshTokenData.Timestamp > DateTimeOffset.UtcNow.AddMinutes(-5).Ticks);
        }
开发者ID:vishal-h,项目名称:OAuth2Provider,代码行数:32,代码来源:RefreshTokenRequestAuthorizerTest.cs

示例15: WhenRedirectUriDoesNotMatch_ThenExceptionIsThrown

        public void WhenRedirectUriDoesNotMatch_ThenExceptionIsThrown()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.AuthorizationCode);
            mocker.GetMock<IConfiguration>().Setup(x => x.AuthorizationTokenExpirationLength).Returns(300);
            mocker.GetMock<IConfiguration>().Setup(x => x.AccessTokenExpirationLength).Returns(500);
            var issuer = new OAuthIssuer();
            mocker.SetInstance<IOAuthIssuer>(issuer);
            var token = issuer.GenerateAuthorizationToken(new TokenData { ConsumerId = 1, Timestamp = DateTime.UtcNow.Ticks, RedirectUri = "http://test.com" });
            mocker.GetMock<IOAuthRequest>().Setup(x => x.AuthorizationCode).Returns(token);

            var authorizer = mocker.Resolve<AuthorizationCodeAuthorizer>();

            try
            {
                authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);
                Assert.Fail("Exception not thrown");
            }
            catch (OAuthException ex)
            {
                Assert.AreEqual(ErrorCode.InvalidRequest, ex.ErrorCode);
                Assert.IsTrue(ex.ErrorDescription.HasValue());
            }

            mocker.GetMock<IOAuthRequest>().Setup(x => x.RedirectUri).Returns("http://test.com");
            var result = authorizer.Authorize(mocker.GetMock<IOAuthRequest>().Object);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.AccessToken.HasValue());
            Assert.AreEqual(500, result.ExpiresIn);
            Assert.IsTrue(result.RefreshToken.HasValue());
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:32,代码来源:AuthorizationCodeAuthorizerTest.cs


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