private void SetAppInAppList(MobileParam mobileParams, List<ApplistItemView> appListItems, AppColumn c, List<App> apps) { foreach (var a in apps) { if (!IsPublishableApp(a, mobileParams)) continue; ApplistItemView appListItem = new ApplistItemView(); var appProject = RedisService.Get<AppProject>(a.AppProjectId); if (appProject == null) { // log it and continue LogHelper.Error(string.Format("App project is null. App name is :{0}, id is {1}, app no is {2}. app proj id is {3}", a.Name, a.Id, a.AppNo, a.AppProjectId)); continue; } appListItem.AppNo = appProject.AppNo; appListItem.Name = appProject.Name; if (c != null) { var appSettings = RedisService.GetSubModel<AppColumn, AppSettingsForAppList>(c.Id, a.Id); if (appSettings != null && appSettings.CustomProperties != null && appSettings.CustomProperties.ContainsKey("Name")) appListItem.Name = appSettings.CustomProperties["Name"].ToString(); } var logoInfo = new List<AppLogo>(); foreach (var l in a.ClientLogos) { var logo = new AppLogo { Type = l.TypeId }; if (!string.IsNullOrWhiteSpace(l.TypeId)) { logo.Id = "C" + l.Id + l.Extension; // attension here: // the url was issued, or, there will be lots of connection for downloading the image if (!l.FileUrl.IsNullOrEmpty()) logo.Url = l.FileUrl.GetImageRelativeUrlByAbsoluteUrl().ToFileServerUrlAPP(); logoInfo.Add(logo); } } appListItem.Logos = logoInfo; appListItem.ServerLogo = GetSingleAppImageUrl(a.Logo.Id); appListItem.Price = (float)a.Price; bool hasValidVersion = false; if (HasTestableVersionForAppStore(a, mobileParams)) { var testVersion = AppStoreUIService.GetCurrentTestVersionForApp(a.Id); if (testVersion != null) { appListItem.FileSize = testVersion.FileSize.ToString(); appListItem.PublishTime = testVersion.PublishDateTime; appListItem.Version = a.CurrentTestVersion; appListItem.DownloadUrl = (FILE_PREFIX + testVersion.FileUrl).ToFileServerUrlAPP(); hasValidVersion = true; } } else if (HasPublishableVersion(a)) { var appVersion = AppStoreUIService.GetCurrentVersionForApp(a.Id); if (appVersion != null) { appListItem.FileSize = appVersion.FileSize.ToString(); appListItem.PublishTime = appVersion.PublishDateTime; appListItem.Version = a.CurrentVer; appListItem.DownloadUrl = (FILE_PREFIX + appVersion.FileUrl).ToFileServerUrlAPP(); hasValidVersion = true; } } if (!hasValidVersion) { continue; } appListItem.SummaryVersion = a.SummaryVer.ToString(); // There are no rate and review count for now. appListItem.Rate = appProject.Rate.ToString(); appListItem.ReviewCount = appProject.ReviewCount; appListItem.PlatformType = ((PlatformType)a.PlatformType).ToString(); appListItem.ApkName = appProject.PackageName; appListItem.Summary = a.Summary; appListItem.Activity = a.Activity; appListItem.DownloadTimes = a.DownloadTimes; appListItems.Add(appListItem); } }
public void CheckAppList_return_data_to_client_successfully() { var columns = new Dictionary<string, string>(); columns.Add("1", "1"); Dictionary<string, object> customProperties = new Dictionary<string, object>(); customProperties["7"] = "240x320"; var deviceModel = new DeviceModel() { ModelName = "MTK_6252", CustomProperties = customProperties, Columns = columns }; AppProject appProj = new AppProject() { Id = "1", AppNo = "1", Name = "New APP 1" }; var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); _appStoreUIServiceMock.Setup(m => m.GetDeviceModelByRequest(mobileParam)).Returns(deviceModel); App app = new App() { Id = "1", Name = "APP1", AppProjectId = "1", CurrentVer = "1" }; _appStoreUIServiceMock.Setup(m => m.GetAppsFromAppList<AppColumn>("1")).Returns(new List<App> { app }); _redisServiceMock.Setup(m => m.Get<AppProject>("1")).Returns(appProj); AppVersion version = new AppVersion { Id = "1", FileSize = 123 }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("1")).Returns(version); AppColumn column = new AppColumn() { Id = "1", ClientId = 1, CurrentVersion = 1, Name = "Applications" }; _redisServiceMock.Setup<List<AppColumn>>(m => m.GetValuesByIds<AppColumn>(new List<string>() { "1" }, true)).Returns(new List<AppColumn>() { column }); AppStoreService appStoreService = new AppStoreService(fileService, redisService, appStoreUIService, new FullTextSearchService(redisService),new IMEICacheService(redisService)); var result = appStoreService.CheckAppList("1~0", mobileParam); Assert.Equal(1, result.Count); }
public void AppColumn_And_AppProject_Test() { #region generate App Project and AppColumn AppProject appProject = new AppProject(); appProject.Name = "10010"; appProject.Id = "10010"; appProject.CreateDateTime = DateTime.Now.AddSeconds(-3); appProject.CurrentVersion = 10010; AppColumn appColumn = new AppColumn(); appColumn.Name = "10020"; appColumn.Id = "10020"; appColumn.CreateDateTime = DateTime.Now.AddDays(3); appColumn.CurrentVersion = 10011; #endregion Service.Add<AppProject>(appProject); Service.Add<AppColumn>(appColumn); #region App settings App app = new App(); app.Id = "10002"; app.Name = "App2"; app.Price = 10.55; app.CreateDateTime = new DateTime(2011, 11, 23, 1, 1, 1); App app1 = new App(); app1.Id = "10001"; app1.Name = "App1"; app1.Price = 25.88; app1.CreateDateTime = new DateTime(2011, 12, 1, 1, 1, 1); #endregion #region Element Settings Element ele = new Element(); ele.Id = "1"; ele.Name = "分辨率"; ele.Type = (int)ElementType.多选列表; Service.Add<Element>(ele); Element ele2 = new Element(); ele2.Id = "2"; ele2.Name = "CustomProperty"; ele2.Type = (int)ElementType.多选列表; ele2.IsQueriable = true; Service.Add<Element>(ele2); Element ele5 = new Element(); ele5.Id = "3"; ele5.Name = "Resolution"; ele5.Type = (int)ElementType.多选列表; ele5.IsQueriable = true; Service.Add<Element>(ele5); Element ele4 = new Element(); ele4.Id = "4"; ele4.Name = "IsTouchable"; ele4.Type = (int)ElementType.输入框; ele4.IsQueriable = true; Service.Add<Element>(ele4); ElementDetail elementDetail1 = new ElementDetail(); elementDetail1.ElementId = "2"; elementDetail1.Value = "CustomPropertyValue1"; ElementDetail elementDetail2 = new ElementDetail(); elementDetail2.ElementId = "2"; elementDetail2.Value = "CustomPropertyValue2"; Element ele3 = new Element(); ele3.Id = "3"; ele3.Name = "IntCustomProperty"; ele3.Type = (int)ElementType.输入框; ele3.IsQueriable = true; Service.Add<Element>(ele3); ElementDetail elementDetail3 = new ElementDetail(); elementDetail3.ElementId = "3"; elementDetail3.Value = 3.6; #endregion #region customProperty settings CustomProperty customProperty = new CustomProperty(); customProperty.Id = ele2.Name; customProperty.Value = new List<string>() { elementDetail1.Value.ToString(), elementDetail2.Value.ToString() }; customProperty.IsQueriable = ele2.IsQueriable; CustomProperty customProperty2 = new CustomProperty(); customProperty2.Id = ele3.Name; customProperty2.Value = elementDetail3.Value; customProperty2.IsQueriable = ele3.IsQueriable; CustomProperty customProperty3 = new CustomProperty(); customProperty3.Id = ele3.Name; customProperty3.Value = elementDetail3.Value; customProperty3.IsQueriable = ele3.IsQueriable; CustomProperty resolutionProperty = new CustomProperty(); resolutionProperty.Id = ele5.Name; resolutionProperty.Value = new List<string>() { "240*320", "320*480" }; CustomProperty isTouchableProperty = new CustomProperty(); isTouchableProperty.Id = ele4.Name; isTouchableProperty.Value = true; #endregion customProperty.IsQueriable = true; Service.AddCustomPropertyFor<AppList, CustomProperty>(appProject.Id, customProperty); Dictionary<string, string> applistConditions = new Dictionary<string, string>(); applistConditions.Add("CustomProperty", "CustomPropertyValue2"); var appProjectOrigin = CloneHelper.DeepClone<AppProject>(appProject); appProject.CreateDateTime = DateTime.Now.AddDays(1); appProject.CurrentVersion++; // make sure bump version number when upate applist Service.UpdateWithRebuildIndex<AppProject>(appProjectOrigin, appProject); var appColumnOrigin = CloneHelper.DeepClone<AppColumn>(appColumn); appColumn.CreateDateTime = DateTime.Now.AddDays(1); appColumn.CurrentVersion++; // make sure bump version number when upate applist Service.UpdateWithRebuildIndex<AppColumn>(appColumnOrigin, appColumn); AppSettingsForAppList customApp1 = new AppSettingsForAppList(); customApp1.Id = app1.Id; customApp1.ScoreForSort = 2; customApp1.CustomProperties = new Dictionary<string, object>(); customApp1.CustomProperties.Add("Name", "NewApp1"); customApp1.CustomProperties.Add("Price", 2.3); customApp1.CustomProperties.Add("CustomProperty", "newValueFromAppListSettings"); AppSettingsForAppList customApp2 = new AppSettingsForAppList(); customApp2.Id = app.Id; customApp2.ScoreForSort = 1; customApp2.CustomProperties = new Dictionary<string, object>(); customApp2.CustomProperties.Add("Name", "NewApp2"); customApp2.CustomProperties.Add("Price", 3.2); AppStoreSvc.SetAppForAppList<AppProject>("10010", customApp1); AppStoreSvc.SetAppForAppList<AppProject>("10010", customApp2); AppSettingsForAppList customApp3 = new AppSettingsForAppList(); customApp3.Id = "10001"; customApp3.CustomProperties = new Dictionary<string, object>(); AppStoreSvc.SetAppForAppList<AppColumn>("10020", customApp3); #region Service.DeleteWithCustomProperties<App, CustomProperty>("10001"); Service.DeleteWithCustomProperties<App, CustomProperty>("10002"); Service.DeleteWithCustomProperties<AppProject, CustomProperty>(appProject.Id); Service.DeleteWithCustomProperties<AppColumn, CustomProperty>(appColumn.Id); Service.Delete<Element>(ele); Service.Delete<Element>(ele2); Service.Delete<Element>(ele3); Service.Delete<Element>(ele4); Service.Delete<Element>(ele5); Service.Delete<AppProject>(appProject); Service.Delete<AppColumn>(appColumn); #endregion }
public void AppList_return_data_to_client_successfully() { var columns = new Dictionary<string, string>(); columns.Add("1", "1"); Dictionary<string, object> customProperties = new Dictionary<string, object>(); customProperties["7"] = "240x320"; var deviceModel = new DeviceModel() { ModelName = "MTK_6252", CustomProperties = customProperties, Columns = columns }; AppProject appProj = new AppProject() { Id = "1", AppNo = "1", Name = "New APP 1" }; var namevalues = new NameValueCollection(); namevalues[MobileParam.Key_Resolution] = "240x320"; _requestRepoMock.Setup<NameValueCollection>(m => m.Header).Returns(namevalues); MobileParam mobileParam = new MobileParam(requestRepo); _appStoreUIServiceMock.Setup(m => m.GetDeviceModelByRequest(mobileParam)).Returns(deviceModel); App app = new App() { Id = "1", Name = "APP1", AppProjectId = "1", CurrentVer = "1", Status = 1 }; _appStoreUIServiceMock.Setup(m => m.GetAppsFromAppList<AppColumn>("1")).Returns(new List<App> { app }); _redisServiceMock.Setup(m => m.Get<AppProject>("1")).Returns(appProj); var settings = new AppSettingsForAppList(); settings.CustomProperties = new Dictionary<string, object>(); settings.CustomProperties.Add("Name", "testName"); _redisServiceMock.Setup(m => m.GetSubModel<AppColumn, AppSettingsForAppList>(It.IsAny<string>(), It.IsAny<string>(), false)).Returns(settings); AppVersion version = new AppVersion { Id = "1", FileSize = 123, PublishDateTime = DateTime.Now.AddDays(-1) }; _appStoreUIServiceMock.Setup(m => m.GetCurrentVersionForApp("1")).Returns(version); AppColumn column = new AppColumn() { Id = "1", ClientId = 1, CurrentVersion = 1, Name = "Applications" }; _redisServiceMock.Setup<List<AppColumn>>(m => m.GetValuesByIds<AppColumn>(new List<string>() { "1" }, true)).Returns(new List<AppColumn>() { column }); AppStoreService appStoreService = new AppStoreService(fileService, redisService, appStoreUIService, new FullTextSearchService(redisService), new IMEICacheService(redisService)); string slver = string.Empty; int totalCount = 0; var result = appStoreService.AppList(mobileParam, 1, 1, 0, 0, "0", out slver, out totalCount); Assert.Equal(1, result.Count); Assert.Equal("testName", result[0].Name); }