Пример #1
0
        public ShowcaseViewModel(INetworkActivityService networkActivity, ShowcaseRepository showcaseRepository)
        {
            Title = "Showcase";

            GoToRepositoryCommand = ReactiveCommand.Create();
            GoToRepositoryCommand.OfType <Octokit.Repository>().Subscribe(x =>
            {
                var vm = CreateViewModel <RepositoryViewModel>();
                vm.RepositoryIdentifier = new BaseRepositoryViewModel.RepositoryIdentifierModel(x.Owner.Login, x.Name);
                ShowViewModel(vm);
            });

            var repositories = new ReactiveList <Octokit.Repository>();

            Repositories = repositories;
            LoadCommand  = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var showcaseRepos = await showcaseRepository.GetShowcaseRepositories(ShowcaseSlug);
                Title             = showcaseRepos.Name;
                Showcase          = new Showcase {
                    Slug = showcaseRepos.Slug, Description = showcaseRepos.Description, Name = showcaseRepos.Name
                };
                repositories.Reset(showcaseRepos.Repositories);
            });
            LoadCommand.TriggerNetworkActivity(networkActivity);
        }
Пример #2
0
        public ShowcasesViewModel(INetworkActivityService networkActivity, ShowcaseRepository showcaseRepository)
        {
            GoToShowcaseCommand = ReactiveCommand.Create();
            GoToShowcaseCommand.OfType <Showcase>().Subscribe(x =>
            {
                var vm          = CreateViewModel <ShowcaseViewModel>();
                vm.ShowcaseSlug = x.Slug;
                vm.Title        = x.Name;
                ShowViewModel(vm);
            });

            var showcases = new ReactiveList <Showcase>();

            Showcases = showcases;

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
                                                          showcases.Reset(await showcaseRepository.GetShowcases()));
            LoadCommand.TriggerNetworkActivity(networkActivity);
        }
        public ShowcaseRepositoryTest()
        {
            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>();
            _topicFactory         = new Mock <IContentfulFactory <ContentfulReference, SubItem> >();
            _crumbFactory         = new Mock <IContentfulFactory <ContentfulReference, Crumb> >();
            _timeprovider         = new Mock <ITimeProvider>();
            _eventHomepageFactory = new Mock <IContentfulFactory <ContentfulEventHomepage, EventHomepage> >();
            _alertFactory         = new Mock <IContentfulFactory <ContentfulAlert, Alert> >();
            _mockLogger           = new Mock <ILogger <ShowcaseRepository> >();
            _timeprovider.Setup(o => o.Now()).Returns(new DateTime(2017, 03, 30));

            var socialMediaFactory = new Mock <IContentfulFactory <ContentfulSocialMediaLink, SocialMediaLink> >();

            socialMediaFactory.Setup(o => o.ToModel(It.IsAny <ContentfulSocialMediaLink>())).Returns(new SocialMediaLink("sm-link-title", "sm-link-slug", "sm-link-icon", "https://link.url", "sm-link-accountName", "sm-link-screenReader"));

            _alertFactory.Setup(o => o.ToModel(It.IsAny <ContentfulAlert>())).Returns(new Alert("title", "", "", "", DateTime.MinValue, DateTime.MaxValue, string.Empty, false));

            var _videoFactory = new Mock <IContentfulFactory <ContentfulVideo, Video> >();

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

            var _triviaFactory = new Mock <IContentfulFactory <ContentfulTrivia, Trivia> >();

            var callToActionBanner = new Mock <IContentfulFactory <ContentfulCallToActionBanner, CallToActionBanner> >();

            callToActionBanner.Setup(_ => _.ToModel(It.IsAny <ContentfulCallToActionBanner>())).Returns(
                new CallToActionBanner
            {
                Title      = "title",
                AltText    = "altText",
                ButtonText = "button text",
                Image      = "url",
                Link       = "url"
            });

            var spotlightBannerFactory = new Mock <IContentfulFactory <ContentfulSpotlightBanner, SpotlightBanner> >();

            var contentfulFactory = new ShowcaseContentfulFactory(_topicFactory.Object, _crumbFactory.Object, _timeprovider.Object, socialMediaFactory.Object, _alertFactory.Object, _profileFactory.Object, _triviaFactory.Object, callToActionBanner.Object, _videoFactory.Object, spotlightBannerFactory.Object);

            var newsListFactory = new Mock <IContentfulFactory <ContentfulNews, News> >();

            var contentfulClientManager = new Mock <IContentfulClientManager>();

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

            _eventFactory = new Mock <IContentfulFactory <ContentfulEvent, Event> >();
            _cacheWrapper = new Mock <ICache>();

            var _logger = new Mock <ILogger <EventRepository> >();

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

            var eventRepository = new EventRepository(config, contentfulClientManager.Object, _timeprovider.Object, _eventFactory.Object, _eventHomepageFactory.Object, _cacheWrapper.Object, _logger.Object, _configuration.Object);

            _repository = new ShowcaseRepository(config, contentfulFactory, contentfulClientManager.Object, newsListFactory.Object, eventRepository, _mockLogger.Object);
        }