Пример #1
0
 public ServicePayPaymentRepository(ContentfulConfig config,
                                    IContentfulClientManager clientManager,
                                    IContentfulFactory <ContentfulServicePayPayment, ServicePayPayment> servicePayPaymentFactory)
 {
     _client = clientManager.GetClient(config);
     _servicePayPaymentFactory = servicePayPaymentFactory;
 }
Пример #2
0
        public ContentfulService(IHostingEnvironment hostingEnvironment, ICacheService cacheService, IOptions <ContentfulConfig> contentfulConfig, IBaseClient baseClient)
        {
            _hostingEnvironment = hostingEnvironment;
            _cacheService       = cacheService;
            _contentfulConfig   = contentfulConfig.Value;

            _imageDBPath = _hostingEnvironment.WebRootPath + "/data/header-images.json";

            // Build Contentful client
            var options = new ContentfulOptions()
            {
                UsePreviewApi  = false,
                DeliveryApiKey = _contentfulConfig.DeliveryApiKey,
                SpaceId        = _contentfulConfig.SpaceId
            };

            _client = new ContentfulClient(baseClient.GetHttpClient(), options);

            // Build Contentful preview client
            var previewOptions = new ContentfulOptions()
            {
                UsePreviewApi = true,
                PreviewApiKey = _contentfulConfig.PreviewApiKey,
                SpaceId       = _contentfulConfig.SpaceId
            };

            _previewClient = new ContentfulClient(baseClient.GetHttpClient(), previewOptions);
        }
 public PaymentRepository(ContentfulConfig config,
                          IContentfulClientManager clientManager,
                          IContentfulFactory <ContentfulPayment, Payment> paymentFactory)
 {
     _client         = clientManager.GetClient(config);
     _paymentFactory = paymentFactory;
 }
Пример #4
0
        public PaymentRepositoryTest()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _alertFactory = new Mock <IContentfulFactory <ContentfulAlert, Alert> >();
            _timeProvider = new Mock <ITimeProvider>();
            _crumbFactory = new Mock <IContentfulFactory <ContentfulReference, Crumb> >();

            _crumbFactory.Setup(o => o.ToModel(It.IsAny <ContentfulReference>()))
            .Returns(new Crumb("title", "slug", "title"));

            var contentfulFactory = new PaymentContentfulFactory(_alertFactory.Object, _timeProvider.Object, _crumbFactory.Object);

            _httpClient = new Mock <IHttpClient>();

            var contentfulClientManager = new Mock <IContentfulClientManager>();

            _contentfulClient = new Mock <IContentfulClient>();
            contentfulClientManager.Setup(o => o.GetClient(config)).Returns(_contentfulClient.Object);
            _repository = new PaymentRepository
                          (
                config,
                contentfulClientManager.Object,
                contentfulFactory
                          );
        }
        private async Task <Group> GetGroup(string groupSlug, ContentfulConfig config)
        {
            var groupRepository = _groupRepository(config);
            var groupResponse   = await groupRepository.GetGroup(groupSlug, false);

            return(groupResponse.Get <Group>());
        }
        private async Task <Asset> GetDocumentAsAsset(string assetId, ContentfulConfig config)
        {
            var repository    = _documentRepository(config);
            var assetResponse = await repository.Get(assetId);

            return(assetResponse);
        }
