示例#1
0
 public static void Define <TFrom, TTo>(this UmbracoMapper mapper, Action <TFrom, TTo, MapperContext> map)
     where TTo : new()
 {
     mapper.Define(
         (src, ctx) => new TTo(),
         map
         );
 }
示例#2
0
 public override void SetUp()
 {
     base.SetUp();
     this._viewModelFactory = new Mock <IBaseContentPageViewModelFactory <TContentPage> >();
     this._viewModelFactory.Setup(x => x.CreateModel(It.IsAny <TContentPage>(), null)).Returns(this._mockedViewModel);
     this._umbracoMapper = new UmbracoMapperComposer().SetupMapper();
     this._sut           = new BaseContentPageController <TContentPage>(this._umbracoMapper, _viewModelFactory.Object);
 }
        public GoogleMapsController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor,
                                    ISqlContext sqlContext, ServiceContext services, GoogleMapsConfig settings,
                                    AppCaches appCaches, IProfilingLogger logger, global::Umbraco.Core.IRuntimeState runtimeState,
                                    UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper) :
            base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper)
#endif
        {
            this.googleMapsConfig = settings;
        }
示例#4
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     // just some random things so that the mapper contains things
     mapper.Define <int, object>();
     mapper.Define <string, object>();
     mapper.Define <double, object>();
     mapper.Define <UmbracoMapper, object>();
     mapper.Define <Property, object>();
 }
示例#5
0
    public void CollectionsMap()
    {
        var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition2() });
        var mapper      = new UmbracoMapper(definitions, _scopeProvider);

        // can map a PropertyCollection
        var source = new PropertyCollection();
        var target = mapper.Map <IEnumerable <ContentPropertyDto> >(source);
    }
示例#6
0
        public override void SetUp()
        {
            base.SetUp();
            this._umbracoMapper     = new UmbracoMapperComposer().SetupMapper();
            this._umbracoHelperMock = new Mock <IUmbracoHelper>();
            var content = this.SetupContent(DocumentTypeAlias.GlobalSettingsPage, this.SetupPropertyValue(GlobalSettingsPagePropertyAlias.HomeTextAlias, "Home text"));

            this._umbracoHelperMock.Setup(x => x.GlobalSettingsPage).Returns(content.Content);
        }
示例#7
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define <IStylesheet, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <IPartialView, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
     mapper.Define <IScript, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
     mapper.Define <IStylesheet, CodeFileDisplay>((source, context) => new CodeFileDisplay(), Map);
     mapper.Define <CodeFileDisplay, IPartialView>(Map);
     mapper.Define <CodeFileDisplay, IScript>(Map);
 }
示例#8
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define<MembershipUser, MemberDisplay>((source, context) => new MemberDisplay(), Map);
     mapper.Define<MembershipUser, IMember>((source, context) => MemberService.CreateGenericMembershipProviderMember(source.UserName, source.Email, source.UserName, ""), Map);
     mapper.Define<IMember, MemberDisplay>((source, context) => new MemberDisplay(), Map);
     mapper.Define<IMember, MemberBasic>((source, context) => new MemberBasic(), Map);
     mapper.Define<MembershipUser, MemberBasic>((source, context) => new MemberBasic(), Map);
     mapper.Define<IMemberGroup, MemberGroupDisplay>((source, context) => new MemberGroupDisplay(), Map);
     mapper.Define<IMember, ContentPropertyCollectionDto>((source, context) => new ContentPropertyCollectionDto(), Map);
 }
        public void DefineMaps(UmbracoMapper mapper)
        {
            mapper.Define <ISearchResult, IPublishedContent>((source, context) => _publishedContentHelper.GetByString(source.Id));

            mapper.Define <string, IPublishedContent>((source, context) => _publishedContentHelper.GetByString(source));

            mapper.Define <Guid, IPublishedContent>((source, context) => _publishedContentHelper.GetByGuid(source));

            mapper.Define <Udi, IPublishedContent>((source, context) => _publishedContentHelper.GetByUdi(source));
        }
示例#10
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define <HomePage, InitViewModel>(InitViewModelMapper.Instance.Map);
     mapper.Define <HomePage, SitemapViewModel>(SitemapViewModelMapper.Instance.Map);
     mapper.Define <HomePage, HomePageViewModel>(HomePageViewModelMapping.Instance.Map);
     mapper.Define <BlogPostPage, BlogPostPageViewModel>(BlogPostPageViewModelMapping.Instance.Map);
     mapper.Define <StandardPage, StandardPageViewModel>(StandardPageViewModelMapping.Instance.Map);
     mapper.Define <Page, BasicNodeViewModel>(BasicNodeViewModelMapper.Instance.Map);
     mapper.Define <Page, BasePageViewModel>(BasePageViewModelMapper.Instance.Map);
 }
