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 void FallbackLanguageUsedForAutoButUnsupportedLanguage() { // arrange var culture = new CultureInfo("tt"); Thread.CurrentThread.CurrentUICulture = culture; var currentIdentity = new CurrentIdentity(); IGigyaModuleSettings settings = new GigyaModuleSettings { SessionTimeout = 10, Language = "auto", LanguageFallback = "fr" }; var pathUtility = new Mock <IPathUtilities>(); pathUtility.Setup(i => i.ToAbsolute(It.IsAny <string>())).Returns(string.Empty); var settingsHelper = new Gigya.Umbraco.Module.Helpers.GigyaSettingsHelper(); settingsHelper.PathUtilities = pathUtility.Object; var viewModel = settingsHelper.ViewModel(settings, null, currentIdentity); Assert.AreEqual("fr", viewModel.Settings.lang, "Language should be fr"); }
public GigyaDsHelper(GigyaModuleSettings settings, Logger logger, GigyaDsSettings dsSettings, GigyaDsApiHelper apiHelper = null) { _settings = settings; _logger = logger; _apiHelper = apiHelper ?? new GigyaDsApiHelper(_logger); _dsSettings = dsSettings; }
public void GlobalSettingsHasHigherPriority() { // arrange var currentIdentity = new CurrentIdentity(); IGigyaModuleSettings settings = new GigyaModuleSettings { SessionTimeout = 10, Language = "abc", GlobalParameters = "{ \"sessionExpiration\": 123, \"lang\": \"override\", \"jkglobal\": \"hello\" }" }; var pathUtility = new Mock <IPathUtilities>(); pathUtility.Setup(i => i.ToAbsolute(It.IsAny <string>())).Returns(string.Empty); var settingsHelper = new Gigya.Umbraco.Module.Helpers.GigyaSettingsHelper(); settingsHelper.PathUtilities = pathUtility.Object; var viewModel = settingsHelper.ViewModel(settings, null, currentIdentity); Assert.AreEqual(123, viewModel.Settings.sessionExpiration, "sessionExpiration doesn't match global params"); Assert.AreEqual("override", viewModel.Settings.lang, "lang doesn't match global params"); Assert.AreEqual("hello", viewModel.Settings.jkglobal, "global param doesn't exist or match in settings object"); }
/// <summary> /// Runs a ds.search query to retrieve ds data. /// </summary> /// <param name="settings">Current module settings.</param> /// <param name="query">The search query.</param> public GSResponse Search(GigyaModuleSettings settings, string query) { var request = NewRequest(settings, settings.ApplicationSecret, "ds.search"); request.SetParam("query", query); var response = Send(request, "ds.search", settings); return(response); }
public GSResponse GetSchema(GigyaModuleSettings settings, string gigyaType) { var method = "ds.getSchema"; var request = NewRequest(settings, settings.ApplicationSecret, method); request.SetParam("type", gigyaType); var response = Send(request, method, settings); return(response); }
protected virtual GSRequest NewRequest(GigyaModuleSettings settings, string applicationSecret, string method) { var request = new GSRequest(settings.ApiKey, applicationSecret, method, null, true, settings.ApplicationKey); if (!string.IsNullOrEmpty(settings.DataCenter)) { request.APIDomain = settings.DataCenter; } return(request); }
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); }
/// <summary> /// Calls ds.get to get ds data. /// </summary> /// <param name="settings">Current module settings.</param> /// <param name="uid">The user Id.</param> /// <param name="oid">The oid of the ds field.</param> /// <param name="gigyaType">The ds type.</param> /// <param name="fields">The fields to retrieve.</param> public GSResponse Get(GigyaModuleSettings settings, string uid, string oid, string gigyaType, IEnumerable <string> fields = null) { var request = NewRequest(settings, settings.ApplicationSecret, "ds.get"); request.SetParam("UID", uid); request.SetParam("oid", oid); request.SetParam("type", gigyaType); if (fields != null && fields.Any()) { var fieldsValue = string.Join(",", fields); request.SetParam("fields", fieldsValue); } var response = Send(request, "ds.get", settings); return(response); }
private IGigyaModuleSettings Map(GigyaUmbracoModuleSettings settings) { var model = new GigyaModuleSettings { ApiKey = settings.ApiKey, ApplicationSecret = settings.ApplicationSecret, ApplicationKey = settings.ApplicationKey, DataCenter = settings.DataCenter, DebugMode = settings.DebugMode, EnableRaas = settings.EnableRaas, GlobalParameters = settings.GlobalParameters, Id = settings.Id, Language = settings.Language, LanguageFallback = settings.LanguageFallback, LogoutUrl = settings.LogoutUrl, MappingFields = settings.MappingFields, RedirectUrl = settings.RedirectUrl, SessionTimeout = settings.SessionTimeout }; return(model); }
private GSResponse Send(GSRequest request, string apiMethod, GigyaModuleSettings settings) { GSResponse response = null; try { response = request.Send(); } catch (Exception e) { return(LogError(response, apiMethod, e)); } GigyaApiHelper.LogResponseIfRequired(_logger, settings, apiMethod, response); if (response.GetErrorCode() != 0) { LogError(response, apiMethod, null); return(null); } return(response); }
/// <summary> /// Gets the Gigya language to use. /// </summary> /// <returns>A culture code.</returns> public string Language(GigyaModuleSettings settings, CultureInfo currentCulture) { if (settings.Language != "auto") { return(settings.Language); } var language = currentCulture.Name.ToLowerInvariant(); if (Languages.ContainsKey(language)) { return(language); } // attempt to find non specific culture language = currentCulture.TwoLetterISOLanguageName.ToLowerInvariant(); if (Languages.ContainsKey(language)) { return(language); } return(settings.LanguageFallback); }