Example #1
0
        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();
        }
Example #2
0
        public async Task PostServiceRequest_Success()
        {
            // Arrange
            var mockServiceRequestService   = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequest   = CreateMockServiceRequest(Guid.NewGuid(), "Random Desc");
            var serviceRequestServiceResult = new ServiceRequestServiceResult
            {
                ServiceRequest = expectectedServiceRequest,
                Success        = true,
            };

            mockServiceRequestService
            .Setup(x => x.CreateAsync(It.IsAny <ServiceRequest>()))
            .ReturnsAsync(serviceRequestServiceResult);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequestResult = await serviceRequestsController.PostServiceRequest(expectectedServiceRequest);

            // Assert

            var createdAtActionResult = (actualServiceRequestResult.Result as CreatedAtActionResult);

            Assert.IsTrue(this.IsSameServiceRequest(expectectedServiceRequest, (ServiceRequest)createdAtActionResult.Value));
            mockServiceRequestService.VerifyAll();
        }
        public void S_CanGetAllUserAccountDetails()
        {
            var mockMailClient = new Moq.Mock <IUserAccountRepository>();

            List <UserAccountModel> r = new List <UserAccountModel>();

            mockMailClient.Setup(client => client.GetAllUserAccountDetails()).Returns(r);


            //// Act
            var _UserAccountService = new UserAccountService(mockMailClient.Object);

            var actual = _UserAccountService.GetAllUserAccountDetails();

            //// Assert - assert on the mock
            mockMailClient.VerifyAll();

            //List<UserAccountModel> r = new List<UserAccountModel>();
            //    moqUserAccountRepositor.Setup(x => x.GetAllUserAccountDetails())
            //                        .Returns(r);

            //    this._IUserAccountRepository = moqUserAccountRepositor.Object;

            //    //// Act
            //    var _UserAccountService = new UserAccountService();

            //    var actual = _UserAccountService.GetAllUserAccountDetails();

            //    //// Assert - assert on the mock
            //    moqUserAccountRepositor.Verify();
        }
Example #4
0
        public async Task GetServiceRequests_Success()
        {
            // Arrange
            var mockServiceRequestService  = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequests = new List <ServiceRequest>
            {
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "1"),
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "2"),
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "3"),
                CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequests_Success) + "4")
            };

            mockServiceRequestService.Setup(x => x.ReadAllAsync()).ReturnsAsync(expectectedServiceRequests);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequests = await serviceRequestsController.GetServiceRequests();

            // Assert
            Assert.AreEqual(4, actualServiceRequests.Value.Count());
            foreach (var expectectedServiceRequest in expectectedServiceRequests)
            {
                Assert.IsTrue(actualServiceRequests.Value.Any(x => x.Id.Equals(expectectedServiceRequest.Id)));
            }
            mockServiceRequestService.VerifyAll();
        }
        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();
        }
        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();
        }
        public void ShouldUseProvidedRandomGenerator()
        {
            var randomMock = new Moq.Mock <IRandom>();

            randomMock.Setup(m => m.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(2);
            var randomMoveStrategy = new RandomMoveStrategy(randomMock.Object);
            var move = randomMoveStrategy.GetNext();

            Assert.AreEqual(Move.Paper, move);
            randomMock.VerifyAll();
        }
Example #8
0
        public void SearchAds_CategoryGroupIsSelected_CallAdRepoWithSubCategoriesIds()
        {
            // 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()
            });

            Category group = new Category();

            group.AddCategory(new Category {
                Id = 12
            });
            group.AddCategory(new Category {
                Id = 17
            });

            var adRepoMock = new Moq.Mock <ISearchRepository>();

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

            var repoMock = new Moq.Mock <IRepository>();

            repoMock.Setup(r => r.Get <Category>(12)).Returns(group);


            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();
        }
        public void StartingPublisherCallsStartListener()
        {
            var mockListener = new Moq.Mock <IServiceCore>();

            mockListener.Setup(x => x.Start()).Verifiable();
            using (var service = new ServicePublisher(mockListener.Object))
            {
                service.Start();
            }
            mockListener.VerifyAll();
        }
		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();
		}
