public StatusRepositoryTest() { QueryWithDefaultValues = BaseListQuery.DefaultValues("nb"); Mock = new Mock.Mock(); StatusRepository = new Repositories.StatusRepository(Mock.Database.Context); _status = Mock.MockStatus(); }
public CategoryRepositoryTest() { _queryWithDefaultValues = BaseListQuery.DefaultValues("nb"); Mock = new Mock.Mock(); CategoryRepository = new Repositories.CategoryRepository(Mock.Database.Context); _category = Mock.MockCategory(); _language = "nb"; }
public BaseTest() { Mock = new Mock.Mock(); var config = Options.Create(ConfigHelper.GetDatabaseConfiguration()); var languageConfig = Options.Create(ConfigHelper.GetLanguageConfiguration()); ConceptRepository = new Repositories.ConceptRepository(Mock.Database.Context, config, languageConfig); BaseListQuery = BaseListQuery.DefaultValues("en"); }
public void GetAll_Returns_Status_500_When_Service_Returns_Null() { A.CallTo(() => _service.GetAllCategories(A <BaseListQuery> ._)).Returns(null); var result = _controller.GetAllCategories(BaseListQuery.DefaultValues("nb")); var status = result.Result as StatusCodeResult; Assert.Equal((int)HttpStatusCode.InternalServerError, status.StatusCode); }
public void GetAll_Returns_A_List_Of_Categories_If_There_Exists_Categories() { A.CallTo(() => _service.GetAllCategories(A <BaseListQuery> ._)).Returns(_listResponse); var result = _controller.GetAllCategories(BaseListQuery.DefaultValues("nb")); var okResult = result.Result as OkObjectResult; Assert.IsType <List <MetaCategory> >((okResult.Value as Response).Data); }
public void GetAll_Returns_Status_200_Categories_Is_Found() { A.CallTo(() => _service.GetAllCategories(A <BaseListQuery> ._)).Returns(_listResponse); var result = _controller.GetAllCategories(BaseListQuery.DefaultValues("nb")); var okResult = result.Result as OkObjectResult; Assert.Equal(200, okResult.StatusCode); }
public void GetRequiredCategories_Returns_EmptyList_If_No_Required_Categories_Exists() { Assert.Empty(CategoryRepository.GetAll(BaseListQuery.DefaultValues(_language))); var notRequiredCategory = Mock.MockCategory(); notRequiredCategory.IsRequired = false; Mock.Database.InsertCategory(notRequiredCategory); Assert.Empty(CategoryRepository.GetRequiredCategories(_language)); }
public MetaDataRepositoryTest() { _queryWithDefaultValues = BaseListQuery.DefaultValues("nb"); var config = ConfigHelper.GetLanguageConfiguration(); Mock = new Mock.Mock(); MetaRepository = new Repositories.MetadataRepository(Mock.Database.Context, new OptionsWrapper <LanguageConfig>(config)); _status = Mock.Database.InsertStatus(Mock.MockStatus()); _category = Mock.Database.InsertCategory(Mock.MockCategory()); }
public MetadataControllerTest() { _service = A.Fake <IMetadataService>(); _controller = new MetadataController(_service); _listResponse = new Response { Data = new List <MetaData>() }; _singleResponse = new Response { Data = new MetaData() }; _queryWithDefaultValues = BaseListQuery.DefaultValues("nb"); }
public void GetRequiredCategories_Returns_List_Of_Categories_When_Some_Exists() { Assert.Empty(CategoryRepository.GetAll(BaseListQuery.DefaultValues(_language))); var notRequiredCategory = Mock.MockCategory(); notRequiredCategory.IsRequired = false; var requiredCategory = Mock.MockCategory(); requiredCategory.IsRequired = true; Mock.Database.InsertCategory(requiredCategory); Assert.Single(CategoryRepository.GetRequiredCategories(_language)); }
public ConceptControllerTest() { _tokenHelper = A.Fake <ITokenHelper>(); A.CallTo(() => _tokenHelper.ReturnScope(A <ClaimsPrincipal> ._)).Returns(_allowedScope); A.CallTo(() => _tokenHelper.GetUserInfo()).Returns(new UserInfo()); _service = A.Fake <IConceptService>(); _controller = new ConceptController(_service, _tokenHelper); _createConcept = new CreateConceptDto { Title = "Title", Content = "Content", Created = DateTime.Now, Updated = DateTime.Now, }; _updateConcept = new UpdateConceptDto { Title = "Title", Content = "Content", Created = DateTime.Now, Updated = DateTime.Now, }; _searchQuery = new ConceptSearchQuery { Title = "title", MetaIds = new List <int> { 1, 2 } }; _errorResponse = new Response { Errors = new ModelStateDictionary() }; _errorResponse.Errors.TryAddModelError("err", "err"); _listResponse = new Response { Data = new List <ConceptDto>() }; _singleResponse = new Response { Data = new ConceptDto() }; _userInfo = new UserInfo { Email = _allowedUserEmail, FullName = "Name" }; _listQuery = BaseListQuery.DefaultValues(language); }
public List <MetaData> SearchForMetadata(MetaSearchQuery searchArgument) { var query = TableWithAllNestedObjects() .AsQueryable(); if (searchArgument == null || searchArgument.HasNoQuery()) { return(GetAll(BaseListQuery.DefaultValues(_languageConfig.Default))); } var searchArgsHasName = !string.IsNullOrWhiteSpace(searchArgument.Name); var searchArgsHasCategory = !string.IsNullOrWhiteSpace(searchArgument.Category); if (searchArgsHasCategory) { query = query.Where(x => x.Category.Name.ToLower().Equals(searchArgument.Category.ToLower())); } if (searchArgsHasName) { query = query.Where(x => x.Name.ToLower().Contains(searchArgument.Name.ToLower())); } var totalItems = query.Count(); var totalPages = Convert.ToInt32(Math.Ceiling(totalItems * 1.0 / searchArgument.PageSize)); if (searchArgument.Page > totalPages) { searchArgument.Page = 1; } var offset = searchArgument.PageSize * (searchArgument.Page - 1); var meta = query .OrderBy(x => x.Id) .Skip(offset) .Take(searchArgument.PageSize) .ToList(); meta.ForEach(x => { x.TotalItems = totalItems; x.NumberOfPages = totalPages; }); return(meta); }
public List <Concept> SearchForConcepts(ConceptSearchQuery searchParam) { if (searchParam == null) { return(GetAll(BaseListQuery.DefaultValues(_languageConfig.Default))); } var queryHasTitle = !string.IsNullOrWhiteSpace(searchParam.Title); var queryHasMetaIds = searchParam.MetaIds != null && searchParam.MetaIds.Count > 0; var sqlParameters = searchParam.GetSqlParameters(); if (queryHasTitle && !queryHasMetaIds) { return(GetConceptsByStoredProcedure("get_concepts_by_title", sqlParameters)); } if (!queryHasTitle && queryHasMetaIds) { return(GetConceptsByStoredProcedure("get_concepts_by_list_of_meta_id", sqlParameters)); } if (!queryHasMetaIds && !queryHasTitle) { if (string.IsNullOrEmpty(searchParam.Language)) { searchParam.Language = _languageConfig.Default; } return(GetAll(searchParam)); } // Has metaIds and title var result = GetConceptsByStoredProcedure("get_concepts_by_title_and_meta_id", sqlParameters); // Did not find any results with metaIds. Tries with title only if (result == null || result.Count == 0) { sqlParameters.ForEach(x => x.Collection = null); sqlParameters.RemoveAll(x => x.ParameterName == "list_of_meta_id"); return(GetConceptsByStoredProcedure("get_concepts_by_title", sqlParameters)); } return(result); }
public List <int> MediaTypesNotExistInDatabase(List <MediaWithMediaType> mediaTypes, string language) { var noExistingIds = new List <int>(); if (mediaTypes == null) { return(noExistingIds); } var allMediaTypes = _mediaTypeRepository.GetAll(BaseListQuery.DefaultValues(language)); var pages = 1; try { pages = allMediaTypes.FirstOrDefault().NumberOfPages; } catch { } for (var page = 0; page < pages; page++) { var query = BaseListQuery.DefaultValues(language); query.Page = page + 1; var medias = _mediaTypeRepository .GetAll(query) .Select(x => x.Id) .ToList(); foreach (var mediaType in mediaTypes) { if (!medias.Contains(mediaType.MediaTypeId)) { noExistingIds.Add(mediaType.MediaTypeId); } } } return(noExistingIds); }
public ConceptServiceTest() { ConceptMediaRepository = A.Fake <IConceptMediaRepository>(); ConceptRepository = A.Fake <IConceptRepository>(); StatusRepository = A.Fake <IStatusRepository>(); LanguageRepository = A.Fake <ILanguageRepository>(); MetadataRepository = A.Fake <IMetadataRepository>(); UrlHelper = A.Fake <IUrlHelper>(); Mapper = AutoMapper.Mapper.Instance; Service = new ConceptService(ConceptRepository, StatusRepository, ConceptMediaRepository, MetadataRepository, LanguageRepository, Mapper, UrlHelper); Mock = new Mock.Mock(); _status = new Status(); BaseListQuery = BaseListQuery.DefaultValues("nb"); _language = new Language(); _listOfMetaWithLanguage = new List <MetaData> { new MetaData { Language = _language, Category = new MetaCategory { TypeGroup = new TypeGroup { Name = "language" } } } }; _userInfo = new UserInfo { FullName = "Fullname", Email = "Email" }; A.CallTo(() => StatusRepository.GetById(A <int> ._)).Returns(null); A.CallTo(() => MetadataRepository.GetByRangeOfIds(A <List <int> > ._)).Returns(_listOfMetaWithLanguage); A.CallTo(() => LanguageRepository.GetByAbbreviation(A <string> ._)).Returns(_language); }