Esempio n. 1
0
        public UnitTestResult GetNextResult(string configuration, UnitTest test, DateTime date)
        {
            DateTime   currentDate = date;
            TestRecord root        = GetRootRecord(configuration, currentDate);

            if (root == null)
            {
                root = GetNextRootRecord(configuration, ref currentDate);
            }

            while (root != null)
            {
                TestRecord tr = FindRecord(root, test.StoreRelativeName);
                if (tr != null && tr.Results != null)
                {
                    foreach (UnitTestResult res in tr.Results)
                    {
                        if (res.TestDate > date)
                        {
                            return(res);
                        }
                    }
                }
                root = GetNextRootRecord(configuration, ref currentDate);
            }
            return(null);
        }
		public void RegisterResult (string configuration, UnitTest test, UnitTestResult result)
		{
			string aname = test.StoreRelativeName;
			
			TestRecord root = GetRootRecord (configuration, result.TestDate);
			if (root == null) {
				root = new TestRecord ();
				fileCache [GetRootFileName (configuration, result.TestDate)] = root;
			}
			root.Modified = true;
			TestRecord record = root;
			
			if (aname.Length > 0) {
				string[] path = test.StoreRelativeName.Split ('.');
				foreach (string p in path) {
					TestRecord ctr = record.Tests != null ? record.Tests [p] : null;
					if (ctr == null) {
						ctr = new TestRecord ();
						ctr.Name = p;
						if (record.Tests == null)
							record.Tests = new TestRecordCollection ();
						record.Tests.Add (ctr);
					}
					record = ctr;
				}
			}
			
			if (record.Results == null)
				record.Results = new UnitTestResultCollection ();
			record.Results.Add (result);
		}
Esempio n. 3
0
		public void RegisterResult (string configuration, UnitTest test, UnitTestResult result)
		{
			//This method can be called from multiple threads when remote process(test runner) is responding
			//This lock is protecting collections fileCache, record.Tests and record.Results
			lock (fileCache) {
				string aname = test.StoreRelativeName;

				TestRecord root = GetRootRecord (configuration, result.TestDate);
				if (root == null) {
					root = new TestRecord ();
					fileCache [GetRootFileName (configuration, result.TestDate)] = root;
				}
				root.Modified = true;
				TestRecord record = root;

				if (aname.Length > 0) {
					string [] path = test.StoreRelativeName.Split ('.');
					foreach (string p in path) {
						TestRecord ctr = record.Tests != null ? record.Tests [p] : null;
						if (ctr == null) {
							ctr = new TestRecord ();
							ctr.Name = p;
							if (record.Tests == null)
								record.Tests = new TestRecordCollection ();
							record.Tests.Add (ctr);
						}
						record = ctr;
					}
				}

				if (record.Results == null)
					record.Results = new UnitTestResultCollection ();
				record.Results.Add (result);
			}
		}
Esempio n. 4
0
        TestRecord GetRootRecord(string configuration, DateTime date)
        {
            string     file = GetRootFileName(configuration, date);
            TestRecord res  = (TestRecord)fileCache [file];

            if (res != null)
            {
                return(res);
            }
            string filePath;

            try {
                filePath = Path.Combine(basePath, file);
            } catch (Exception) {
                return(null);
            }

            try {
                res = (TestRecord)serializer.Deserialize(filePath);
            } catch (Exception ex) {
                LoggingService.LogError(ex.ToString());
                return(null);
            }

            if (res != null)
            {
                fileCache [file] = res;
            }
            return(res);
        }
Esempio n. 5
0
 TestRecord FindRecord(TestRecord root, string aname)
 {
     if (aname.Length == 0)
     {
         return(root);
     }
     else
     {
         string[]   path = aname.Split('.');
         TestRecord tr   = root;
         foreach (string p in path)
         {
             if (tr.Tests == null)
             {
                 return(null);
             }
             tr = tr.Tests [p];
             if (tr == null)
             {
                 return(null);
             }
         }
         return(tr);
     }
 }
Esempio n. 6
0
        public void Save()
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            foreach (DictionaryEntry entry in fileCache)
            {
                TestRecord record = (TestRecord)entry.Value;
                if (!record.Modified)
                {
                    continue;
                }

                string filePath = Path.Combine(basePath, (string)entry.Key);
                try {
                    serializer.Serialize(filePath, record);
                    record.Modified = false;
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                }
            }
            cachedRootList.Clear();
        }
Esempio n. 7
0
        public UnitTestResult GetPreviousResult(string configuration, UnitTest test, DateTime date)
        {
            DateTime   currentDate = date;
            TestRecord root        = GetRootRecord(configuration, currentDate);

            if (root == null)
            {
                root = GetPreviousRootRecord(configuration, ref currentDate);
            }

            while (root != null)
            {
                TestRecord tr = FindRecord(root, test.StoreRelativeName);
                if (tr != null && tr.Results != null)
                {
                    for (int n = tr.Results.Count - 1; n >= 0; n--)
                    {
                        UnitTestResult res = (UnitTestResult)tr.Results [n];
                        if (res.TestDate < date)
                        {
                            return(res);
                        }
                    }
                }
                root = GetPreviousRootRecord(configuration, ref currentDate);
            }
            return(null);
        }
Esempio n. 8
0
        public void Serialize(string xmlFilePath, TestRecord testRecord)
        {
            // no need for xml serialization because next time it will be
            // deserialized from the binary format
            string binaryFilePath = GetBinaryFilePath(xmlFilePath);

            using (var stream = File.OpenWrite(binaryFilePath)) {
                fastSerializer.Serialize(stream, testRecord);
            }
        }
