public TestView() { InitializeComponent(); heater4.ValueONDelegete = new HMIBooleanBase.StatePosition(ValueOnFunc); //heater4.ValueOFFDelegete = new HMIBooleanBase.StatePosition(ValueOffFunc); _data = new Collection <TestDataItem>(); arrXdate = new DateTime[1000]; arrX = new double[1000]; arrY = new double[1000]; for (int i = 0; i < 1000; i++) { TestDataItem point = new TestDataItem() { Member = DateTime.Now + new TimeSpan(0, 0, i), Value = i }; _data.Add(point); arrXdate[i] = DateTime.Now + new TimeSpan(0, 0, i); arrX[i] = i; arrY[i] = i; } MyPoints = new Collection <MyPoint>(); for (int i = 0; i < 1000; i++) { MyPoint point = new MyPoint(i, i); MyPoints.Add(point); } }
public void DataItemConstructorTest() { var testDataItem = new TestDataItem(); Assert.IsInstanceOf <TestDataItem>(testDataItem); Assert.That(testDataItem.Id, Is.EqualTo(0)); }
public TestDataSection(XElement testDataSectionElement) { this.name = testDataSectionElement.Attribute(TestDataSection.NameAttribute).Value; foreach (XElement testDataItemElement in testDataSectionElement.Elements()) { TestDataItem testDataItem = new TestDataItem(testDataItemElement); this.testDataItemsByName[testDataItem.Name] = testDataItem; } }
/// <summary> /// Assigns a test data item in the specified XML section. /// </summary> public void SetXml(string sectionName, string itemName, string newXml) { TestDataItem testDataItem = this.GetTestDataItem(sectionName, itemName); if (this.Normalizer != null) { newXml = this.Normalizer.GetNormalized(newXml); } testDataItem.Xml = newXml; }
/// <summary> /// Comparse the test data item in the specified XML section against the /// provided otherXml value. /// </summary> public bool CompareXml(string sectionName, string itemName, string otherXml) { TestDataItem testDataItem = this.GetTestDataItem(sectionName, itemName); var otherDocument = XDocument.Parse(otherXml); if (this.Normalizer != null) { this.Normalizer.NormalizeDocument(otherDocument); } return(testDataItem.IsXmlEqual(otherDocument.Nodes())); }
public void TestPositionHashVerification() { var folderName = "TestPositionHashVerification"; IFolder folder = CreateNewTestFolder(folderName); folder.Properties.DesiredItemsPerFile = 10; var testItems = new TestDataItem[200]; for (int n = 0; n < testItems.Length; ++n) { var item = TestDataItem.GetTestItem(n); item.DateTime = DateTime.Now.AddDays(n); testItems[n] = item; } using (var writer = folder.GetWriter()) { foreach (var item in testItems) { writer.Write(item); } } SeekStatusListener seekStatusListener = new SeekStatusListener(); using (var reader = folder.GetReader(DateTime.Now.AddHours(-1), false)) { Random random = new Random(); int skipItems = random.Next(50, 150); for (int n = 0; n < skipItems; ++n) { Assert.AreEqual(testItems[n], reader.Read().DataItem); } var position = new ReadingPosition(reader.Position); FolderReadingPosition folderPos = (FolderReadingPosition)position.FolderPositions[folder.FolderKey]; Assert.IsNotNull(folderPos); folderPos.VerificationLastReadItemHash = ~folderPos.VerificationLastReadItemHash; using (var altReader = Repository.ObjectFactory.GetReader(position, seekStatusListener.HanldeStatus)) { for (int n = skipItems; n < testItems.Length; ++n) { Assert.AreEqual(testItems[n], altReader.Read().DataItem); } } Assert.AreEqual(1, seekStatusListener.Statuses.Count); Assert.AreEqual(FolderSeekStatus.PositionStatus.DataItemHashMismatch, seekStatusListener.Statuses[0].Status); } }
public void DataItemValueChangedDoesNotFireTest() { var testDataItem = new TestDataItem(); var receivedPropertyChanges = new List <string>(); testDataItem.ValueChanged += delegate(object sender, DataItemEventArgs args) { receivedPropertyChanges.Add(args.PropertyName); }; testDataItem.Id = 0; Assert.That(receivedPropertyChanges, Is.Empty); }
public void DataItemValueChangedFiresTest() { var testDataItem = new TestDataItem(); var receivedPropertyChanges = new List <string>(); testDataItem.ValueChanged += delegate(object sender, DataItemEventArgs args) { receivedPropertyChanges.Add(args.PropertyName); }; testDataItem.Id = 1; Assert.That(receivedPropertyChanges.Count, Is.EqualTo(1)); Assert.That(receivedPropertyChanges, Has.Member(nameof(testDataItem.Id))); }
public void LoadSubfoldersTest() { const string topFolderName = "LoadSubfoldersTest"; const string subFolderName1 = "sub1"; const string subFolderName2 = "sub2"; IFolder topFolder = CreateNewTestFolder(topFolderName); IFolder sub1 = topFolder.CreateSubfolder(subFolderName1); IFolder sub2 = topFolder.CreateSubfolder(subFolderName2); Assert.AreEqual(2, topFolder.SubFolders.Count); Assert.IsNull(sub1.Properties.DisplayName, "Display name must be null after creation"); IRepository repoStandalone = GetStandaloneRepository(); IFolder sub1Alt = repoStandalone.RootFolder.GetDescendant(sub1.LogicalPath, false); const string newDisplayName1 = "newDisplayName1"; sub1Alt.Properties.DisplayName = newDisplayName1; // check that instances are preserved topFolder.LoadSubfolders(true, false, false); Assert.AreEqual(2, topFolder.SubFolders.Count); Assert.AreSame(sub1, topFolder.GetSubFolder(subFolderName1), "Existing folder instance not preserved"); Assert.AreSame(sub2, topFolder.GetSubFolder(subFolderName2), "Existing folder instance not preserved"); Assert.IsNull(sub1.Properties.DisplayName, "Contents refreshed "); // check that missing folder is purged sub1Alt.Delete(true, true); Assert.Throws(Is.InstanceOf <InvalidOperationException>(), () => sub1Alt.Delete(true, true)); topFolder.LoadSubfolders(true, false, false); Assert.AreEqual(1, topFolder.SubFolders.Count); Assert.AreSame(sub2, topFolder.GetSubFolder(subFolderName2), "Existing folder instance not preserved"); Assert.IsTrue(sub1.IsDetached, "Purged subfolder must be detached after reloading"); // check that subfolders are unloaded topFolder.UnloadSubfolders(); Assert.IsFalse(topFolder.SubfoldersLoaded); // now check that with reload OFF folders are reloaded topFolder.LoadSubfolders(reloadIfLoaded: false, recursive: false, refreshContent: false); Assert.AreEqual(1, topFolder.SubFolders.Count); // recreating previously deleted folder sub1 = topFolder.CreateSubfolder(subFolderName1); Assert.IsNull(sub1.Properties.DisplayName, "Display name must be null after creation"); // note that tis is required to make sure data folders are loaded to check refreshContent option later Assert.IsNull(sub1.GetDataFileIterator(false).Seek(DateTime.MinValue)); repoStandalone.RootFolder.UnloadSubfolders(); sub1Alt = repoStandalone.RootFolder.GetDescendant(sub1.LogicalPath, false); sub1Alt.Properties.Description = newDisplayName1; using (var writer = sub1Alt.GetWriter()) { writer.Write(TestDataItem.GetTestItem(2)); } topFolder.LoadSubfolders(reloadIfLoaded: false, recursive: false, refreshContent: false); Assert.IsNull(sub1.Properties.Description, "Did not ask for content refreshing"); Assert.IsNull(sub1.GetDataFileIterator(false).Seek(DateTime.MinValue)); topFolder.LoadSubfolders(reloadIfLoaded: true, recursive: false, refreshContent: true); Assert.AreEqual(newDisplayName1, sub1.Properties.Description, "Did ask for content to be refreshed"); Assert.IsNotNull(sub1.GetDataFileIterator(false).Seek(DateTime.MinValue)); }
public bool TryGetValue(string itemName, out TestDataItem testDataItem) { return(this.testDataItemsByName.TryGetValue(itemName, out testDataItem)); }
/// <summary> /// Returns an test data item from the specified XML section. /// </summary> public string GetXml(string sectionName, string itemName) { TestDataItem testDataItem = this.GetTestDataItem(sectionName, itemName); return(testDataItem.Xml); }