Example #11
0
        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();
        }
Example #12
0
        public async Task GetServiceRequest_Success()
        {
            // Arrange
            var mockServiceRequestService = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequest = CreateMockServiceRequest(Guid.NewGuid(), nameof(GetServiceRequest_Success));

            mockServiceRequestService.Setup(x => x.ReadByIdAsync(It.IsAny <Guid>())).ReturnsAsync(expectectedServiceRequest);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequestResult = await serviceRequestsController.GetServiceRequest(expectectedServiceRequest.Id);

            // Assert
            Assert.IsTrue(this.IsSameServiceRequest(expectectedServiceRequest, actualServiceRequestResult.Value));
            mockServiceRequestService.VerifyAll();
        }
Example #13
0
        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();
        }
Example #14
0
        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();
        }
Example #15
0
        public void TestAMoqStub()
        {
            // wrap fake with interceptors
            var fake = new Moq.Mock <IFakeStubjectUnderTest>();

            // set up mappings
            fake.Setup(mock => mock.GetInteger()).Returns(1);

            var sut = fake.Object;

            Assert.AreEqual(1, sut.GetInteger());

            Console.WriteLine("B is :" + sut.GetString());

            sut.GetDecimal();

            // Explicitly verify each expectation...
            fake.Verify(mock => mock.GetInteger(), Times.Once());

            // For stub behaviour, we just don't verify anything
            fake.VerifyAll();
        }
        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();
        }
Example #17
0
        public void TestAMoqMock()
        {
            var fake = new Moq.Mock <IFakeStubjectUnderTest>();

            fake.Setup(mock => mock.GetInteger()).Returns(1);

            // Moq keeps the fake and its definition separate
            var sut = fake.Object;

            Assert.AreEqual(1, sut.GetInteger());
            Assert.AreEqual(1, sut.GetInteger());

            // when no mappings are set, a mock will return default<T>
            Assert.AreEqual(null, sut.GetString());
            Assert.AreEqual(0m, sut.GetDecimal());
            Assert.AreEqual(DateTime.MinValue, sut.GetDateTime());

            // Explicitly verify each expectation...
            fake.Verify(mock => mock.GetInteger(), Times.Exactly(2));

            // Verify everything
            fake.VerifyAll();
        }
Example #18
0
        public async Task DeleteServiceRequest_Success()
        {
            // Arrange
            var mockServiceRequestService = new Moq.Mock <IServiceRequestService>(MockBehavior.Strict);
            var expectectedServiceRequest = CreateMockServiceRequest(Guid.NewGuid(), "Random Desc");
            var serviceResult             = new ServiceResult
            {
                Success = true,
            };
            var deleteGuid = Guid.NewGuid();

            mockServiceRequestService
            .Setup(x => x.DeleteAsync(deleteGuid))
            .ReturnsAsync(serviceResult);
            var serviceRequestsController = new ServiceRequestsController(mockServiceRequestService.Object);
            // Act
            var actualServiceRequestResult = await serviceRequestsController.DeleteServiceRequest(deleteGuid);

            // Assert
            Assert.IsNotNull(actualServiceRequestResult);
            Assert.AreEqual(201, ((IStatusCodeActionResult)actualServiceRequestResult).StatusCode);
            mockServiceRequestService.VerifyAll();
        }
Example #19
0
        public void ShouldNotBeAbleToRegisterUserIfAlreadyExists()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            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();
        }
Example #20
0
        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();
        }
Example #21
0
        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();
        }
Example #22
0
        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();
        }
Example #23
0
 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();
 }
Example #24
0
        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();
        }
Example #25
0
 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();
 }
Example #26
0
        public void ShouldBeAbleToRegisterUser()
        {
            LoginId loginid = new LoginId("*****@*****.**");
            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();
        }
Example #27
0
        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();
        }
Example #28
0
        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();
        }
Example #29
0
        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();
        }