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


C# Moq.Mock.VerifyAll方法代码示例

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


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

示例1: OpenTest

        public void OpenTest()
        {
            var mock = new Moq.Mock<IMyDriver>();
            var client = new MyWork.MyConnection(new[] {mock.Object});
            mock.Setup(driver => driver.Connect());

            client.Open();

            mock.VerifyAll();
        }
开发者ID:wangxuesong,项目名称:unit-test-practices,代码行数:10,代码来源:MyClientTestFixture.cs

示例2: shouldBeAbleToFetchPagedData

		public void shouldBeAbleToFetchPagedData() {
			var avegaContactRepositoryMock = new Moq.Mock<IAvegaClientRepository>();

			avegaContactRepositoryMock.Setup(x=>x.GetAll(It.IsAny<int>(), It.IsAny<int>()))
				.Returns(new List<AvegaContact>());

			IAvegaClientRepository avegaContactRepository = avegaContactRepositoryMock.Object;

			int offsetStart = 0;
			int contactToGet = 5;
			avegaContactRepository.GetAll(offsetStart, contactToGet);

			avegaContactRepositoryMock.VerifyAll();
		}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:14,代码来源:IAvegaClientRepositoryTest.cs

示例3: InSuggester_PassSeveralSourcesAndSeveralStringKeywords_CheckThatReturnsCombinedReslt

        public void InSuggester_PassSeveralSourcesAndSeveralStringKeywords_CheckThatReturnsCombinedReslt()
        {
            // Setup several returning values
            // HACK had to use Moq directly instead of mocking kernel because it returned the same object. In this case it is ok, but once know how to solve it better change code.
            var resultMock1 = new Moq.Mock<ISuggestionInstance>();
            resultMock1.Setup(r => r.GetTextValue()).Returns("one");
            resultMock1.Setup(r => r.Relevance).Returns(10);
            var resultMock2 = new Moq.Mock<ISuggestionInstance>();
            resultMock2.Setup(r => r.GetTextValue()).Returns("two");
            resultMock2.Setup(r => r.Relevance).Returns(10);
            var resultMock3 = new Moq.Mock<ISuggestionInstance>();
            resultMock3.Setup(r => r.GetTextValue()).Returns("three");
            resultMock3.Setup(r => r.Relevance).Returns(10);

            this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock1.Object);
            this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock2.Object);
            this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock3.Object);

            // Setup two sources
            var sourceMock2 = new Moq.Mock<ISuggestionSource>();
            sourceMock2.Setup(m => m.GetSuggestions(It.IsAny<ISemanticObject>())).Returns(new ISuggestionInstance[] { resultMock1.Object, resultMock2.Object });

            var sourceMock1 = new Moq.Mock<ISuggestionSource>();
            sourceMock1.Setup(m => m.GetSuggestions(It.IsAny<ISemanticObject>())).Returns(new ISuggestionInstance[] { resultMock3.Object, resultMock2.Object });

            this.kernel.Bind<ISuggestionSource>().ToMethod(s => sourceMock1.Object);
            this.kernel.Bind<ISuggestionSource>().ToMethod(s => sourceMock2.Object);

            // Run test
            var sut = this.kernel.Get<Suggester>();
            var mockKeyword = this.kernel.GetMock<ISemanticObject>();
            var result = sut.GetSuggestions(new ISemanticObject[] { mockKeyword.Object });

            // verify
            CollectionAssert.AreEquivalent(result.Select(r => r.GetTextValue()).ToArray(), new string[] { resultMock2.Object.GetTextValue(), resultMock1.Object.GetTextValue(), resultMock3.Object.GetTextValue() });
            sourceMock1.VerifyAll();
            sourceMock2.VerifyAll();
        }
开发者ID:serrnovik,项目名称:SemanticDescription,代码行数:38,代码来源:SuggesterTests.cs