Пример #7
0
        public GroupRepositoryTest()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _groupFactory         = new Mock <IContentfulFactory <ContentfulGroup, Group> >();
            _eventFactory         = new Mock <IContentfulFactory <ContentfulEvent, Event> >();
            _eventHomepageFactory = new Mock <IContentfulFactory <ContentfulEventHomepage, EventHomepage> >();

            _timeProvider                   = new Mock <ITimeProvider>();
            _httpClient                     = new Mock <IHttpClient>();
            _groupCategoryFactory           = new Mock <IContentfulFactory <ContentfulGroupCategory, GroupCategory> >();
            _groupHomepageContentfulFactory = new Mock <IContentfulFactory <ContentfulGroupHomepage, GroupHomepage> >();
            _logger = new Mock <ILogger <EventRepository> >();

            _cacheWrapper  = new Mock <ICache>();
            _configuration = new Mock <IConfiguration>();
            _configuration.Setup(_ => _["redisExpiryTimes:Groups"]).Returns("60");
            _configuration.Setup(_ => _["redisExpiryTimes:Events"]).Returns("60");
            var contentfulClientManager = new Mock <IContentfulClientManager>();

            _client = new Mock <IContentfulClient>();
            contentfulClientManager.Setup(o => o.GetClient(config)).Returns(_client.Object);

            _eventRepository = new EventRepository(config, contentfulClientManager.Object, _timeProvider.Object, _eventFactory.Object, _eventHomepageFactory.Object, _cacheWrapper.Object, _logger.Object, _configuration.Object);
            _repository      = new GroupRepository(config, contentfulClientManager.Object, _timeProvider.Object, _groupFactory.Object, _groupCategoryFactory.Object, _groupHomepageContentfulFactory.Object, _eventRepository, _cacheWrapper.Object, _configuration.Object);
        }
        public EventRepositoryTest()
        {
            // Arrange
            _config = new ContentfulConfig("test")
                      .Add("DELIVERY_URL", "https://fake.url")
                      .Add("TEST_SPACE", "SPACE")
                      .Add("TEST_ACCESS_KEY", "KEY")
                      .Add("TEST_MANAGEMENT_KEY", "KEY")
                      .Build();

            // Mock
            _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2017, 01, 01));

            _alertFactory.Setup(o => o.ToModel(It.IsAny <ContentfulAlert>())).Returns(new Alert("title", "subHeading", "body",
                                                                                                "severity", new DateTime(0001, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                                                                                                new DateTime(9999, 9, 9, 0, 0, 0, DateTimeKind.Utc), string.Empty, false));

            // TODO: Make this into a mock instead of concrete class, will need refactor to tests with this also
            var contentfulFactory    = new EventContentfulFactory(_documentFactory.Object, _groupFactory.Object, _eventCategoryFactory.Object, _alertFactory.Object, _mockTimeProvider.Object);
            var eventHomepageFactory = new EventHomepageContentfulFactory(_mockTimeProvider.Object);

            _contentfulClientManager.Setup(o => o.GetClient(_config)).Returns(_contentfulClient.Object);
            _eventCategoryFactory.Setup(o => o.ToModel(It.IsAny <ContentfulEventCategory>())).Returns(new EventCategory("", "", ""));
            _configuration.Setup(_ => _["redisExpiryTimes:Articles"]).Returns("60");
            _configuration.Setup(_ => _["redisExpiryTimes:Events"]).Returns("60");

            _repository = new EventRepository(_config, _contentfulClientManager.Object,
                                              _mockTimeProvider.Object, contentfulFactory, eventHomepageFactory, _cacheWrapper.Object, _logger.Object, _configuration.Object);
        }
Пример #9
0
 public TopicRepository(ContentfulConfig config, IContentfulClientManager clientManager,
                        IContentfulFactory <ContentfulTopic, Topic> topicFactory,
                        IContentfulFactory <ContentfulTopicForSiteMap, TopicSiteMap> topicSiteMapFactory)
 {
     _client              = clientManager.GetClient(config);
     _topicFactory        = topicFactory;
     _topicSiteMapFactory = topicSiteMapFactory;
 }
 public EventCategoryRepository(ContentfulConfig config, IContentfulFactory <ContentfulEventCategory, EventCategory> contentfulFactory, IContentfulClientManager contentfulClientManager, ICache cache, IConfiguration configuration)
 {
     _contentfulFactory = contentfulFactory;
     _client            = contentfulClientManager.GetClient(config);
     _configuration     = configuration;
     int.TryParse(_configuration["redisExpiryTimes:Events"], out _eventsCategoryTimeout);
     _cache = cache;
 }
        private async Task <bool> DoesGroupReferenceAsset(string groupSlug, ContentfulConfig config, Asset asset)
        {
            var group = await GetGroup(groupSlug, config);

            var assetExistsInGroup = group.AdditionalDocuments.Exists(o => o.AssetId == asset.SystemProperties.Id);

            return(assetExistsInGroup);
        }
