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


C# AutoMoqer类代码示例

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


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

示例1: When_a_navigation_button_is_clicked_the_associated_page_should_be_displayed

        public void When_a_navigation_button_is_clicked_the_associated_page_should_be_displayed()
        {
            this.testContainer = new UnityContainer();
            this.autoMocker = new AutoMoq.AutoMoqer(this.testContainer);

            var mockPageViewModel = new Mock<IPageViewModel>();
            mockPageViewModel.SetupGet(page => page.Title).Returns("Page1");
            IPageViewModel pageViewModel = mockPageViewModel.Object;

            var viewModelFactoryMock = new Mock<IViewModelFactory>();
            viewModelFactoryMock.Setup(f => f.Get<StartPageViewModel>()).Returns(() => new StartPageViewModel(new Mock<INavigationService>().Object));
            this.autoMocker.SetInstance(viewModelFactoryMock.Object);

            var navigationServiceMock = this.navigationServiceMock;
            navigationServiceMock.Setup(vm => vm.GetDefaultPagesByNames())
                                 .Returns(
                                     new Dictionary<string, Func<IPageViewModel>>
                                         {
                                             { "page1", () => pageViewModel },
                                             { "page2", () => null },
                                             { "page3", () => null },
                                             { "page4", () => null },
                                         });

            INavigationService navigationService = navigationServiceMock.Object;
            this.autoMocker.SetInstance(navigationService);

            var applicationViewModel = this.autoMocker.Resolve<ApplicationViewModel>();

            applicationViewModel.LeftNavigationButtonCollection.Single(btn => btn.DisplayText == "page1").ExecuteAsync(null);

            navigationServiceMock.VerifySet(ns => ns.CurrentPage = pageViewModel);
        }
开发者ID:joomnet,项目名称:SkillSignal,代码行数:33,代码来源:ApplicationViewModelTests.cs

示例2: creating_the_child_twice

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

            autoMoq.Create<Child>();
            autoMoq.Create<Child>();
        }
开发者ID:darrencauthon,项目名称:AutoMoq,代码行数:7,代码来源:CallingCreateTwice.cs

示例3: SetUp

        public void SetUp()
        {
            var customer = new Customer
            {
                Name = CustomerName
            };

            var employee = new Employee
            {
                Name = EmployeeName
            };

            var product = new Product
            {
                Name = ProductName
            };

            _sale = new Sale()
            {
                Id = SaleId,
                Date = Date,
                Customer = customer,
                Employee = employee,
                Product = product,
                UnitPrice = UnitPrice,
                Quantity = Quantity,
                TotalPrice = TotalPrice
            };

            _mocker = new AutoMoqer();

            _query = _mocker.Create<GetSalesListQuery>();
        }
开发者ID:boriphuth,项目名称:clean-architecture-demo,代码行数:33,代码来源:GetSalesListQueryTests.cs

示例4: RequiresAuthorizationCodeGrantType

        public void RequiresAuthorizationCodeGrantType()
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns<string>(null);

            var validator = mocker.Resolve<AuthorizationCodeRequestValidator>();

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("");

            var result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsTrue(result.ErrorDescription.HasValue());

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("   ");

            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.AreEqual(ErrorCode.InvalidRequest, result.ErrorCode);
            Assert.IsTrue(result.ErrorDescription.HasValue());

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns("bad");

            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.AreEqual(ErrorCode.InvalidGrant, result.ErrorCode);
            Assert.IsTrue(result.ErrorDescription.HasValue());

            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.AuthorizationCode);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.AuthorizationCode).Returns("authcode");
            result = validator.ValidateRequest(mocker.GetMock<IOAuthRequest>().Object);
            Assert.IsTrue(result.Success);
        }
开发者ID:naasir,项目名称:OAuth2Provider,代码行数:30,代码来源:AuthorizationCodeRequestValidatorTest.cs