示例4: SearchAds_CategoryIsSelected_CallAdRepoWithOneCategoryId

        public void SearchAds_CategoryIsSelected_CallAdRepoWithOneCategoryId()
        {
            // Given
            Category cat = new Category { Id = 12 };

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "ship",
                City = new City() { Label = "the city" },
                Category = cat
            });

            var adRepoMock = new Moq.Mock<ISearchRepository>();
            adRepoMock.Setup(r => r.SearchAds(new string[] { "ship" }, null, new int[] { 12 })).Returns(searchResult);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(12)).Returns(cat);

            AdvancedAdSearchModel model = new AdvancedAdSearchModel()
            {
                SearchString = "ship",
                CategorySelectedId = 12
            };

            SearchServices service = new SearchServices(repoMock.Object, null, adRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.LightSearchAds(model);

            // Then
            Assert.AreEqual("ship", result.SearchString);
            Assert.IsNull(result.CitySelectedId);
            Assert.AreEqual(12, result.CategorySelectedId);
            Assert.AreEqual(1, result.SearchResult.Count);
            Assert.AreEqual(1, result.SearchResultTotalCount);
            Assert.AreEqual("ship", result.SearchResult[0].Title);

            adRepoMock.VerifyAll();
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:40,代码来源:SearchServicesTest.cs

示例5: SearchAds_2SearchString_CallAdRepoWithSeveralWords

        public void SearchAds_2SearchString_CallAdRepoWithSeveralWords()
        {
            // Given
            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "ship",
                City = new City() { Label = "the city" },
                Category = new Bea.Domain.Categories.Category()
            });
            searchResult.Add(new SearchAdCache
            {
                Title = "computer",
                City = new City() { Label = "the city" },
                Category = new Bea.Domain.Categories.Category()
            });

            var adRepoMock = new Moq.Mock<ISearchRepository>();
            adRepoMock.Setup(r => r.SearchAds(new string[] { "ship", "computer" }, 98, null)).Returns(searchResult);

            AdvancedAdSearchModel model = new AdvancedAdSearchModel()
            {
                SearchString = "ship computer",
                CitySelectedId = 98
            };

            SearchServices service = new SearchServices(null, null, adRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.LightSearchAds(model);

            // Then
            Assert.AreEqual("ship computer", result.SearchString);
            Assert.AreEqual(98, result.CitySelectedId);
            Assert.AreEqual(2, result.SearchResult.Count);
            Assert.AreEqual(2, result.SearchResultTotalCount);
            Assert.AreEqual("ship", result.SearchResult[0].Title);
            Assert.AreEqual("computer", result.SearchResult[1].Title);

            adRepoMock.VerifyAll();
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:41,代码来源:SearchServicesTest.cs

示例6: SearchAdsFromUrl_CityIsSelected_RunSearchWithCity

        public void SearchAdsFromUrl_CityIsSelected_RunSearchWithCity()
        {
            // Given
            City city = new City { Id = 12, LabelUrlPart = "city-url-label", Label = "Label" };

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "ship",
                City = city,
                Category = new Category { Label = "pouet" }
            });

            var adRepoMock = new Moq.Mock<ISearchRepository>();
            adRepoMock.Setup(r => r.SearchAds(null, city.Id, null)).Returns(searchResult);

            var catLocationServiceMock = new Moq.Mock<ILocationServices>();
            catLocationServiceMock.Setup(r => r.GetCityFromLabelUrlPart("city-url-label")).Returns(city);

            SearchServices service = new SearchServices(null, null, adRepoMock.Object, null, null, catLocationServiceMock.Object);

            // When
            AdSearchResultModel result = service.SearchAdsFromUrl("city-url-label", null);

            // Then
            Assert.IsNull(result.SearchString);
            Assert.AreEqual(12, result.CitySelectedId);
            Assert.AreEqual(1, result.SearchResult.Count);
            Assert.AreEqual(1, result.SearchResultTotalCount);
            Assert.AreEqual("ship", result.SearchResult[0].Title);

            adRepoMock.VerifyAll();
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:33,代码来源:SearchServicesTest.cs