Пример #12
0
 public SectionRepository(ContentfulConfig config,
                          IContentfulFactory <ContentfulSection, Section> SectionBuilder,
                          IContentfulClientManager contentfulClientManager,
                          ITimeProvider timeProvider)
 {
     _dateComparer      = new DateComparer(timeProvider);
     _contentfulFactory = SectionBuilder;
     _client            = contentfulClientManager.GetClient(config);
 }
Пример #13
0
 public OrganisationRepository(ContentfulConfig config,
                               IContentfulFactory <ContentfulOrganisation, Organisation> contentfulFactory,
                               IContentfulClientManager contentfulClientManager,
                               IGroupRepository groupRepository)
 {
     _contentfulFactory = contentfulFactory;
     _client            = contentfulClientManager.GetClient(config);
     _groupRepository   = groupRepository;
 }
        public IContentfulClient GetClient(ContentfulConfig config)
        {
            bool.TryParse(_configuration["Contentful:UsePreviewAPI"], out var usePreviewApi);
            var client = new ContentfulClient(_httpClient, !usePreviewApi ? config.AccessKey : "", usePreviewApi ? config.AccessKey : "", config.SpaceKey, usePreviewApi)
            {
                ResolveEntriesSelectively = true
            };

            return(client);
        }
 public DocumentPageRepository(ContentfulConfig config,
                               IContentfulClientManager contentfulClientManager,
                               ITimeProvider timeProvider,
                               IContentfulFactory <ContentfulDocumentPage, DocumentPage> contentfulFactory,
                               ICache cache)
 {
     _contentfulFactory = contentfulFactory;
     _dateComparer      = new DateComparer(timeProvider);
     _client            = contentfulClientManager.GetClient(config);
     _cache             = cache;
 }
        private async Task <bool> IsUserAdvisorForGroup(string groupSlug, ContentfulConfig config, LoggedInPerson user)
        {
            if (string.IsNullOrEmpty(user.Email))
            {
                return(false);
            }

            var groupAdvisorsRepository = _groupAdvisorRepository(config);
            var groupAdvisorResponse    = await groupAdvisorsRepository.CheckIfUserHasAccessToGroupBySlug(groupSlug, user.Email);

            return(groupAdvisorResponse);
        }
Пример #17
0
 public NewsRepository(ContentfulConfig config, ITimeProvider timeProvider, IContentfulClientManager contentfulClientManager,
                       IContentfulFactory <ContentfulNews, News> newsContentfulFactory, IContentfulFactory <ContentfulNewsRoom, Newsroom> newsRoomContentfulFactory, ICache cache, IConfiguration configuration)
 {
     _timeProvider              = timeProvider;
     _newsContentfulFactory     = newsContentfulFactory;
     _newsRoomContentfulFactory = newsRoomContentfulFactory;
     _dateComparer              = new DateComparer(timeProvider);
     _client        = contentfulClientManager.GetClient(config);
     _cache         = cache;
     _configuration = configuration;
     int.TryParse(_configuration["redisExpiryTimes:News"], out _newsTimeout);
 }
Пример #18
0
 public AtoZRepository(ContentfulConfig config, IContentfulClientManager clientManager,
                       IContentfulFactory <ContentfulAtoZ, AtoZ> contentfulAtoZFactory,
                       ITimeProvider timeProvider, ICache cache, IConfiguration configuration, ILogger logger)
 {
     _client                = clientManager.GetClient(config);
     _contentfulApiUrl      = config.ContentfulUrl.ToString();
     _contentfulAtoZFactory = contentfulAtoZFactory;
     _dateComparer          = new DateComparer(timeProvider);
     _cache         = cache;
     _configuration = configuration;
     _logger        = logger;
     int.TryParse(_configuration["redisExpiryTimes:AtoZ"], out _atoZTimeout);
 }
 public ShowcaseRepository(ContentfulConfig config,
                           IContentfulFactory <ContentfulShowcase, Showcase> showcaseBuilder,
                           IContentfulClientManager contentfulClientManager,
                           IContentfulFactory <ContentfulNews, News> newsBuilder,
                           EventRepository eventRepository,
                           ILogger <ShowcaseRepository> logger)
 {
     _contentfulFactory = showcaseBuilder;
     _newsFactory       = newsBuilder;
     _client            = contentfulClientManager.GetClient(config);
     _eventRepository   = eventRepository;
     _logger            = logger;
 }