示例#11
0
 public ProductService(
     IUmbracoContextFactory umbracoContextFactory,
     UmbracoMapper umbracoMapper,
     ILogger logger,
     IContentService contentService)
 {
     _umbracoMapper         = umbracoMapper ?? throw new System.ArgumentNullException(nameof(umbracoMapper));
     _umbracoContextFactory = umbracoContextFactory ?? throw new System.ArgumentNullException(nameof(umbracoContextFactory));
     _logger         = logger ?? throw new System.ArgumentNullException(nameof(logger));
     _contentService = contentService ?? throw new System.ArgumentNullException(nameof(contentService));
 }
示例#12
0
 public UmbracoTreeSearcher(
     IExamineManager examineManager,
     UmbracoContext umbracoContext,
     ILocalizationService languageService,
     IEntityService entityService,
     UmbracoMapper mapper,
     ISqlContext sqlContext,
     IUmbracoTreeSearcherFields umbracoTreeSearcherFields)
     : this(examineManager, umbracoContext, languageService, entityService, mapper, sqlContext, umbracoTreeSearcherFields, Current.AppCaches)
 {
 }
        public virtual void Setup()
        {
            SetupHttpContext();
            SetupCultureDictionaries();
            SetupPublishedContentQuerying();
            SetupMembership();

            ServiceContext = ServiceContext.CreatePartial(memberService: MemberService.Object);
            UmbracoHelper  = new UmbracoHelper(Mock.Of <IPublishedContent>(), Mock.Of <ITagQuery>(), CultureDictionaryFactory.Object, Mock.Of <IUmbracoComponentRenderer>(), PublishedContentQuery.Object, MembershipHelper);
            UmbracoMapper  = new UmbracoMapper(new MapDefinitionCollection(new List <IMapDefinition>()), Mock.Of <IScopeProvider>());
        }
示例#14
0
        public virtual void SetUp()
        {
            this.SetupHttpContext();
            this.SetupCultureDictionaries();
            this.SetupPublishedContentQuerying();
            this.SetupMembership();

            this.ServiceContext = ServiceContext.CreatePartial();
            this.UmbracoHelper  = new Umbraco.Web.UmbracoHelper(Mock.Of <IPublishedContent>(), Mock.Of <ITagQuery>(), this.CultureDictionaryFactory.Object, Mock.Of <IUmbracoComponentRenderer>(), this.PublishedContentQuery.Object, this.MembershipHelper);
            this.UmbracoMapper  = new UmbracoMapper(new MapDefinitionCollection(new List <IMapDefinition>()));
        }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UmbracoApiControllerBase"/> class with all its dependencies.
 /// </summary>
 protected UmbracoApiControllerBase(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper)
 {
     UmbracoContextAccessor = umbracoContextAccessor;
     GlobalSettings         = globalSettings;
     SqlContext             = sqlContext;
     Services     = services;
     AppCaches    = appCaches;
     Logger       = logger;
     RuntimeState = runtimeState;
     Umbraco      = umbracoHelper;
     Mapper       = umbracoMapper;
 }
示例#16
0
    public void NullPropertyMap()
    {
        var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition5() });
        var mapper      = new UmbracoMapper(definitions, _scopeProvider);

        var thing7 = new Thing7();

        var thing8 = mapper.Map <Thing7, Thing8>(thing7);

        Assert.IsNotNull(thing8);
        Assert.IsNull(thing8.Things);
    }
示例#17
0
 public UmbracoTreeSearcher(IExamineManager examineManager,
                            UmbracoContext umbracoContext,
                            ILocalizationService languageService,
                            IEntityService entityService,
                            UmbracoMapper mapper)
 {
     _examineManager  = examineManager ?? throw new ArgumentNullException(nameof(examineManager));
     _umbracoContext  = umbracoContext;
     _languageService = languageService;
     _entityService   = entityService;
     _mapper          = mapper;
 }
示例#18
0
        public void Can_Mock_UmbracoApiController_Dependencies_With_Injected_UmbracoMapper()
        {
            var umbracoContext = TestObjects.GetUmbracoContextMock();

            var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of <IPublishedMemberCache>(), Mock.Of <MembershipProvider>(), Mock.Of <RoleProvider>(), Mock.Of <IMemberService>(), Mock.Of <IMemberTypeService>(), Mock.Of <IUserService>(), Mock.Of <IPublicAccessService>(), Mock.Of <AppCaches>(), Mock.Of <ILogger>());
            var umbracoHelper    = new UmbracoHelper(Mock.Of <IPublishedContent>(), Mock.Of <ITagQuery>(), Mock.Of <ICultureDictionaryFactory>(), Mock.Of <IUmbracoComponentRenderer>(), Mock.Of <IPublishedContentQuery>(), membershipHelper);
            var umbracoMapper    = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of <IMapDefinition>() }));

            // ReSharper disable once UnusedVariable
            var umbracoApiController = new FakeUmbracoApiController(Mock.Of <IGlobalSettings>(), Mock.Of <IUmbracoContextAccessor>(), Mock.Of <ISqlContext>(), ServiceContext.CreatePartial(), AppCaches.NoCache, Mock.Of <IProfilingLogger>(), Mock.Of <IRuntimeState>(), umbracoHelper, umbracoMapper);

            Assert.Pass();
        }
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define <HeadRestOptions, HeadRestConfig>(
         (src, ctx) => new HeadRestConfig(),
         (src, dst, ctx) =>
     {
         dst.Mode                = src.Mode;
         dst.ControllerType      = src.ControllerType;
         dst.Mapper              = src.Mapper;
         dst.ViewModelMappings   = src.ViewModelMappings;
         dst.CustomRouteMappings = src.CustomRouteMappings;
     });
 }
示例#20
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define <IEntitySlim, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <PropertyType, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <PropertyGroup, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <IUser, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <ITemplate, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <EntityBasic, ContentTypeSort>((source, context) => new ContentTypeSort(), Map);
     mapper.Define <IContentTypeComposition, EntityBasic>((source, context) => new EntityBasic(), Map);
     mapper.Define <IEntitySlim, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
     mapper.Define <ISearchResult, SearchResultEntity>((source, context) => new SearchResultEntity(), Map);
     mapper.Define <ISearchResults, IEnumerable <SearchResultEntity> >((source, context) => context.MapEnumerable <ISearchResult, SearchResultEntity>(source));
     mapper.Define <IEnumerable <ISearchResult>, IEnumerable <SearchResultEntity> >((source, context) => context.MapEnumerable <ISearchResult, SearchResultEntity>(source));
 }
