Beispiel #1
0
        protected override ISearchHistoryData parseUserData(string coreId, List <string> userFiles, SearchType sType)
        {
            List <string> data = new List <string>();

            foreach (string userFile in userFiles)
            {
                data.AddRange(getDataFromFile(userFile));
            }

            ISearchHistoryData searchData = SearchHistoryDataFacory.createSearchHistoryData(sType);

            searchData.SearchIds = data;
            searchData.CoreId    = coreId;

            return(searchData);
        }
        public void SaveLoadData()
        {
            ISearchHistoryStorage storage = HistoryStorageFactory.getFileHistoryStorage(StorageType.File);

            /**********************/
            /*      FIRST SET     */
            /**********************/

            ISearchHistoryData searchData = SearchHistoryDataFacory.createSearchHistoryData(SearchType.People);
            DateTime           timeStamp  = DateTime.Now;

            /* Generate random search IDs */
            Random        rnd       = new Random();
            List <string> searchIds = new List <string>();

            for (int i = 0; i < 100; i++)
            {
                searchIds.Add(rnd.Next(2000, 3000).ToString());
            }

            string coreId = "55555";

            searchData.CoreId          = coreId;
            searchData.SearchIds       = searchIds;
            searchData.SearchTimestamp = timeStamp;

            storage.saveSearchHistoryData(searchData);

            /**********************/
            /*      SECOND SET    */
            /**********************/

            ISearchHistoryData s_searchData = SearchHistoryDataFacory.createSearchHistoryData(SearchType.People);
            DateTime           s_timeStamp  = DateTime.Now;

            /* Generate random search IDs */
            Random        s_rnd       = new Random();
            List <string> s_searchIds = new List <string>();

            for (int s_i = 0; s_i < 533; s_i++)
            {
                s_searchIds.Add(s_rnd.Next(2000, 3000).ToString());
            }

            string s_coreId = "666666";

            s_searchData.CoreId          = s_coreId;
            s_searchData.SearchIds       = s_searchIds;
            s_searchData.SearchTimestamp = s_timeStamp;

            storage.saveSearchHistoryData(s_searchData);

            /**********************/
            /*      THIRD SET    */
            /**********************/

            ISearchHistoryData t_searchData = SearchHistoryDataFacory.createSearchHistoryData(SearchType.People);
            DateTime           t_timeStamp  = new DateTime(2012, 01, 01);

            /* Generate random search IDs */
            Random        t_rnd       = new Random();
            List <string> t_searchIds = new List <string>();

            for (int t_i = 0; t_i < 781; t_i++)
            {
                t_searchIds.Add(t_rnd.Next(2000, 3000).ToString());
            }

            string t_coreId = "666666";

            t_searchData.CoreId          = t_coreId;
            t_searchData.SearchIds       = t_searchIds;
            t_searchData.SearchTimestamp = t_timeStamp;

            storage.saveSearchHistoryData(t_searchData);

            /**********************/
            /*    FIRST RESULT    */
            /**********************/

            ISearchHistoryData loadedData = storage.loadSearchHistoryData(coreId, SearchType.People);

            Assert.AreEqual(loadedData.CoreId, coreId);
            Assert.AreEqual(loadedData.SearchDataType, SearchType.People);
            Assert.AreEqual(loadedData.SearchIds.Count, searchIds.Count);
            for (int f_r = 0; f_r < searchIds.Count; f_r++)
            {
                Assert.AreEqual(loadedData.SearchIds[f_r], searchIds[f_r]);
            }

            /**********************/
            /*    SECOND RESULT   */
            /**********************/

            ISearchHistoryData s_loadedData = storage.loadSearchHistoryData(s_coreId, SearchType.People);

            Assert.AreEqual(s_loadedData.CoreId, s_coreId);
            Assert.AreEqual(s_loadedData.SearchDataType, SearchType.People);
            Assert.AreEqual(s_loadedData.SearchIds.Count, (s_searchIds.Count + t_searchIds.Count));
        }