示例7: SearchAdsFromUrl_CategoryIsSelected_RunSearchWithCategory

        public void SearchAdsFromUrl_CategoryIsSelected_RunSearchWithCategory()
        {
            // Given
            Category cat = new Category { Id = 12, LabelUrlPart = "cat-url-label", Label = "Label" };

            IList<SearchAdCache> searchResult = new List<SearchAdCache>();
            searchResult.Add(new SearchAdCache
            {
                Title = "ship",
                City = new City() { Label = "the city" },
                Category = cat
            });

            var adRepoMock = new Moq.Mock<ISearchRepository>();
            adRepoMock.Setup(r => r.SearchAds(null, null, It.Is<int[]>(x => x[0] == cat.Id))).Returns(searchResult);

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var catRepoMock = new Moq.Mock<ICategoryRepository>();
            catRepoMock.Setup(r => r.GetCategoryFromUrlPart("cat-url-label")).Returns(cat);

            SearchServices service = new SearchServices(repoMock.Object, catRepoMock.Object, adRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.SearchAdsFromUrl(null, "cat-url-label");

            // Then
            Assert.IsNull(result.SearchString);
            Assert.IsNull(result.CitySelectedId);
            Assert.AreEqual(12, result.CategorySelectedId);
            Assert.AreEqual("Label", result.CategorySelectedLabel);
            Assert.AreEqual(1, result.SearchResult.Count);
            Assert.AreEqual(1, result.SearchResultTotalCount);
            Assert.AreEqual("ship", result.SearchResult[0].Title);

            adRepoMock.VerifyAll();
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:38,代码来源:SearchServicesTest.cs

示例8: SearchAdsFromUrl_CategoryIsSelected_ReturnParentCategoryLabelUrlPartAsImagePath

        public void SearchAdsFromUrl_CategoryIsSelected_ReturnParentCategoryLabelUrlPartAsImagePath()
        {
            // Given
            Category cat = new Category { Id = 12, LabelUrlPart = "cat-url-label", Label = "Label", ImageName = "image" };

            var adRepoMock = new Moq.Mock<ISearchRepository>();
            adRepoMock.Setup(r => r.SearchAds(null, null, It.Is<int[]>(x => x[0] == cat.Id))).Returns(new List<SearchAdCache>());

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(r => r.Get<Category>(cat.Id)).Returns(cat);

            var catRepoMock = new Moq.Mock<ICategoryRepository>();
            catRepoMock.Setup(r => r.GetCategoryFromUrlPart("cat-url-label")).Returns(cat);

            SearchServices service = new SearchServices(repoMock.Object, catRepoMock.Object, adRepoMock.Object, null, null, null);

            // When
            AdSearchResultModel result = service.SearchAdsFromUrl(null, "cat-url-label");

            // Then
            Assert.IsNull(result.SearchString);
            Assert.IsNull(result.CitySelectedId);
            Assert.AreEqual(12, result.CategorySelectedId);
            Assert.AreEqual("image", result.CategoryImagePath);
            Assert.AreEqual("Label", result.CategorySelectedLabel);

            adRepoMock.VerifyAll();
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:28,代码来源:SearchServicesTest.cs

示例9: ShouldNotBeAbleToRegisterUserIfAlreadyExists

        public void ShouldNotBeAbleToRegisterUserIfAlreadyExists()
        {
            LoginId loginid = new LoginId("[email protected]");
            Name name = new Name("firstName", "lastName");

            var likes = new[]
                               {
                                   new Like() {UserId = loginid, Text = "Like1"},
                                   new Like() {UserId = loginid, Text = "Like2"},
                                   new Like() {UserId = loginid, Text = "Like3"},
                               };

            var dislikes = new[]
                               {
                                   new Dislike() {UserId = loginid, Text = "Dislike1"},
                                   new Dislike() {UserId = loginid, Text = "Dislike2"},
                                   new Dislike() {UserId = loginid, Text = "Dislike3"},
                               };

            User user = new User(loginid, name)
            {
                DateOfBirth = new GetInDate(DateTime.Today.AddYears(-25)),
                Location = new Location { City = "Banglore" },
                Gender = new Gender(),
                Likes = new HashedSet<Like>(likes),
                Dislikes = new HashedSet<Dislike>(dislikes),
                Picture = new Photo { Bytes = new byte[] { 1, 2, 3, 4, 5 } },
                Profile = new Profile("Big Profile")
            };

            var repositoryMock = new Moq.Mock<IUserRepository>();
            repositoryMock.Setup(p => p.LookupUsers(It.IsAny<User>())).Returns(new List<User> { user });
            user.Repository = repositoryMock.Object;
            Assert.Throws(typeof(UserAlreadyExistsException), user.Register);
            repositoryMock.VerifyAll();
        }
开发者ID:bagheera,项目名称:getin,代码行数:36,代码来源:UserTest.cs

示例10: ShouldNotBeAbleToCreateGroupIfAlreadyExists

        public void ShouldNotBeAbleToCreateGroupIfAlreadyExists()
        {
            User user = new User(new LoginId("123"), null);
            Group group = new Group() {Name = "Nature-Lovers"};
            var repositoryMock = new Moq.Mock<IGroupRepository>();
            user.GroupRepository = repositoryMock.Object;
            repositoryMock.Setup(p => p.Exists(group)).Returns(true);

            try{
                user.CreateGroup(group);
                Assert.Fail("exception expected");
            }
            catch (GroupAlreadyExistsException){
            }

            repositoryMock.VerifyAll();
        }
开发者ID:bagheera,项目名称:getin,代码行数:17,代码来源:UserTest.cs

示例11: ShouldBeAbleToRegisterUser

        public void ShouldBeAbleToRegisterUser()
        {
            LoginId loginid = new LoginId("[email protected]");
            string firstname = "firstName";
            string lastname = "lastName";
            Name name = new Name(firstname, lastname);

            Image image = new Bitmap(1, 1);

            Like[] likes = new Like[]
                               {
                                   new Like() {UserId = loginid, Text = "Like1"},
                                   new Like() {UserId = loginid, Text = "Like2"},
                                   new Like() {UserId = loginid, Text = "Like3"},
                               };

            Dislike[] dlikes = new Dislike[]
                               {
                                   new Dislike() {UserId = loginid, Text = "Dislike1"},
                                   new Dislike() {UserId = loginid, Text = "Dislike2"},
                                   new Dislike() {UserId = loginid, Text = "Dislike3"},
                               };

            User user = new User(loginid, name)
                            {
                                DateOfBirth = new GetInDate(DateTime.Today.AddYears(-25)),
                                Location = new Location { City = "Banglore" },
                                Gender = new Gender(),
                                Likes = new HashedSet<Like>(likes),
                                Dislikes = new HashedSet<Dislike>(dlikes),
                                Picture = new Photo { Bytes = new byte[] { 1, 2, 3, 4, 5 } },
                                Profile = new Profile("Big Profile")
                            };

            var repositoryMock = new Moq.Mock<IUserRepository>();
            repositoryMock.Setup(p => p.LookupUsers(It.IsAny<User>())).Returns(new List<User>());
            repositoryMock.Setup(p => p.Save(user));

            user.Repository = repositoryMock.Object;

            user.Register();
            repositoryMock.VerifyAll();
        }
开发者ID:bagheera,项目名称:getin,代码行数:43,代码来源:UserTest.cs

示例12: ShouldBeAbleToCallUserRepositoryonLookUpUsersWithAgeRestriction

 public void ShouldBeAbleToCallUserRepositoryonLookUpUsersWithAgeRestriction()
 {
     User user1 = new User(new LoginId("123"), null);
     var repositoryMock = new Moq.Mock<IUserRepository>();
     repositoryMock.Setup(p => p.LookupUsers(It.IsAny<User>(), It.IsAny<AgeRange>())).Returns(new List<User> { user1 });
     user1.Repository = repositoryMock.Object;
     IList<User> lookedupUser = user1.LookupUsers(new AgeRange());
     Assert.AreEqual(1, lookedupUser.Count());
     repositoryMock.VerifyAll();
 }
开发者ID:bagheera,项目名称:getin,代码行数:10,代码来源:UserTest.cs

示例13: UserShouldNotRecommendFriends

 public void UserShouldNotRecommendFriends()
 {
     User user1 = new User(new LoginId("123"), null);
     var repositoryMock = new Moq.Mock<IUserRepository>();
     User user2 = new User(new LoginId("234"), null);
     User user3 = new User(new LoginId("234"), null);
     repositoryMock.Setup(p => p.NotFriendsOf(user1)).Returns(new List<User> { user2, user3 });
     user1.Repository = repositoryMock.Object;
     Assert.AreEqual(0, user1.RecommendFriends().Count);
     repositoryMock.VerifyAll();
 }
开发者ID:bagheera,项目名称:getin,代码行数:11,代码来源:UserTest.cs

示例14: RecommendOnlyIfSimilarityScoreExceedsThreshold

        public void RecommendOnlyIfSimilarityScoreExceedsThreshold()
        {
            var user1 = new User(new LoginId("123"), new Name("Mark", "Twain"))
                            {
                                Likes = new HashedSet<Like>(new[]
                                                                {
                                                                    new Like() {UserId = new LoginId("123"), Text = "Like1"},
                                                                    new Like() {UserId = new LoginId("123"), Text = "Like2"},
                                                                    new Like() {UserId = new LoginId("123"), Text = "Like3"},
                                                                    new Like() {UserId = new LoginId("123"), Text = "Like4"},
                                                                    new Like() {UserId = new LoginId("123"), Text = "Like5"},
                                                                }),
                                Dislikes = new HashedSet<Dislike>(new[]
                                                                      {
                                                                          new Dislike() {UserId = new LoginId("123"), Text = "Dislike1"},
                                                                          new Dislike() {UserId = new LoginId("123"), Text = "Dislike2"},
                                                                          new Dislike() {UserId = new LoginId("123"), Text = "Dislike3"},
                                                                          new Dislike() {UserId = new LoginId("123"), Text = "Dislike4"},
                                                                          new Dislike() {UserId = new LoginId("123"), Text = "Dislike5"},
                                                                      }),
                            };

            var user2 = new User(new LoginId("345"), new Name("Sudhakar", "Rayavaram"))
                            {
                                Likes = new HashedSet<Like>(new[]
                                                                {
                                                                    new Like() {UserId = new LoginId("345"), Text = "Like6"},
                                                                    new Like() {UserId = new LoginId("345"), Text = "Like7"},
                                                                    new Like() {UserId = new LoginId("345"), Text = "Like8"},
                                                                }),
                                Dislikes = new HashedSet<Dislike>(new[]
                                                                      {
                                                                          new Dislike() {UserId = new LoginId("345"), Text = "Dislike6"},
                                                                          new Dislike() {UserId = new LoginId("345"), Text = "Dislike7"},
                                                                          new Dislike() {UserId = new LoginId("345"), Text = "Dislike8"},
                                                                      }),
                            };
            var user3 = new User(new LoginId("678"), new Name("Alex", "Anto"))
                            {
                                Likes = new HashedSet<Like>(new[]
                                                                {
                                                                    new Like() {UserId = new LoginId("678"), Text = "Like1"},
                                                                    new Like() {UserId = new LoginId("678"), Text = "Like2"},
                                                                    new Like() {UserId = new LoginId("678"), Text = "Like3"},
                                                                    new Like() {UserId = new LoginId("678"), Text = "Like4"},
                                                                    new Like() {UserId = new LoginId("678"), Text = "Like5"},
                                                                }),
                                Dislikes = new HashedSet<Dislike>(new[]
                                                                      {
                                                                          new Dislike() {UserId = new LoginId("678"), Text = "Dislike6"},
                                                                          new Dislike() {UserId = new LoginId("678"), Text = "Dislike7"},
                                                                          new Dislike() {UserId = new LoginId("678"), Text = "Dislike8"},
                                                                      }),
                            };
            var repositoryMock = new Moq.Mock<IUserRepository>();
            repositoryMock.Setup(p => p.NotFriendsOf(user1)).Returns(new List<User> { user2, user3 });
            user1.Repository = repositoryMock.Object;
            Assert.AreEqual(1, user1.RecommendFriends().Count);
            Assert.AreEqual(user3,user1.RecommendFriends().First());
            repositoryMock.VerifyAll();
        }
开发者ID:bagheera,项目名称:getin,代码行数:61,代码来源:UserTest.cs


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