Пример #20
0
        public GroupAdvisorRepositoryTests()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _contentfulClientManager.Setup(o => o.GetClient(config)).Returns(_client.Object);

            _reporisory = new GroupAdvisorRepository(config, _contentfulClientManager.Object, _contentfulFactory.Object);
        }
Пример #21
0
        public CommsRepositoryTests()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _mockClientManager.Setup(_ => _.GetClient(It.IsAny <ContentfulConfig>())).Returns(_mockClient.Object);

            _repository = new CommsRepository(config, _mockClientManager.Object, _mockCommsHomepageFactory.Object);
        }
        public RedirectsRepositoryTest()
        {
            _config = new ContentfulConfig("unittest")
                      .Add("DELIVERY_URL", "https://fake.url")
                      .Add("UNITTEST_SPACE", "SPACE")
                      .Add("UNITTEST_ACCESS_KEY", "KEY")
                      .Add("UNITTEST_MANAGEMENT_KEY", "KEY")
                      .Build();

            _createConfig            = new Mock <Func <string, ContentfulConfig> >();
            _contenfulFactory        = new Mock <IContentfulFactory <ContentfulRedirect, BusinessIdToRedirects> >();
            _contentfulClientManager = new Mock <IContentfulClientManager>();
            _client = new Mock <IContentfulClient>();
            _createConfig.Setup(o => o(It.IsAny <string>())).Returns(_config);
            _contentfulClientManager.Setup(o => o.GetClient(_config)).Returns(_client.Object);
        }
Пример #23
0
        public ProfileRepositoryTest()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _profileFactory = new Mock <IContentfulFactory <ContentfulProfile, Profile> >();
            var contentfulClientManager = new Mock <IContentfulClientManager>();

            _client = new Mock <IContentfulClient>();
            contentfulClientManager.Setup(o => o.GetClient(config)).Returns(_client.Object);

            _repository = new ProfileRepository(config, contentfulClientManager.Object, _profileFactory.Object);
        }
Пример #24
0
 public EventRepository(ContentfulConfig config,
                        IContentfulClientManager contentfulClientManager, ITimeProvider timeProvider,
                        IContentfulFactory <ContentfulEvent, Event> contentfulFactory,
                        IContentfulFactory <ContentfulEventHomepage, EventHomepage> contentfulEventHomepageFactory,
                        ICache cache,
                        ILogger <EventRepository> logger, IConfiguration configuration)
 {
     _contentfulFactory = contentfulFactory;
     _contentfulEventHomepageFactory = contentfulEventHomepageFactory;
     _dateComparer  = new DateComparer(timeProvider);
     _client        = contentfulClientManager.GetClient(config);
     _cache         = cache;
     _logger        = logger;
     _configuration = configuration;
     int.TryParse(_configuration["redisExpiryTimes:Events"], out _eventsTimeout);
     _timeProvider = timeProvider;
 }
Пример #25
0
 public ArticleRepository(ContentfulConfig config,
                          IContentfulClientManager contentfulClientManager,
                          ITimeProvider timeProvider,
                          IContentfulFactory <ContentfulArticle, Article> contentfulFactory,
                          IContentfulFactory <ContentfulArticleForSiteMap, ArticleSiteMap> contentfulFactoryArticle,
                          IVideoRepository videoRepository,
                          ICache cache,
                          IConfiguration configuration)
 {
     _contentfulFactory        = contentfulFactory;
     _dateComparer             = new DateComparer(timeProvider);
     _client                   = contentfulClientManager.GetClient(config);
     _videoRepository          = videoRepository;
     _contentfulFactoryArticle = contentfulFactoryArticle;
     _cache         = cache;
     _configuration = configuration;
     int.TryParse(_configuration["redisExpiryTimes:Articles"], out _articleTimeout);
 }
