public void BibtexRecordGetYear() { var record = new BibtexRecord(); Assert.AreEqual("", record.GetYear()); record.SetField("year", "2016"); Assert.AreEqual("2016", record.GetYear()); }
public void BibtexRecordGetJournal() { var record = new BibtexRecord(); Assert.AreEqual("", record.GetJournal()); record.SetField("journal", "test journal"); Assert.AreEqual("test journal", record.GetJournal()); }
public void BibtexRecordGetDOI() { var record = new BibtexRecord(); Assert.AreEqual("", record.GetDOI()); Assert.AreEqual(false, record.HasDOI()); record.SetField("doi", "testdoi"); Assert.AreEqual("testdoi", record.GetDOI()); Assert.AreEqual(true, record.HasDOI()); }
public void RecordsEvents() { bool recordAdded, recordDeleted, recordModified, recordsModified, recordURIAdded, recordURIModified; int recordAddedCount, recordDeletedCount, recordModifiedCount, recordsModifiedCount, recordURIAddedCount, recordURIModifiedCount; recordAdded = false; recordDeleted = false; recordModified = false; recordsModified = false; recordURIAdded = false; recordURIModified = false; recordAddedCount = 0; recordDeletedCount = 0; recordModifiedCount = 0; recordsModifiedCount = 0; recordURIAddedCount = 0; recordURIModifiedCount = 0; var records = new BibtexRecords(); var record = new BibtexRecord(); records.RecordAdded += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); recordAdded = true; recordAddedCount += 1; }; records.RecordDeleted += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); recordDeleted = true; recordDeletedCount += 1; }; records.RecordModified += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); recordModified = true; recordModifiedCount += 1; }; records.RecordsModified += delegate(object sender, EventArgs e) { Assert.AreNotSame(sender, record, "Delegate sender is not the record"); recordsModified = true; recordsModifiedCount += 1; }; records.RecordURIAdded += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); recordURIAdded = true; recordURIAddedCount += 1; }; records.RecordURIModified += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); recordURIModified = true; recordURIModifiedCount += 1; }; records.Add(record); Assert.IsTrue(recordAdded, "RecordAdded event is meant to be raised"); Assert.IsFalse(recordDeleted, "RecordDeleted event is not meant to be raised"); Assert.IsFalse(recordModified, "RecordModified event is not meant to be raised"); Assert.IsTrue(recordsModified, "RecordsModified event is meant to be raised"); Assert.IsFalse(recordURIAdded, "RecordURIAdded event is not meant to be raised"); Assert.IsFalse(recordURIModified, "RecordURIModified event is not meant to be raised"); Assert.AreEqual(1, recordAddedCount); Assert.AreEqual(0, recordDeletedCount); Assert.AreEqual(0, recordModifiedCount); Assert.AreEqual(1, recordsModifiedCount); Assert.AreEqual(0, recordURIAddedCount); Assert.AreEqual(0, recordURIModifiedCount); recordAdded = false; recordDeleted = false; recordModified = false; recordsModified = false; recordURIAdded = false; recordURIModified = false; recordAddedCount = 0; recordDeletedCount = 0; recordModifiedCount = 0; recordsModifiedCount = 0; recordURIAddedCount = 0; recordURIModifiedCount = 0; record.SetField("test_field", "test_data"); Assert.IsFalse(recordAdded, "RecordAdded event is not meant to be raised"); Assert.IsFalse(recordDeleted, "RecordDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsFalse(recordsModified, "RecordsModified event is not meant to be raised"); Assert.IsFalse(recordURIAdded, "RecordURIAdded event is not meant to be raised"); Assert.IsFalse(recordURIModified, "RecordURIModified event is not meant to be raised"); Assert.AreEqual(0, recordAddedCount); Assert.AreEqual(0, recordDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, recordsModifiedCount); Assert.AreEqual(0, recordURIAddedCount); Assert.AreEqual(0, recordURIModifiedCount); recordAdded = false; recordDeleted = false; recordModified = false; recordsModified = false; recordURIAdded = false; recordURIModified = false; recordAddedCount = 0; recordDeletedCount = 0; recordModifiedCount = 0; recordsModifiedCount = 0; recordURIAddedCount = 0; recordURIModifiedCount = 0; record.SetURI("file://tmp/test"); Assert.IsFalse(recordAdded, "RecordAdded event is not meant to be raised"); Assert.IsFalse(recordDeleted, "RecordDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsFalse(recordsModified, "RecordsModified event is not meant to be raised"); Assert.IsTrue(recordURIAdded, "RecordURIAdded event is meant to be raised"); Assert.IsFalse(recordURIModified, "RecordURIModified event is not meant to be raised"); Assert.AreEqual(0, recordAddedCount); Assert.AreEqual(0, recordDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, recordsModifiedCount); Assert.AreEqual(1, recordURIAddedCount); Assert.AreEqual(0, recordURIModifiedCount); recordAdded = false; recordDeleted = false; recordModified = false; recordsModified = false; recordURIAdded = false; recordURIModified = false; recordAddedCount = 0; recordDeletedCount = 0; recordModifiedCount = 0; recordsModifiedCount = 0; recordURIAddedCount = 0; recordURIModifiedCount = 0; record.SetURI("file://tmp/test1"); Assert.IsFalse(recordAdded, "RecordAdded event is not meant to be raised"); Assert.IsFalse(recordDeleted, "RecordDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsFalse(recordsModified, "RecordsModified event is not meant to be raised"); Assert.IsFalse(recordURIAdded, "RecordURIAdded event is not meant to be raised"); Assert.IsTrue(recordURIModified, "RecordURIModified event is meant to be raised"); Assert.AreEqual(0, recordAddedCount); Assert.AreEqual(0, recordDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, recordsModifiedCount); Assert.AreEqual(0, recordURIAddedCount); Assert.AreEqual(1, recordURIModifiedCount); recordAdded = false; recordDeleted = false; recordModified = false; recordsModified = false; recordURIAdded = false; recordURIModified = false; recordAddedCount = 0; recordDeletedCount = 0; recordModifiedCount = 0; recordsModifiedCount = 0; recordURIAddedCount = 0; recordURIModifiedCount = 0; records.Remove(record); Assert.IsFalse(recordAdded, "RecordAdded event is not meant to be raised"); Assert.IsTrue(recordDeleted, "RecordDeleted event is not meant to be raised"); Assert.IsFalse(recordModified, "RecordModified event is meant to be raised"); Assert.IsTrue(recordsModified, "RecordsModified event is not meant to be raised"); Assert.IsFalse(recordURIAdded, "RecordURIAdded event is not meant to be raised"); Assert.IsFalse(recordURIModified, "RecordURIModified event is not meant to be raised"); Assert.AreEqual(0, recordAddedCount); Assert.AreEqual(1, recordDeletedCount); Assert.AreEqual(0, recordModifiedCount); Assert.AreEqual(1, recordsModifiedCount); Assert.AreEqual(0, recordURIAddedCount); Assert.AreEqual(0, recordURIModifiedCount); }
public void RecordEvents() { bool fieldAdded, fieldDeleted, recordModified, uriAdded, uriUpdated, doiAdded, doiUpdated; int fieldAddedCount, fieldDeletedCount, recordModifiedCount, uriAddedCount, uriUpdatedCount, doiAddedCount, doiUpdatedCount; fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; var record = new BibtexRecord(); record.FieldAdded += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); fieldAdded = true; fieldAddedCount += 1; }; record.FieldDeleted += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); fieldDeleted = true; fieldDeletedCount += 1; }; record.RecordModified += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); recordModified = true; recordModifiedCount += 1; }; record.UriAdded += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); uriAdded = true; uriAddedCount += 1; }; record.UriUpdated += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); uriUpdated = true; uriUpdatedCount += 1; }; record.DoiAdded += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); doiAdded = true; doiAddedCount += 1; }; record.DoiUpdated += delegate(object sender, EventArgs e) { Assert.AreSame(sender, record, "Delegate sender is the record"); doiUpdated = true; doiUpdatedCount += 1; }; record.SetField("test_field", "test_data"); Assert.IsTrue(fieldAdded, "FieldAdded event is meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is not meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(1, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; record.RemoveField("test_field"); Assert.IsFalse(fieldAdded, "FieldAdded event is not meant to be raised"); Assert.IsTrue(fieldDeleted, "FieldDeleted event is meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is not meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(0, fieldAddedCount); Assert.AreEqual(1, fieldDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; // Adding URI record.SetURI("file://tmp/test"); Assert.IsFalse(fieldAdded, "FieldAdded event is meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsTrue(uriAdded, "URIAdded event is meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(0, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(1, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; // Setting URI without a change record.SetURI("file://tmp/test"); Assert.IsFalse(fieldAdded, "FieldAdded event is not meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsFalse(recordModified, "RecordModified event is not meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is not meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(0, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(0, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; // Updating URI record.SetURI("file:///tmp/test1"); Assert.IsFalse(fieldAdded, "FieldAdded event is not meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsTrue(uriUpdated, "URIUpdated event is meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is not meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is meant to be raised"); Assert.AreEqual(0, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(1, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; record.SetField("doi", "testdoi"); Assert.IsTrue(fieldAdded, "FieldAdded event is not meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is not meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsTrue(doiAdded, "DOIAdded event is meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(1, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(1, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; // re-setting doi without change record.SetField("doi", "testdoi"); Assert.IsFalse(fieldAdded, "FieldAdded event is not meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsFalse(recordModified, "RecordModified event is not meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is not meant to be raised"); Assert.IsFalse(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(0, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(0, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(0, doiUpdatedCount); fieldAdded = false; fieldDeleted = false; recordModified = false; uriAdded = false; uriUpdated = false; doiAdded = false; doiUpdated = false; fieldAddedCount = 0; fieldDeletedCount = 0; recordModifiedCount = 0; uriAddedCount = 0; uriUpdatedCount = 0; doiAddedCount = 0; doiUpdatedCount = 0; // updating doi to new value record.SetField("doi", "testdoiwithchange"); Assert.IsFalse(fieldAdded, "FieldAdded event is not meant to be raised"); Assert.IsFalse(fieldDeleted, "FieldDeleted event is not meant to be raised"); Assert.IsTrue(recordModified, "RecordModified event is not meant to be raised"); Assert.IsFalse(uriAdded, "URIAdded event is not meant to be raised"); Assert.IsFalse(uriUpdated, "URIUpdated event is not meant to be raised"); Assert.IsFalse(doiAdded, "DOIAdded event is not meant to be raised"); Assert.IsTrue(doiUpdated, "DOIUpdated event is not meant to be raised"); Assert.AreEqual(0, fieldAddedCount); Assert.AreEqual(0, fieldDeletedCount); Assert.AreEqual(1, recordModifiedCount); Assert.AreEqual(0, uriAddedCount); Assert.AreEqual(0, uriUpdatedCount); Assert.AreEqual(0, doiAddedCount); Assert.AreEqual(1, doiUpdatedCount); }