Exemple #1
0
 public void WriteCacheToFile(string path)
 {
     try
     {
         File.WriteAllText(path, JsonConvert.SerializeObject(_candidates));
     }
     catch (Exception e)
     {
         CodeGenOutput.Warning($"Unable to write test discovery cache file: {path}.\n{e.ToString()}");
     }
 }
Exemple #2
0
        private Dictionary <string, List <UnitTestInfo> > LoadCacheFromFile(string path)
        {
            Dictionary <string, List <UnitTestInfo> > cache = null;

            if (File.Exists(path))
            {
                UnitTestInfo[] cachedTests = null;
                try
                {
                    cachedTests = ReadCacheFromFile(path);

                    Dictionary <string, DateTime> assmTimestamp = new Dictionary <string, DateTime>();

                    cache = new Dictionary <string, List <UnitTestInfo> >();

                    foreach (var test in cachedTests)
                    {
                        DateTime currentAssmTimestamp;

                        if (!assmTimestamp.TryGetValue(test.AssemblyPath, out currentAssmTimestamp))
                        {
                            currentAssmTimestamp = File.Exists(test.AssemblyPath) ? File.GetLastWriteTime(test.AssemblyPath) : DateTime.MaxValue;

                            assmTimestamp[test.AssemblyPath] = currentAssmTimestamp;
                        }

                        if (currentAssmTimestamp == test.AssemblyLastModified)
                        {
                            List <UnitTestInfo> assmTests;
                            if (!cache.TryGetValue(test.AssemblyPath, out assmTests))
                            {
                                assmTests = new List <UnitTestInfo>();

                                cache[test.AssemblyPath] = assmTests;
                            }

                            assmTests.Add(test);
                        }
                    }
                }
                catch (Exception e)
                {
                    CodeGenOutput.Warning($"Unable to read test discovery cache file: {path}.\n{e.ToString()}");
                }
            }

            return(cache);
        }
        public void WriteCacheToFile(string path)
        {
            try
            {
                // Serialize the RunConfiguration
                JsonSerializer serializer = JsonSerializer.CreateDefault();

                using (FileStream fs = new FileStream(path, FileMode.Create))
                {
                    using (StreamWriter writer = new StreamWriter(fs))
                    {
                        serializer.Serialize(writer, _candidates);
                    }
                }
            }
            catch (Exception e)
            {
                CodeGenOutput.Warning($"Unable to write test discovery cache file: {path}.\n{e.ToString()}");
            }
        }