Пример #1
0
        public void GetDutchPioneers_ContextWithSeveralPioneersAndNationalities_DutchPioneersOnly_NonMocked()
        {
            // Arrange. Mock without a mocking framework
            Pioneers pioneers = new Pioneers(Source.XmlFile); //1st problem, you create a real object, is this xmlfile available???

            //Arrange. private _datacontext object
            PropertyInfo prop = typeof(Pioneers).GetProperty("_dataContext", BindingFlags.NonPublic | BindingFlags.Instance);
            prop.SetValue(pioneers, DataSource.Pioneers(), null);

            //Act.
            var result = pioneers.GetDutchPioneers();

            //Assert
            Assert.IsTrue(result.All(p => p.Nationality.Equals("NL")));
        }
Пример #2
0
        public void OlderThan65_ContextWithSeveralPioneersDeadAndAlive_PioneersCurrentlyAreOlderThan65_NonMocked()
        {
            // Arrange. Mock without a mocking framework
            Pioneers pioneers = new Pioneers(Source.XmlFile); //1st problem, you create a real object, is this xmlfile available???

            //Arrange. private _datacontext object
            PropertyInfo prop = typeof(Pioneers).GetProperty("_dataContext", BindingFlags.NonPublic | BindingFlags.Instance);
            prop.SetValue(pioneers, DataSource.Pioneers(), null);

            /* We can't mock the calculate function!
            Mock.Arrange(() => Pioneers.CalculateAge(new DateTime(1931, 5, 13)))
                .Returns(....*/

            /* * * * * * * * * * * * Test will fail after some time.. * * * * * * * * * * * * * * * */

            //Act.
            var result = pioneers.OlderThan65();

            //Assert
            Assert.IsTrue(result.Count() == 2);
        }