Esempio n. 9
0
        public void Serialize(string xmlFilePath, TestRecord testRecord)
        {
            // no need for xml serialization because next time it will be
            // deserialized from the binary format
            string binaryFilePath = GetBinaryFilePath(xmlFilePath);

            using var stream = File.OpenWrite(binaryFilePath);
            using var writer = new StreamWriter(stream);

            jsonSerializer.Serialize(writer, testRecord);
        }
Esempio n. 10
0
        public void RegisterResult(string configuration, UnitTest test, UnitTestResult result)
        {
            //This method can be called from multiple threads when remote process(test runner) is responding
            //This lock is protecting collections fileCache, record.Tests and record.Results
            lock (fileCache) {
                string aname = test.StoreRelativeName;

                TestRecord root = GetRootRecord(configuration, result.TestDate);
                if (root == null)
                {
                    root = new TestRecord();
                    fileCache [GetRootFileName(configuration, result.TestDate)] = root;
                }
                root.Modified = true;
                TestRecord record = root;

                if (aname.Length > 0)
                {
                    string [] path = test.StoreRelativeName.Split('.');
                    foreach (string p in path)
                    {
                        TestRecord ctr = record.Tests != null ? record.Tests [p] : null;
                        if (ctr == null)
                        {
                            ctr      = new TestRecord();
                            ctr.Name = p;
                            if (record.Tests == null)
                            {
                                record.Tests = new TestRecordCollection();
                            }
                            record.Tests.Add(ctr);
                        }
                        record = ctr;
                    }
                }

                if (record.Results == null)
                {
                    record.Results = new UnitTestResultCollection();
                }
                record.Results.Add(result);
            }
        }
Esempio n. 11
0
        public UnitTestResult[] GetResults(string configuration, UnitTest test, DateTime startDate, DateTime endDate)
        {
            ArrayList list     = new ArrayList();
            DateTime  firstDay = new DateTime(startDate.Year, startDate.Month, startDate.Day);

            DateTime[] dates = GetStoreDates(configuration);

            lock (fileCache) {
                foreach (DateTime date in dates)
                {
                    if (date < firstDay)
                    {
                        continue;
                    }
                    if (date > endDate)
                    {
                        break;
                    }

                    TestRecord root = GetRootRecord(configuration, date);
                    if (root == null)
                    {
                        continue;
                    }

                    TestRecord tr = FindRecord(root, test.StoreRelativeName);
                    if (tr != null && tr.Results != null)
                    {
                        foreach (UnitTestResult res in tr.Results)
                        {
                            if (res.TestDate >= startDate && res.TestDate <= endDate)
                            {
                                list.Add(res);
                            }
                        }
                    }
                }
            }

            return((UnitTestResult[])list.ToArray(typeof(UnitTestResult)));
        }
Esempio n. 12
0
        public void RegisterResult(string configuration, UnitTest test, UnitTestResult result)
        {
            string aname = test.StoreRelativeName;

            TestRecord root = GetRootRecord(configuration, result.TestDate);

            if (root == null)
            {
                root = new TestRecord();
                fileCache [GetRootFileName(configuration, result.TestDate)] = root;
            }
            root.Modified = true;
            TestRecord record = root;

            if (aname.Length > 0)
            {
                string[] path = test.StoreRelativeName.Split('.');
                foreach (string p in path)
                {
                    TestRecord ctr = record.Tests != null ? record.Tests [p] : null;
                    if (ctr == null)
                    {
                        ctr      = new TestRecord();
                        ctr.Name = p;
                        if (record.Tests == null)
                        {
                            record.Tests = new TestRecordCollection();
                        }
                        record.Tests.Add(ctr);
                    }
                    record = ctr;
                }
            }

            if (record.Results == null)
            {
                record.Results = new UnitTestResultCollection();
            }
            record.Results.Add(result);
        }
Esempio n. 13
0
        public UnitTestResult[] GetResultsToDate(string configuration, UnitTest test, DateTime endDate, int count)
        {
            ArrayList list = new ArrayList();

            DateTime[] dates = GetStoreDates(configuration);

            lock (fileCache) {
                for (int n = dates.Length - 1; n >= 0 && list.Count < count; n--)
                {
                    if (dates [n] > endDate)
                    {
                        continue;
                    }

                    TestRecord root = GetRootRecord(configuration, dates [n]);
                    if (root == null)
                    {
                        continue;
                    }

                    TestRecord tr = FindRecord(root, test.StoreRelativeName);
                    if (tr != null && tr.Results != null)
                    {
                        for (int m = tr.Results.Count - 1; m >= 0 && list.Count < count; m--)
                        {
                            UnitTestResult res = (UnitTestResult)tr.Results [m];
                            if (res.TestDate <= endDate)
                            {
                                list.Add(res);
                            }
                        }
                    }
                }
            }

            UnitTestResult[] array = (UnitTestResult[])list.ToArray(typeof(UnitTestResult));
            Array.Reverse(array);
            return(array);
        }
Esempio n. 14
0
 public void Add(TestRecord test)
 {
     ((IList)this).Add(test);
 }
		public void Add (TestRecord test)
		{
			((IList)this).Add (test);
		}
		TestRecord FindRecord (TestRecord root, string aname)
		{
			if (aname.Length == 0)
				return root;
			else {
				string[] path = aname.Split ('.');
				TestRecord tr = root;
				foreach (string p in path) {
					if (tr.Tests == null)
						return null;
					tr = tr.Tests [p];
					if (tr == null)
						return null;
				}
				return tr;
			}
		}