Exemplo n.º 1
0
        private void TestDsDataRetrieved(GigyaDsSettings dsSettings)
        {
            dynamic gigyaModel = new ExpandoObject();

            gigyaModel.UID = _dsUid;

            var settings = new GigyaModuleSettings
            {
                Id                = -1,
                ApiKey            = _dsApiKey,
                ApplicationKey    = _dsUserKey,
                ApplicationSecret = _dsSecret,
                MappingFields     = string.Empty,
                DataCenter        = "eu1.gigya.com"
            };

            //var settingsHelper = new Mock<GigyaDsSettingsHelper>(_logger);
            //settingsHelper.Setup(i => i.Get(It.IsAny<string>())).Returns(dsSettings);

            var mappingFields = new List <MappingField>();

            var helper = new GigyaDsHelper(settings, _logger, dsSettings);
            var result = helper.Merge(gigyaModel, mappingFields);

            Assert.IsNotNull(result);
            Assert.IsTrue(mappingFields.Any(), "Mapping fields not added");

            // verify all the fields
            Assert.AreEqual(30, result.ds.dsTesting.age_i);
            Assert.AreEqual("david", result.ds.dsTesting.firstName_s);
            Assert.AreEqual("1978-07-22", result.ds.dsTesting.birthDate_d);
            Assert.AreEqual("MBA", result.ds.dsTesting.academicDegree.degree_s);
        }
 public GigyaDsHelper(GigyaModuleSettings settings, Logger logger, GigyaDsSettings dsSettings, GigyaDsApiHelper apiHelper = null)
 {
     _settings   = settings;
     _logger     = logger;
     _apiHelper  = apiHelper ?? new GigyaDsApiHelper(_logger);
     _dsSettings = dsSettings;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the settings from the db and maps.
        /// </summary>
        /// <returns></returns>
        private GigyaDsSettingsContainer Load(int id)
        {
            var db = UmbracoContext.Current.Application.DatabaseContext.Database;

            var results = db.Fetch <GigyaUmbracoModuleDsSettings>(string.Format("SELECT * FROM gigya_ds_settings WHERE Id IN (-1, {0})", id));

            if (!results.Any())
            {
                return(null);
            }

            var mappings = db.Fetch <GigyaUmbracoDsMapping>(string.Format("SELECT * FROM gigya_ds_mapping WHERE DsSettingId IN (-1, {0})", id));

            var model = new GigyaDsSettingsContainer
            {
                Sites = new List <GigyaDsSettings>(results.Count)
            };

            foreach (var result in results)
            {
                GigyaDsSettings mappedSetting = Map(mappings, result);

                model.Sites.Add(mappedSetting);
            }

            return(model);
        }
        private GigyaDsSettingsViewModel GetModel(int id, GigyaDsSettings data)
        {
            var model = Map(data);

            var idString = id.ToString();

            model.Inherited = data.SiteId.All(i => i != idString);
            model.Id        = id;

            return(model);
        }
Exemplo n.º 5
0
        private void TestInvalidUidReturnsNull_Search(GigyaDsSettings dsSettings)
        {
            var settings = new GigyaModuleSettings
            {
                Id            = -1,
                ApiKey        = "3_qkAT5OcGyvYpkjc_VF6-OfoeTKGk4T_jVwjFF9f5TQzoAg-mH8SBsjQi1srdsOm6",
                MappingFields = string.Empty,
                DataCenter    = "eu1.gigya.com"
            };

            var helper = new GigyaDsHelper(settings, _logger, dsSettings);
            var result = helper.SearchAll("abc");

            Assert.IsNull(result);
        }
Exemplo n.º 6
0
        public GigyaDsSettings Map(List <GigyaUmbracoDsMapping> mappings, GigyaUmbracoModuleDsSettings settings)
        {
            var mappedSetting = new GigyaDsSettings
            {
                Method   = (GigyaDsMethod)settings.Method,
                SiteId   = new string[] { settings.Id.ToString() },
                Mappings = mappings.Where(i => i.DsSettingId == settings.Id).Select(Map).ToList()
            };

            mappedSetting.MappingsByType = mappedSetting.Mappings
                                           .Where(i => !string.IsNullOrEmpty(i.GigyaDsType))
                                           .GroupBy(i => i.GigyaDsType)
                                           .ToDictionary(i => i.Key, j => j.ToList());
            return(mappedSetting);
        }
        /// <summary>
        /// Maps Sitefinity DS model to a core model.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        public GigyaDsSettings Map(GigyaSitefinityModuleDsSettings settings)
        {
            var mappedSetting = new GigyaDsSettings
            {
                Method   = settings.Method,
                SiteId   = new string[] { settings.SiteId.ToString() },
                Mappings = settings.Mappings.Select(Map).ToList()
            };

            mappedSetting.MappingsByType = mappedSetting.Mappings
                                           .Where(i => !string.IsNullOrEmpty(i.GigyaDsType))
                                           .GroupBy(i => i.GigyaDsType)
                                           .ToDictionary(i => i.Key, j => j.ToList());
            return(mappedSetting);
        }
        /// <summary>
        /// Maps the core module to a vew model.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        private GigyaDsSettingsViewModel Map(GigyaDsSettings settings)
        {
            var model = new GigyaDsSettingsViewModel
            {
                Mappings = settings.Mappings.Select(i => new GigyaDsMappingViewModel
                {
                    CmsName   = i.CmsName,
                    GigyaName = i.GigyaName,
                    Oid       = i.Custom.Oid
                }).ToList(),
                Method = settings.Method
            };

            return(model);
        }
        private bool Validate(GigyaDsSettings settings)
        {
            var coreSettingsHelper = new Gigya.Module.Connector.Helpers.GigyaSettingsHelper();
            var coreSettings       = coreSettingsHelper.Get(settings.SiteId, true);

            var dsHelper = new GigyaDsHelper(coreSettings, Logger, settings);

            var errorMessage = dsHelper.Validate();

            if (!string.IsNullOrEmpty(errorMessage))
            {
                Logger.Error(errorMessage);
                throw new ArgumentException(errorMessage);
            }

            return(true);
        }
        private bool Validate(GigyaDsSettings settings, ref GigyaDsSettingsResponseModel responseModel)
        {
            var coreSettingsHelper = new GigyaSettingsHelper();
            var coreSettings       = coreSettingsHelper.Get(settings.SiteId, true);

            var dsHelper = new GigyaDsHelper(coreSettings, _logger, settings);

            var errorMessage = dsHelper.Validate();

            if (!string.IsNullOrEmpty(errorMessage))
            {
                responseModel.Error = errorMessage;
                _logger.Error(responseModel.Error);
                return(false);
            }

            return(true);
        }
 public GigyaSitefinityDsHelper(IGigyaModuleSettings settings, Logger logger, GigyaDsSettings dsSettings, GigyaDsApiHelper apiHelper = null) : base(settings, logger, dsSettings, apiHelper)
 {
 }