示例5: TestCloseInvalidConnection

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

            var mockConnectionFactory = mocker.GetMock<RabbitMQ.Client.ConnectionFactory>();
            var mockConnection1 = new Mock<RabbitMQ.Client.IConnection>();
            var mockConnection2 = new Mock<RabbitMQ.Client.IConnection>();

            mockConnectionFactory.Setup(c => c.CreateConnection()).ReturnsInOrder(mockConnection1.Object, mockConnection2.Object);

            // simulate a dead connection
            mockConnection1.Setup(c => c.IsOpen).Returns(false);

            var connectionFactory = new SingleConnectionFactory(mockConnectionFactory.Object);

            var connection = connectionFactory.CreateConnection();

            // the dead connection should be discarded
            connection.CreateChannel(false);
            mockConnectionFactory.Verify(c => c.CreateConnection(), Times.Exactly(2));
            mockConnection2.Verify(c => c.CreateModel(), Times.Exactly(1));

            connectionFactory.Dispose();
            mockConnection2.Verify(c => c.Close(), Times.Exactly(1));
        }
开发者ID:DonMcRae,项目名称:spring-net-amqp,代码行数:25,代码来源:SingleConnectionFactoryTests.cs

示例6: 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

示例7: SendShout_should_return_a_success_response_for_an_episode_shout

        public void SendShout_should_return_a_success_response_for_an_episode_shout()
        {
            //Setup
            var expectedUrl = String.Format("{0}{1}", Url.ShoutEpisode, Constants.ApiKey);
            var expectedJson = "{\"username\": \"username\",\"password\": \"sha1hash\",\"tvdb_id\": 213221,\"title\": \"Portlandia\",\"year\": 2011,\"season\": 1,\"episode\": 1,\"shout\": \"The opening musical number is just superb!\"}";
            var jsonResult = "{\"status\":\"success\",\"message\":\"shout added to Portlandia 1x01\"}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(expectedUrl, It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            var shout = new ShoutEpisode
                            {
                                Username = "username",
                                Password = "sha1hash",
                                TvdbId = 213221,
                                Title = "Portlandia",
                                Year = 2011,
                                Season = 1,
                                Episode = 1,
                                Shout = "The opening musical number is just superb!"
                            };

            //Act
            var result = mocker.Resolve<ShoutProvider>().SendShout(Constants.ApiKey, shout);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("shout added to Portlandia 1x01");
        }
开发者ID:markus101,项目名称:Trakter,代码行数:30,代码来源:ShoutProviderTests.cs

示例8: AddListItems_should_return_success_when_list_items_are_added

        public void AddListItems_should_return_success_when_list_items_are_added()
        {
            //Setup
            const string slug = "new-test-list";

            var items = new List<dynamic>();
            items.Add(new { Type = "movie", Tmdb_id = 161, Title = "Ocean's 11", Year = 2001 });
            items.Add(new { Type = "show", Title = "30 Rock", Tvdb_Id = 79488 });

            var expectedJson = "{\"username\":\"username\",\"password\":\"sha1hash\",\"slug\":\"new-test-list\",\"items\":[{\"type\":\"movie\",\"tmdb_id\":161,\"title\":\"Ocean's 11\",\"year\":2001},{\"type\":\"show\",\"title\":\"30 Rock\",\"tvdb_id\":79488}]}";

            var jsonResult = "{\"status\": \"success\",\"inserted\": 2,\"already_exist\": 0,\"skipped\": 0,\"skipped_array\": []}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<ListProvider>().AddListItems(Constants.ApiKey, "username", "sha1hash", slug, items);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Inserted.Should().Be(items.Count);
            result.Skipped.Should().Be(0);
            result.Already_Exist.Should().Be(0);
        }
开发者ID:markus101,项目名称:Trakter,代码行数:26,代码来源:ListProviderTests.cs