Пример #26
0
        public void BuildsContentfulUrlForBusinessIdBasedOnEnvironmentVariables()
        {
            var key   = "KEY";
            var space = "SPACE";

            var config = new ContentfulConfig("testid")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TESTID_ACCESS_KEY", key)
                         .Add("TESTID_MANAGEMENT_KEY", "KEY")
                         .Add("TESTID_SPACE", space)
                         .Build();
            var expectedResult = "https://fake.url/spaces/SPACE/entries?access_token=KEY";

            config.AccessKey.Should().Be(key);
            config.SpaceKey.Should().Be(space);

            Assert.Equal(config.ContentfulUrl.ToString(), expectedResult);
        }
        //private const string MockContentfulApiUrl = "https://fake.url/spaces/SPACE/entries?access_token=KEY";

        public AtoZRepositoryTest()
        {
            _config = new ContentfulConfig("test")
                      .Add("DELIVERY_URL", "https://fake.url")
                      .Add("TEST_SPACE", "SPACE")
                      .Add("TEST_ACCESS_KEY", "KEY")
                      .Add("TEST_MANAGEMENT_KEY", "KEY")
                      .Build();

            _configuration = new Mock <IConfiguration>();
            _configuration.Setup(_ => _["redisExpiryTimes:AtoZ"]).Returns("60");
            _cache = new Mock <ICache>();

            _contentfulClientManager = new Mock <IContentfulClientManager>();
            _client = new Mock <IContentfulClient>();
            _contentfulClientManager.Setup(o => o.GetClient(_config)).Returns(_client.Object);
            _aToZFactory = new Mock <IContentfulFactory <ContentfulAtoZ, AtoZ> >();
            _logger      = new Mock <ILogger>();
        }
Пример #28
0
        public GroupCategoryRepositoryTest()
        {
            var config = new ContentfulConfig("test")
                         .Add("DELIVERY_URL", "https://fake.url")
                         .Add("TEST_SPACE", "SPACE")
                         .Add("TEST_ACCESS_KEY", "KEY")
                         .Add("TEST_MANAGEMENT_KEY", "KEY")
                         .Build();

            _httpClient = new Mock <IHttpClient>();

            var contentfulClientManager = new Mock <IContentfulClientManager>();

            _contentfulClient = new Mock <IContentfulClient>();
            _contentfulGroupCategoryFactory = new Mock <IContentfulFactory <ContentfulGroupCategory, GroupCategory> >();
            contentfulClientManager.Setup(o => o.GetClient(config)).Returns(_contentfulClient.Object);

            _repository = new GroupCategoryRepository(config, _contentfulGroupCategoryFactory.Object, contentfulClientManager.Object);
        }
Пример #29
0
        public void ShouldReturnClient()
        {
            var _configuration = new Mock <IConfiguration>();
            var httpClient     = new HttpClient();
            var manager        = new ContentfulClientManager(httpClient, _configuration.Object);
            var config         = new ContentfulConfig("test")
                                 .Add("DELIVERY_URL", "https://test.url")
                                 .Add("TEST_SPACE", "SPACE")
                                 .Add("TEST_ACCESS_KEY", "KEY")
                                 .Add("TEST_MANAGEMENT_KEY", "KEY")
                                 .Build();

            var contenfulClient = manager.GetClient(config);

            contenfulClient.Should().BeEquivalentTo(new Contentful.Core.ContentfulClient(httpClient, "", config.AccessKey, config.SpaceKey)
            {
                ResolveEntriesSelectively = true
            });
        }
Пример #30
0
 public GroupRepository(ContentfulConfig config, IContentfulClientManager clientManager,
                        ITimeProvider timeProvider,
                        IContentfulFactory <ContentfulGroup, Group> groupFactory,
                        IContentfulFactory <ContentfulGroupCategory, GroupCategory> groupCategoryFactory,
                        IContentfulFactory <ContentfulGroupHomepage, GroupHomepage> groupHomepageContentfulFactory,
                        EventRepository eventRepository,
                        ICache cache,
                        IConfiguration configuration
                        )
 {
     _dateComparer         = new DateComparer(timeProvider);
     _client               = clientManager.GetClient(config);
     _groupFactory         = groupFactory;
     _groupCategoryFactory = groupCategoryFactory;
     _eventRepository      = eventRepository;
     _cache         = cache;
     _configuration = configuration;
     int.TryParse(_configuration["redisExpiryTimes:Groups"], out _groupsTimeout);
     _groupHomepageContentfulFactory = groupHomepageContentfulFactory;
 }