public void ReturnCorrectResult_IfNameMatch()
        {
            // Arrange
            var mockedCollection = new List <LakeModel>()
            {
                new LakeModel {
                    Name = "First"
                },
                new LakeModel {
                    Name = "Second"
                }
            };

            var model = new SearchModel()
            {
                Name = "not match"
            };
            var mockedLakeService = new Mock <ILakeService>();

            mockedLakeService.Setup(s => s.FindByLocation(It.IsAny <string>())).Returns(mockedCollection).Verifiable();

            var controller = new SearchApiController(mockedLakeService.Object);

            // Act
            var result  = controller.Lakes(model);
            var content = (result as OkNegotiatedContentResult <IEnumerable <LakeModel> >).Content;

            // Assert
            Assert.IsInstanceOf <OkNegotiatedContentResult <IEnumerable <LakeModel> > >(result);
            Assert.AreEqual(content, mockedCollection);

            mockedLakeService.Verify(s => s.FindByLocation(It.IsAny <string>()), Times.Once);
        }
Пример #2
0
        public void SetUp()
        {
            beginDate = DateTime.Parse("2019-09-16");

            endDate = DateTime.Parse("2019-09-24");

            _timesheets = SetupTimeSheets();

            _timesheetRespository = SetupTimeSheetRespository();

            _timesheetService = new TimeSheetService(_timesheetRespository);

            _searchApiController = new SearchApiController(_timesheetService);
        }
Пример #3
0
        public async Task GetRankings_ShouldReturn10Items()
        {
            var googleSearchService = new Mock <IGoogleSearchService>();
            var apiController       = new SearchApiController(googleSearchService.Object);

            var webHelper   = new WebHelper();
            var googleQuery = new GoogleQuery(webHelper);

            googleSearchService.Setup(service => service.GetRankingsAsync("", "", 100))
            .ReturnsAsync(await googleQuery.GetRankingsAsync("test", 1));

            var results = await apiController.Get("", "");

            Assert.AreEqual(10, results.Count());
        }
        public void ReturnNotFound_IfNameNotMatch()
        {
            // Arrange
            var model = new SearchModel()
            {
                Name = "not match"
            };
            var mockedLakeService = new Mock <ILakeService>();

            mockedLakeService.Setup(s => s.FindByLocation(It.IsAny <string>())).Verifiable();

            var controller = new SearchApiController(mockedLakeService.Object);

            // Act
            var result = controller.Lakes(model);

            // Assert
            Assert.IsInstanceOf <NotFoundResult>(result);
            mockedLakeService.Verify(s => s.FindByLocation(It.IsAny <string>()), Times.Once);
        }