コード例 #1
0
        public void BibtexRecordGetYear()
        {
            var record = new BibtexRecord();

            Assert.AreEqual("", record.GetYear());
            record.SetField("year", "2016");
            Assert.AreEqual("2016", record.GetYear());
        }
コード例 #2
0
        public void BibtexRecordGetJournal()
        {
            var record = new BibtexRecord();

            Assert.AreEqual("", record.GetJournal());
            record.SetField("journal", "test journal");
            Assert.AreEqual("test journal", record.GetJournal());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        public void RecordCompare()
        {
            var record1 = new BibtexRecord();
            var record2 = new BibtexRecord();

            Assert.AreNotSame(record1, record2, "Two record instances are not the same");

            record1.SetKey("testKey");
            record2.SetKey("testKey");

            Assert.AreNotSame(record1, record2, "Two record instances are not the same when they have the same key");
        }
コード例 #5
0
        public void RecordsCompare()
        {
            var records1 = new BibtexRecords();
            var records2 = new BibtexRecords();

            Assert.AreNotSame(records1, records2, "Two records instances are not the same");

            var record = new BibtexRecord();

            records1.Add(record);
            records2.Add(record);

            Assert.AreNotSame(records1, records2, "Two records instances are not the same when they have the same record stored within them");
        }
コード例 #6
0
        public void EmptyRecord()
        {
            var record = new BibtexRecord();

            Assert.IsInstanceOf <BibtexRecord>(record);

            Assert.AreEqual(record.RecordType, "", "Empty record's RecordType is an empty string");
            Assert.AreEqual(record.GetKey(), "", "Empty record's Key is an empty string");
            Assert.AreEqual(record.GetAuthors(), new StringArrayList(), "Empty record's Authors array is an empty StringArrayList");
            Assert.AreEqual(record.GetAuthorsString(), "", "Empty record's Authors string is an empty string");
            Assert.AreEqual(record.GetJournal(), "", "Empty record's Journal is an empty string");
            Assert.AreEqual(record.GetYear(), "", "Empty record's Year is an empty string");
            Assert.IsNull(record.GetURI(), "Empty record's URI is null");
            Assert.IsFalse(record.HasURI(), "Empty record does not have an URI");
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }