コード例 #1
0
        public async Task browse_asyc_calls_mappers_map_method_using_repos_browse_async_result()
        {
            //Given
            IEnumerable <Company> companiesFromRepo   = new List <Company>();
            IEnumerable <Company> companiesGivenToMap = null;

            var companyRepoMock = new Mock <ICompanyRepository>();

            companyRepoMock.Setup(x => x.BrowseAsync())
            .ReturnsAsync(companiesFromRepo);

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <CompanyDto> >(companiesFromRepo))
            .Callback <object>(x => companiesGivenToMap = x as IEnumerable <Company>);

            var predictorProviderMock = new Mock <IValuePredictorProvider>();

            var comapnyService = new CompanyService(companyRepoMock.Object,
                                                    predictorProviderMock.Object, mapperMock.Object);

            //When
            await comapnyService.BrowseAsync();

            //Then
            mapperMock.Verify(x => x.Map <IEnumerable <CompanyDto> >(companiesFromRepo),
                              Times.Once);
            companiesFromRepo.Should().BeSameAs(companiesGivenToMap);
        }
コード例 #2
0
        public async Task browse_asyc_calls_browse_async_on_copmanies_repo()
        {
            //Given
            var companyRepoMock       = new Mock <ICompanyRepository>();
            var mapperMock            = new Mock <IMapper>();
            var predictorProviderMock = new Mock <IValuePredictorProvider>();

            var comapnyService = new CompanyService(companyRepoMock.Object,
                                                    predictorProviderMock.Object, mapperMock.Object);

            //When
            await comapnyService.BrowseAsync();

            //Then
            companyRepoMock.Verify(x => x.BrowseAsync(), Times.Once);
        }
コード例 #3
0
        public async Task browse_asyc_returns_mappers_map_result()
        {
            //Given
            IEnumerable <CompanyDto> mappedCompanies = new List <CompanyDto>();

            var companyRepoMock = new Mock <ICompanyRepository>();

            var mapperMock = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <IEnumerable <CompanyDto> >(
                                 It.IsAny <IEnumerable <Company> >()))
            .Returns(mappedCompanies);

            var predictorProviderMock = new Mock <IValuePredictorProvider>();

            var comapnyService = new CompanyService(companyRepoMock.Object,
                                                    predictorProviderMock.Object, mapperMock.Object);

            //When
            var returnedCollection = await comapnyService.BrowseAsync();

            //Then
            returnedCollection.Should().BeSameAs(mappedCompanies);
        }