Esempio n. 1
0
        public override ActionResult AppBranchAdd(FormCollection parameters)
        {
            var appProject = RedisService.Get<AppProject>(parameters["appProjectId"]);
            var defaultProperties = SetDefaultSettingsToView(appProject.Creator);

            if (defaultProperties.Count < 1)
            {
                TempData["errorMsg"] = string.Format("请先添加该型号的默认配置信息!");
                return RedirectToAction("AppBranchAdd", new { appProjectId = parameters["appProjectId"] });
            }
            if (string.IsNullOrWhiteSpace(parameters["AppName"]))
            {
                TempData["errorMsg"] = string.Format("版本号不能为空!");
                return RedirectToAction("AppBranchAdd", new { appProjectId = parameters["appProjectId"] });
            }

            App app = new App();
            string appName = parameters["AppName"].Trim();
            Regex rx = new Regex(@"^[v|V].*");
            if (!rx.IsMatch(appName))
            {
                TempData["errorMsg"] = string.Format("版本号前面带v!");
                return RedirectToAction("AppBranchAdd", new { appProjectId = parameters["appProjectId"] });
            }
            try
            {
                Version version = new Version(appName.TrimStart(new char[] { 'v', 'V' }).Trim());
            }
            catch
            {
                TempData["errorMsg"] = string.Format("版本号输入不符合规则!");
                return RedirectToAction("AppBranchAdd", new { appProjectId = parameters["appProjectId"] });
            }
            var appList = UIService.GetAppsFromAppList<AppProject>(parameters["appProjectId"]);
            foreach (var a in appList)
            {
                if (a.Name.ToUpper().Trim().Equals(appName.ToUpper().Trim()))
                {
                    TempData["errorMsg"] = string.Format("已经添加过版本号【{0}】,版本号不能重复!", appName);
                    return RedirectToAction("AppBranchAdd", new { appProjectId = parameters["appProjectId"] });
                }
            }
            var elementIdNameMapping = GetElementIdNameMapping();
            var apps = this.UIService.GetAppsFromAppList<AppProject>(appProject.Id);
            app.Name = ConfigHelper.IsOTAMode() ? appName : string.Format("{0}({1})", appProject.Name, appName);
            app.CreateDateTime = DateTime.Now;
            app.AppProjectId = parameters["appProjectId"];
            app.AppNo = appProject.AppNo;
            var appId = RedisService.Add<App>(app);

            if (string.IsNullOrEmpty(appId))
            {
                TempData["errorMsg"] = string.Format("Please check if there is duplicate name.");
                return RedirectToAction("AppBranchList", new { appProjectId = parameters["appProjectId"] });
            }

            var properties = apps.Count > 0 ? apps[0].CustomProperties : defaultProperties;

            foreach (var propertie in properties)
            {
                if (propertie.Value == null || !elementIdNameMapping.ContainsKey(propertie.Key))
                {
                    continue;
                }

                CustomProperty prop = new CustomProperty()
                {
                    Id = propertie.Key.ToString(),

                    Value = !elementIdNameMapping[propertie.Key].ToString().Contains(OTAConfigKeys.OTAUpdateContent.ToString()) ? propertie.Value.ToString() : defaultProperties[propertie.Key].ToString()
                };

                if (prop.Value != null && !string.IsNullOrWhiteSpace(prop.Value.ToString()))
                {
                    RedisService.AddCustomPropertyFor<App, CustomProperty>(appId, prop);
                }
            }

            AppSettingsForAppList appSetting = new AppSettingsForAppList()
            {
                Id = appId,
                CreateDateTime = DateTime.Now
            };

            UIService.SetAppForAppList<AppProject>(parameters["appProjectId"], appSetting);

            return RedirectToAction("AppBranchList", new { appProjectId = parameters["appProjectId"] });
        }
        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 AppStoreIntergrationTest()
        {
            Redis.AddItemToQueue<string>("qlist1", "task");
            var waitResult = Redis.RetrieveItemFromQueue<string>("qlist1");
            Console.WriteLine(waitResult);

            #region App Add & Get
            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);

            Redis.Add<App>(app);
            PrintDebug("app id:10001 added");
            Redis.Add<App>(app1);
            PrintDebug("app id:10002 added");

            PrintDebug("Get app info for id:10001 : " + Redis.Get<App>("10001").Name);

            Console.WriteLine("Get one page of app : " + Redis.GetValuesByIds<App>(Redis.GetPagedModelIds<App>(1, 2)).Count);
            Console.WriteLine("Get one page of app sorted by price: " + Redis.GetValuesByIds<App>(Redis.GetPagedModelIds<App>(1, 2, "Price", true)).Count);
            #endregion

            #region App Element settings
            Element ele = new Element();
            ele.Id = "1";
            ele.Name = "分辨率";
            ele.Type = (int)ElementType.多选列表;
            Redis.Add<Element>(ele);

            ElementDetail eleDetl = new ElementDetail();
            eleDetl.Id = "2";
            eleDetl.Value = "176x220";
            eleDetl.ElementId = "1";
            Redis.Add<ElementDetail>(eleDetl);

            ElementDetail eleDetl1 = new ElementDetail();
            eleDetl1.Id = "3";
            eleDetl1.Value = "240x320";
            eleDetl1.ElementId = "1";
            Redis.Add<ElementDetail>(eleDetl1);

            ElementDetail eleDetl2 = new ElementDetail();
            eleDetl2.Id = "4";
            eleDetl2.Value = "240x400";
            eleDetl2.ElementId = "1";
            Redis.Add<ElementDetail>(eleDetl2);

            var collection = Redis.GetValuesByIds<Element>(Redis.GetAllActiveModelIds<Element>());
            PrintDebug("Element count: " + collection.Count + "  " + Redis.GetAllCount<Element>());
            if (collection.Count > 0)
            {
                PrintDebug("Element name: " + collection[0].Name);
            }

            var collection2 = AppStoreSvc.GetElementDetailList("1");
            PrintDebug("ElementDetail count for Element[1]: " + collection2.Count);

            var originModel = CloneHelper.DeepClone<Element>(ele);
            ele.Name = "resolution";
            Redis.UpdateWithRebuildIndex<Element>(originModel, ele);
            PrintDebug("Element name: " + Redis.Get<Element>("1").Name);

            if (Redis.Get<Element>("1") == null)
            {
                PrintDebug("Element[1] deleted.");
            }
            #endregion

            #region App Dynamic Property
            #region Element Settings
            Element ele2 = new Element();
            ele2.Id = "2";
            ele2.Name = "CustomProperty";
            ele2.Type = (int)ElementType.多选列表;
            ele2.IsQueriable = true;
            Redis.Add<Element>(ele2);

            Element ele5 = new Element();
            ele5.Id = "3";
            ele5.Name = "Resolution";
            ele5.Type = (int)ElementType.多选列表;
            ele5.IsQueriable = true;
            Redis.Add<Element>(ele5);

            Element ele4 = new Element();
            ele4.Id = "4";
            ele4.Name = "IsTouchable";
            ele4.Type = (int)ElementType.输入框;
            ele4.IsQueriable = true;
            Redis.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;
            Redis.Add<Element>(ele3);

            ElementDetail elementDetail3 = new ElementDetail();
            elementDetail3.ElementId = "3";
            elementDetail3.Value = 3.6;
            #endregion

            // Set up dynamic value for App
            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;

            Redis.AddCustomPropertyFor<App, CustomProperty>("10001", customProperty);
            Redis.AddCustomPropertyFor<App, CustomProperty>("10001", customProperty2);
            Redis.AddCustomPropertyFor<App, CustomProperty>("10001", resolutionProperty);
            Redis.AddCustomPropertyFor<App, CustomProperty>("10001", isTouchableProperty);
            resolutionProperty.Value = new List<string>() { "320*480" };
            Redis.AddCustomPropertyFor<App, CustomProperty>("10002", resolutionProperty);
            isTouchableProperty.Value = false;
            Redis.AddCustomPropertyFor<App, CustomProperty>("10002", isTouchableProperty);
            PrintDebug("add App's custom property: " + Redis.GetCustomPropertyFrom<App, CustomProperty>("10001", "CustomProperty").Id);

            Dictionary<string, string> newConditions = new Dictionary<string, string>();
            newConditions.Add("Resolution", "320*480");
            newConditions.Add("IsTouchable", bool.TrueString);
            newConditions.Add("CustomProperty", "CustomPropertyValue2");
            PrintDebug("found app by dynamic property : " + Redis.FindIdsByConditions<App>(newConditions).Count);
            PrintDebug("found app by dynamic property (double value) : " + Redis.FindIdsByValueRange<App>("IntCustomProperty", 3.58, 3.62).Count);
            PrintDebug("find Custom Properties count for app[10001] :  " + Redis.GetModelWithCustomProperties<App, CustomProperty>("10001").CustomProperties.Count);

            var originalCustomProperty = CloneHelper.DeepClone<CustomProperty>(customProperty);
            customProperty.IsQueriable = false;
            Redis.UpdateCustomPropertyFor<App, CustomProperty>("10001", originalCustomProperty, customProperty);
            PrintDebug("found app by dynamic property [CustomProperty:CustomPropertyValue2] after set IsQueriable to false : " + Redis.FindIdsByConditions<App>(newConditions).Count);

            //AppStoreSvc.DeleteCustomPropertyForApp("10001", customProperty);
            //PrintDebug("delete App's CustomProperty: " + (AppStoreSvc.GetCustomPropertyForApp("10001", "CustomProperty") == null));
            #endregion

            #region Find app By a certain Value Range
            List<App> apps = Redis.GetValuesByIds<App>(Redis.FindIdsByValueRange<App>("Price", 10.56, 25.88));
            PrintDebug("found app num by 10.56<= Price <=25.88 : " + apps.Count);

            apps = Redis.GetValuesByIds<App>(Redis.FindIdsByValueRange<App>("CreateDateTime", new DateTime(2011, 11, 23, 1, 1, 1), new DateTime(2011, 12, 1, 1, 1, 1)));
            PrintDebug("found app num by CreateDate : " + apps.Count);
            #endregion

            #region Fuzzy Find App
            apps = Redis.GetValuesByIds <App>(Redis.FuzzyFindIdsByCondition<App>("N*e", "App?"));
            PrintDebug("found app num by N*e like App? " + apps.Count);
            #endregion

            #region Complex Find App

            List<string> appIdsByValueRange = Redis.FindIdsByValueRange<App>("Price", 10.55, 25.88);
            List<string> appIdsByDateValueRange = Redis.FindIdsByValueRange<App>("CreateDateTime", new DateTime(2011, 11, 23, 1, 1, 1), new DateTime(2011, 12, 1, 1, 1, 1));

            // Intersect means AND,  Union mean OR
            List<App> finalResult = Redis.GetValuesByIds<App>((appIdsByValueRange.Intersect<string>(appIdsByDateValueRange).ToList()));

            PrintDebug("found app num by complex conditions " + finalResult.Count);
            #endregion

            #region App Version
            AppVersion appVer = new AppVersion();
            appVer.Id = "10000";
            appVer.FileUrl = "C:\a";
            appVer.PublishDateTime = DateTime.Now;
            AppStoreSvc.AddAppVersion("10001", appVer);
            appVer.FileUrl = "E:\\";
            AppStoreSvc.AddAppVersion("10001", appVer);
            AppStoreSvc.SetAppCurrentTestVersion("10001", "10000");
            PrintDebug("added version num : " + AppStoreSvc.GetCurrentTestVersionForApp("10001").Id);
            PrintDebug("app current version : " + Redis.Get<App>("10001").CurrentTestVersion);

            var appCopy = CloneHelper.DeepClone<App>(app);
            app.Name = "App3";
            Redis.UpdateWithRebuildIndex<App>(appCopy, app);
            PrintDebug("App name updated to " + Redis.Get<App>("10002").Name);
            #endregion

            #region Category
            Category c1 = new Category();
            c1.Id = "1";
            c1.Name = "游戏";
            c1.ParentId = "0";
            c1.status = "1";

            Redis.Add<Category>(c1);

            Category csub1 = new Category();
            csub1.Id = "2";
            csub1.Name = "益智游戏";
            csub1.ParentId = "1";
            csub1.status = "1";

            Redis.Add<Category>(csub1);

            PrintDebug("Sub Category count for Category[0] : " + AppStoreSvc.GetCategoryList("0").Count);
            #endregion

            #region App list
            AppList applist1 = new AppList();
            applist1.Name = "10010";
            applist1.Id = "10010";
            applist1.CreateDateTime = DateTime.Now.AddSeconds(-3);
            applist1.CurrentVersion = 10010;

            AppList applist2 = new AppList();
            applist2.Name = "10020";
            applist2.Id = "10020";
            applist2.CreateDateTime = DateTime.Now.AddDays(3);
            applist2.CurrentVersion = 10011;

            Redis.Add<AppList>(applist1);
            Redis.Add<AppList>(applist2);
            PrintDebug("two app lists added.");

            customProperty.IsQueriable = true;
            Redis.AddCustomPropertyFor<AppList, CustomProperty>(applist1.Id, customProperty);
            Dictionary<string, string> applistConditions = new Dictionary<string, string>();
            applistConditions.Add("CustomProperty", "CustomPropertyValue2");
            PrintDebug("found applist by dynamic property : " + Redis.FindIdsByConditions<AppList>(applistConditions).Count);

            var applist1Origin = CloneHelper.DeepClone<AppList>(applist1);
            applist1.CreateDateTime = DateTime.Now.AddDays(1);
            applist1.CurrentVersion++; // make sure bump version number when upate applist
            Redis.UpdateWithRebuildIndex<AppList>(applist1Origin, applist1);
            PrintDebug("app list updated :" + Redis.Get<AppList>("10010").Name);

            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<AppList>("10010", customApp1);
            AppStoreSvc.SetAppForAppList<AppList>("10010", customApp2);

            var appsFromList1 = AppStoreSvc.GetAppsFromAppList<AppList>("10010");
            PrintDebug("App count for AppList[10010] : " + appsFromList1.Count);

            var app1FromAppList1 = AppStoreSvc.GetAppFromAppList<AppList>("10010", "10001");
            PrintDebug("Get App[10001]'s price From AppList[10010] : " + app1FromAppList1.Price);
            PrintDebug("Get App[10001]'s CustomProperty From AppList[10010] : " + app1FromAppList1.CustomProperties["CustomProperty"]);

            NameValueCollection headers = new NameValueCollection();
            headers.Add("Resolution", "240*320");
            headers.Add("IsTouchable", "1");
            RequestHeadersMock.Setup(s => s.Header).Returns(headers);
            MobileParam requestParams = new MobileParam(RequestHeadersMock.Object);
            var matchedApp = AppStoreSvc.GetMatchedAppByRequest<AppList>("10010", requestParams);
            //PrintDebug("Matched app in applist[10010]: " + matchedApp.Id);

            AppSettingsForAppList customApp3 = new AppSettingsForAppList();
            customApp3.Id = "10001";
            customApp3.CustomProperties = new Dictionary<string, object>();
            AppStoreSvc.SetAppForAppList<AppList>("10020", customApp3);

            List<string> appIdsUnion = AppStoreSvc.GetAppIdsByUnionAppList<AppList>("10010", "10020");
            PrintDebug("Union applist1 and applist2, App count : " + appIdsUnion.Count);

            List<string> appIdsDiff = AppStoreSvc.GetAppIdsByDiffAppList<AppList>("10010", "10020");
            PrintDebug("Diff applist1 and applist2, App count : " + appIdsDiff.Count);
            #endregion

            #region Device Model

            DeviceModel tyd1 = new DeviceModel()
            {
                Id = "天奕达HWQP",
                ModelName = "天奕达HWQP",
                CreateDateTime = DateTime.Now
            };
            Redis.Add<DeviceModel>(tyd1);
            CustomProperty criteria1 =  new CustomProperty()
            {
                Id = "Resolution",
                Value = "240*320",
                IsQueriable = false
            };
            CustomProperty criteria2 =  new CustomProperty()
            {
                Id = "IsTouchable",
                Value = true,
                IsQueriable = false
            };
            PrintDebug("add device model : " + tyd1.ModelName);
            Redis.AddCustomPropertyFor<DeviceModel, CustomProperty>(tyd1.Id, criteria1);
            Redis.AddCustomPropertyFor<DeviceModel, CustomProperty>(tyd1.Id, criteria2);
            PrintDebug("add search criterias for device model : " + tyd1.ModelName);
            tyd1 = Redis.GetModelWithCustomProperties<DeviceModel, CustomProperty>("天奕达HWQP");
            PrintDebug("search by DeviceModel[天奕达HWQP]: " + AppStoreSvc.GetAppsForDeviceModel(tyd1).Count);
            //PrintDebug("Get Device Model By Request parameters : " + AppStoreSvc.GetDeviceModelByRequest(requestParams).ModelName);

            #endregion

            #region Clean up
            Redis.DeleteWithCustomProperties<App, CustomProperty>("10001");
            Redis.DeleteWithCustomProperties<App, CustomProperty>("10002");
            Redis.DeleteWithCustomProperties<AppList, CustomProperty>(applist1.Id);
            Redis.DeleteWithCustomProperties<AppList, CustomProperty>(applist2.Id);
            Redis.Delete<Category>(c1);
            Redis.Delete<Category>(csub1);
            Redis.Delete<Element>(ele);
            Redis.Delete<Element>(ele2);
            Redis.Delete<Element>(ele3);
            Redis.Delete<Element>(ele4);
            Redis.Delete<Element>(ele5);
            Redis.Delete<ElementDetail>(eleDetl);
            Redis.Delete<ElementDetail>(eleDetl1);
            Redis.Delete<ElementDetail>(eleDetl2);
            Redis.Delete<DeviceModel>(tyd1);

            if (Redis.KeyFuzzyFind("*").Count == 0)
            {
                PrintDebug("App Count: " + Redis.GetAllCount<App>());
                PrintDebug("All cleaned up.");
            }
            else
            {
                PrintDebug("Still useless keys left.");
            }

            #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);
        }