public void PerformanceCounterPersistence_SaveEmpty_ExpectCountersSaved() { PerformanceCounterPersistence obj = new PerformanceCounterPersistence(new FileWrapper()); IList <IPerformanceCounter> counters = new List <IPerformanceCounter>(); var fileName = Path.GetTempFileName(); obj.Save(counters, fileName); var saved = File.ReadAllText(fileName); Dev2JsonSerializer serialiser = new Dev2JsonSerializer(); var persisted = serialiser.Deserialize <IList <IPerformanceCounter> >(saved); Assert.IsNotNull(persisted); File.Delete(fileName); }
public void PerformanceCounterPersistence_Save_ExpectCountersSaved() { var obj = new PerformanceCounterPersistence(new FileWrapper()); IList <IPerformanceCounter> counters = new List <IPerformanceCounter>(); counters.Add(new TestCounter()); var fileName = Path.GetTempFileName(); obj.Save(counters, fileName); var saved = File.ReadAllText(fileName); var serialiser = new Dev2JsonSerializer(); var persisted = serialiser.Deserialize <IList <IPerformanceCounter> >(saved); Assert.AreEqual(persisted.Count, 1); File.Delete(fileName); }
public void PerformanceCounterPersistence_Load_ExpectCountersRecreatedForNoFile() { var _file = new Mock <IFile>(); var register = new Mock <IWarewolfPerformanceCounterRegister>(); PerformanceCounterPersistence obj = new PerformanceCounterPersistence(_file.Object); IList <IPerformanceCounter> counters = new List <IPerformanceCounter>(); counters.Add(new TestCounter()); register.Setup(a => a.DefaultCounters).Returns(counters); var fileName = Path.GetTempFileName(); _file.Setup(a => a.Exists(fileName)).Returns(false); obj.Save(counters, fileName); var persisted = obj.LoadOrCreate(fileName); Assert.AreEqual(persisted.Count, 6); File.Delete(fileName); }
public void PerformanceCounterPersistence_Load_ExpectCountersLoadedForExistingFile() { var _file = new Mock <IFile>(); var obj = new PerformanceCounterPersistence(_file.Object); IList <IPerformanceCounter> counters = new List <IPerformanceCounter>(); counters.Add(new TestCounter()); var fileName = Path.GetTempFileName(); _file.Setup(a => a.Exists(fileName)).Returns(true); obj.Save(counters, fileName); var serialiser = new Dev2JsonSerializer(); File.WriteAllText(fileName, serialiser.Serialize(counters)); _file.Setup(a => a.ReadAllText(fileName)).Returns(File.ReadAllText(fileName)); var persisted = obj.LoadOrCreate(fileName); Assert.AreEqual(persisted.Count, 1); File.Delete(fileName); }