示例#21
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define <IDataEditor, PropertyEditorBasic>((source, context) => new PropertyEditorBasic(), Map);
     mapper.Define <ConfigurationField, DataTypeConfigurationFieldDisplay>((source, context) => new DataTypeConfigurationFieldDisplay(), Map);
     mapper.Define <IDataEditor, DataTypeBasic>((source, context) => new DataTypeBasic(), Map);
     mapper.Define <IDataType, DataTypeBasic>((source, context) => new DataTypeBasic(), Map);
     mapper.Define <IDataType, DataTypeDisplay>((source, context) => new DataTypeDisplay(), Map);
     mapper.Define <IDataType, IEnumerable <DataTypeConfigurationFieldDisplay> >(MapPreValues);
     mapper.Define <DataTypeSave, IDataType>((source, context) => new DataType(_propertyEditors[source.EditorAlias])
     {
         CreateDate = DateTime.Now
     }, Map);
     mapper.Define <IDataEditor, IEnumerable <DataTypeConfigurationFieldDisplay> >(MapPreValues);
 }
        /// <summary>
        /// Maps a menu item from a content node
        /// </summary>
        /// <param name="item">Content node to map from</param>
        /// <returns></returns>
        private MenuItemViewModel MapItem(IPublishedContent item)
        {
            MenuItemViewModel model = null;

            if (item != null)
            {
                model = new MenuItemViewModel();
                UmbracoMapper.Map(item, model);
                model.IsCurrentPage           = CurrentPage.Id.Equals(item.Id);
                model.IsCurrentPageOrAncestor = CurrentPage.Path.Contains(item.Id.ToString());
            }

            return(model);
        }
        private void ConfigureTwoFactorAuthentication(object sender, OwinMiddlewareConfiguredEventArgs args)
        {
            var app = args.AppBuilder;
            var applicationContext = Umbraco.Core.Composing.Current.Services;

            IGlobalSettings         GlobalSettings  = Umbraco.Core.Composing.Current.Configs.Global();
            IUmbracoSettingsSection UmbracoSettings = Umbraco.Core.Composing.Current.Configs.Settings();
            UmbracoMapper           umbracoMapper   = Umbraco.Core.Composing.Current.Mapper;

            //netser/////////////////////////

            /* var oAuthServerOptions = new OAuthAuthorizationServerOptions
             *
             * {
             *   AllowInsecureHttp = true,
             *   TokenEndpointPath = new PathString("/token"),
             *   AccessTokenExpireTimeSpan = TimeSpan.FromDays(1)
             * };
             * // Token Generation
             * app.UseOAuthAuthorizationServer(oAuthServerOptions);
             * app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());*/
            ////////////////////end netser

            app.SetUmbracoLoggerFactory();
            app.UseTwoFactorSignInCookie(Umbraco.Core.Constants.Security.BackOfficeTwoFactorAuthenticationType, TimeSpan.FromMinutes(5));

            // app.UseOAuthAuthorizationServer(options);
            // app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
            // We need to set these values again after our custom changes. Otherwise preview doesn't work.
            // Gunni: Apparently we don't need this for preview to work and the following code breaks other Identity providers
            //app.UseUmbracoBackOfficeCookieAuthentication(umbracoContextAccessor, Umbraco.Web.Composing.Current.RuntimeState, applicationContext.UserService, GlobalSettings, securitySection)
            //    .UseUmbracoBackOfficeExternalCookieAuthentication(umbracoContextAccessor, runtimeState, GlobalSettings)
            //    .UseUmbracoPreviewAuthentication(umbracoContextAccessor, runtimeState, globalSettings, securitySection);

            app.ConfigureUserManagerForUmbracoBackOffice <TwoFactorBackOfficeUserManager, BackOfficeIdentityUser>(
                Umbraco.Web.Composing.Current.RuntimeState,
                GlobalSettings,
                (options, context) =>
            {
                var membershipProvider = MembershipProviderExtensions.GetUsersMembershipProvider().AsUmbracoMembershipProvider();
                var userManager        = TwoFactorBackOfficeUserManager.Create(options,
                                                                               applicationContext.UserService,
                                                                               applicationContext.MemberTypeService,
                                                                               applicationContext.EntityService,
                                                                               applicationContext.ExternalLoginService,
                                                                               membershipProvider, GlobalSettings, umbracoMapper);
                return(userManager);
            });
        }
示例#24
0
        public void DefineMaps(UmbracoMapper mapper)
        {
            mapper.Define <ISection, Section>((source, context) => new Section(), Map);

            // this is for AutoMapper ReverseMap - but really?
            mapper.Define <Section, ContentSection>();
            mapper.Define <Section, ContentSection>();
            mapper.Define <Section, ManifestSection>(Map);
            mapper.Define <Section, MediaSection>();
            mapper.Define <Section, MembersSection>();
            mapper.Define <Section, PackagesSection>();
            mapper.Define <Section, SettingsSection>();
            mapper.Define <Section, TranslationSection>();
            mapper.Define <Section, UsersSection>();
        }
示例#25
0
 public DashboardLogService(IScopeProvider scopeProvider, IUserService userService, IEntityService entityService, IContentTypeService contentTypeService, UmbracoMapper mapper, IContentService contentService, IMemberService memberService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, IDataTypeService dataTypeService, IRelationService relationService, IMediaService mediaService)
 {
     _scopeProvider      = scopeProvider;
     _userService        = userService;
     _entityService      = entityService;
     _contentTypeService = contentTypeService;
     _mapper             = mapper;
     _contentService     = contentService;
     _memberService      = memberService;
     _mediaTypeService   = mediaTypeService;
     _memberTypeService  = memberTypeService;
     _dataTypeService    = dataTypeService;
     _relationService    = relationService;
     _mediaService       = mediaService;
 }
示例#26
0
    public void EnumMap()
    {
        var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition4() });
        var mapper      = new UmbracoMapper(definitions, _scopeProvider);

        var thing5 = new Thing5 {
            Fruit1 = Thing5Enum.Apple, Fruit2 = Thing5Enum.Banana, Fruit3 = Thing5Enum.Cherry
        };

        var thing6 = mapper.Map <Thing5, Thing6>(thing5);

        Assert.IsNotNull(thing6);
        Assert.AreEqual(Thing6Enum.Apple, thing6.Fruit1);
        Assert.AreEqual(Thing6Enum.Banana, thing6.Fruit2);
        Assert.AreEqual(Thing6Enum.Cherry, thing6.Fruit3);
    }
