コード例 #1
0
ファイル: GuideEntryTests.cs プロジェクト: rocketeerbkw/DNA
        public void EnsureValidH2G2IDSucceedsToCreate()
        {
            // Create a mockery of the input context
            Mockery mockery = new Mockery();
            IInputContext mockedContext = mockery.NewMock<IInputContext>();

            IDnaDataReader mockedReader = mockery.NewMock<IDnaDataReader>();
            Stub.On(mockedReader).Method("AddParameter").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).Method("Execute").Will(Return.Value(mockedReader));
            Stub.On(mockedReader).GetProperty("HasRows").Will(Return.Value(true));
            Stub.On(mockedReader).Method("Read").Will(Return.Value(true));
            
            // Set the expiry date to be 1 minute from now
            Stub.On(mockedReader).Method("GetInt32").With("seconds").Will(Return.Value(60));
            Stub.On(mockedReader).Method("Dispose").Will(Return.Value(null));

            Stub.On(mockedContext).Method("CreateDnaDataReader").With("cachegetarticleinfo").Will(Return.Value(mockedReader));

            // Return false for now as it's bloody inpossible to test methods that use ref params!!!
            Stub.On(mockedContext).Method("FileCacheGetItem").Will(Return.Value(false));

            // Now create the setup object and create the guideentry
            GuideEntrySetup setup = new GuideEntrySetup(388217);
            GuideEntry testEntry = new GuideEntry(mockedContext, setup);

            // Test the initialisation code.
            Assert.IsTrue(testEntry.Initialise(), "Valid h2g2id should return true!");
        }
コード例 #2
0
ファイル: GuideEntryTests.cs プロジェクト: rocketeerbkw/DNA
        public void EnsureInvalidH2G2IDFailsToCreate()
        {
            // Create a mockery of the input context
            Mockery mockery = new Mockery();
            IInputContext mockedContext = mockery.NewMock<IInputContext>();

            // Now create the setup object and create the guideentry
            GuideEntrySetup setup = new GuideEntrySetup(123456789);
            GuideEntry testEntry = new GuideEntry(mockedContext, setup);

            // Test the initialisation code.
            Assert.IsFalse(testEntry.Initialise(), "Invalid h2g2id should return false!");
        }
コード例 #3
0
ファイル: DNAComponentTests.cs プロジェクト: rocketeerbkw/DNA
        public void TestUpdatingOfRelativeDates()
        {
            // Create a dna guidentry component
            Mockery mock = new Mockery();
            IInputContext mockedContext = mock.NewMock<IInputContext>();
            GuideEntry testComponent = new GuideEntry(mockedContext, new GuideEntrySetup(5176));

            // Now create a date block in the xml
            testComponent.AddDateXml(DateTime.UtcNow.Subtract(new TimeSpan(5,5,0)),testComponent.RootElement,"TESTDATE");

            
            // Remove the Relative date attribute
            testComponent.RootElement.SelectSingleNode("//TESTDATE/DATE").Attributes.RemoveNamedItem("RELATIVE");
            Assert.IsTrue(testComponent.RootElement.SelectSingleNode("//TESTDATE/DATE").Attributes["RELATIVE"] == null, "Shouldn't have a relative date attribute at this stage!");

            // Now update the relative date attribute
            testComponent.UpdateRelativeDates();
            Assert.IsTrue(testComponent.RootElement.SelectSingleNode("//TESTDATE/DATE").Attributes["RELATIVE"] != null, "Should have a relative date attribute at this stage!");
            Assert.IsTrue(testComponent.RootElement.SelectSingleNode("//TESTDATE/DATE").Attributes["RELATIVE"].Value.CompareTo("5 Hours Ago") == 0, "The relative time should be 5 hours ago! It's " + testComponent.RootElement.SelectSingleNode("//TESTDATE/DATE").Attributes["RELATIVE"].Value);
        }