示例9: AddList_should_return_success_when_list_is_added

        public void AddList_should_return_success_when_list_is_added()
        {
            //Setup
            const string name = "Top 10 of 2011";
            const ListPrivacyType privacy = ListPrivacyType.Public;
            const string description = "These movies and shows really defined 2011 for me.";

            var expectedJson = @"{""username"": ""username"",""password"": ""sha1hash"",""name"": ""Top 10 of 2011"",""description"": ""These movies and shows really defined 2011 for me."",""privacy"": ""public""}";

            var jsonResult = "{\"status\":\"success\",\"message\":\"list added\",\"name\":\"Top 10 of 2011\",\"slug\":\"top-10-of-2011\",\"privacy\":\"public\"}";

            var mocker = new AutoMoqer();
            mocker.GetMock<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<String>(), It.Is<string>(e => e.Replace(" ", "").Replace("\r\n", "").Replace("\t", "") == expectedJson.Replace(" ", "")))).Returns(jsonResult);

            //Act
            var result = mocker.Resolve<ListProvider>().AddList(Constants.ApiKey, "username", "sha1hash", name, privacy, description);

            //Assert
            result.Should().NotBeNull();
            result.Status.Should().Be(ResultStatusType.Success);
            result.Message.Should().Be("list added");
            result.Name.Should().Be(name);
            result.Slug.Should().Be(name.Replace(' ', '-').ToLowerInvariant());
            result.Privacy.Should().Be(privacy);
        }
开发者ID:markus101,项目名称:Trakter,代码行数:25,代码来源:ListProviderTests.cs

示例10: 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

示例11: 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

示例12: ItSendsBackSomeRss

        public void ItSendsBackSomeRss(ComicType type)
        {
            var mocker = new AutoMoqer();
            mocker.GetMock<IComicsRepository>()
                .Setup(m => m.GetLatestComics(type, 10))
                .Returns(new[]
                {
                    new Comic()
                    {
                        ComicNumber = 1,
                        ComicType = type,
                        ImageSrc = "http://example.com/image.png",
                        Permalink = "http://example.com",
                        ComicId = 1,
                        PublishedDate = DateTime.Today
                    }
                });

            var result = mocker.Create<FeedController>().Feed(type);

            var s = new MemoryStream();
            result.FileStream.CopyTo(s);
            var xml = Encoding.UTF8.GetString(s.ToArray());

            Check.That(result.ContentType).IsEqualTo("text/xml");
            Check.That(xml).Contains("http://example.com/image.png");
        }
开发者ID:akatakritos,项目名称:Comics,代码行数:27,代码来源:FeedControllerTests.cs

示例13: Setup

 public void Setup()
 {
     this.moqer = new AutoMoq.AutoMoqer();
     this.sut = this.moqer.Resolve<RssSubscriptionService>();
     this.mockHandlerFactory = this.moqer.GetMock<ISubscriptionHandlerFactory>();
     this.mockSubscriptionHandler = this.moqer.GetMock<ISubscriptionHandler>();
 }
开发者ID:jstadnicki,项目名称:isthereanynews,代码行数:7,代码来源:LoadAllUnreadRssEntriesToReadForCurrentUserFromSubscription.cs

示例14: I_can_instantiate_a_working_automoqer_with_no_dependencies

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

            var bar = mocker.Create<Bar>();
            bar.Foo.ShouldBeSameAs(mocker.GetMock<IFoo>().Object);
        }
开发者ID:darrencauthon,项目名称:AutoMoq,代码行数:7,代码来源:ConstructorTests.cs

示例15: WhenClientIdIsInvalid_ThenThrowsException

        public void WhenClientIdIsInvalid_ThenThrowsException()
        {
            var mocker = new AutoMoqer();
            mocker.MockServiceLocator();
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ContentType).Returns(ContentType.FormEncoded);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientSecret).Returns("clientsecret");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Username).Returns("username");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.Password).Returns("password");
            mocker.GetMock<IOAuthRequest>().Setup(x => x.GrantType).Returns(GrantType.Password);
            mocker.GetMock<IOAuthRequest>().Setup(x => x.ClientId).Returns("clientid");
            mocker.GetMock<IConsumerRepository>().Setup(x => x.GetByClientId("clientid")).Returns<ConsumerImpl>(null);

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

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


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