示例#27
0
 public void DefineMaps(UmbracoMapper mapper)
 {
     mapper.Define <IUser, BackOfficeIdentityUser>(
         (source, context) =>
     {
         var target = new BackOfficeIdentityUser(source.Id, source.Groups);
         target.DisableChangeTracking();
         return(target);
     },
         (source, target, context) =>
     {
         Map(source, target);
         target.ResetDirtyProperties(true);
         target.EnableChangeTracking();
     });
 }
        public void DefineMaps(UmbracoMapper mapper)
        {
            mapper.Define <HomePage, BaseContentViewModel>((source, context) => new BaseContentViewModel
            {
                Title       = source.PageTitle.HasValue() ? source.PageTitle : source.Name,
                Description = source.PageDescription
            });

            mapper.Define <HomePage, BaseContentSuggestionViewModel>((source, context) => new BaseContentSuggestionViewModel
            {
                Title       = source.PageTitle.HasValue() ? source.PageTitle : source.Name,
                Description = source.PageDescription,
                //Added this to display the reminder and children nodes data but this is not required in my suggestion
                PageInfo = _contentResponseBuilder.GetPageInfoData(source, ApplicationConstants.ReminderForSuggestion)
            });

            mapper.Define <NewsListingPage, BaseContentViewModel>((source, context) => new BaseContentViewModel
            {
                Title       = source.PageTitle.HasValue() ? source.PageTitle : source.Name,
                Description = source.PageDescription
            });

            mapper.Define <NewsListingPage, BaseContentSuggestionViewModel>((source, context) => new BaseContentSuggestionViewModel
            {
                Title       = source.PageTitle.HasValue() ? source.PageTitle : source.Name,
                Description = source.PageDescription,
                //Added this to display the reminder and children nodes data but this is not required in my suggestion
                PageInfo = _contentResponseBuilder.GetPageInfoData(source, ApplicationConstants.ReminderForSuggestion)
            });

            mapper.Define <NewsPage, NewsPageViewModel>((source, context) => new NewsPageViewModel
            {
                Name          = source.Name,
                PublishedDate = source.PublishedDate,
                Content       = _blockListBuilder.BuildBlockListValues(source.Blocks)
            });

            mapper.Define <NewsPage, NewsPageSuggestionViewModel>((source, context) => new NewsPageSuggestionViewModel
            {
                Name          = source.Name,
                PublishedDate = source.PublishedDate,
                Content       = _blockListBuilder.BuildBlockListValues(source.Blocks),
                //Added this to display the reminder and children nodes data but this is not required in my suggestion
                PageInfo = _contentResponseBuilder.GetPageInfoData(source, ApplicationConstants.ReminderForSuggestion)
            });
        }
示例#29
0
        public void LatestNewsWidgetHandler_CanMapFromContent()
        {
            // Arrange
            var mapper   = new UmbracoMapper();
            var rootNode = MockContent();
            var handler  = new LatestNewsWidgetHandler(mapper, rootNode.Object);
            var model    = new LatestNewsWidgetViewModel();

            // Act
            handler.Handle(model);

            // Assert
            Assert.AreEqual("/news/", model.NewsOverviewUrl);
            Assert.AreEqual(3, model.NewsItems.Count);
            Assert.AreEqual("Story 3", model.NewsItems[0].Title);
            Assert.AreEqual("/news/story-3/", model.NewsItems[0].Url);
            Assert.AreEqual(new DateTime(2016, 11, 23).ToString("d-MMM-yyyy"), model.NewsItems[0].DateTime.ToString("d-MMM-yyyy"));
        }
        public void FeaturedPagesHandler_CanMapFromContent()
        {
            // Arrange
            var mapper   = new UmbracoMapper();
            var rootNode = MockContent();
            var handler  = new FeaturedPagesHandler(mapper, rootNode.Object);
            var model    = new FeaturedPagesViewModel();

            // Act
            handler.Handle(model);

            // Assert
            Assert.AreEqual(2, model.Pages.Count);
            Assert.AreEqual("Text page", model.Pages[0].Name);
            Assert.AreEqual("/text-page/", model.Pages[0].Url);
            Assert.AreEqual("/media/1.jpg", model.Pages[0].ImageUrl);
            Assert.AreEqual(new string('*', 97) + "...", model.Pages[0].TruncatedBodyText);
        }