Exemplo n.º 1
0
        public void TestClickLoadWithExcpetionOnLoadImage()
        {
            // Create a substitute for all interface
            var display   = Substitute.For <IDisplay>();
            var extBitmap = Substitute.For <IExtBitmap>();
            var iLoad     = Substitute.For <ILoad>();
            var iSave     = Substitute.For <ISave>();
            // Get the instance of BusinessPresentation
            BusinessPresentation bp = new BusinessPresentation(iLoad, iSave, extBitmap, display);

            // Get a fake picture from the form
            PictureBox fakePictureBox = new PictureBox();

            fakePictureBox.Image = Properties.Resources.firefox;

            //instructions to NSubstitute : Throw an exception
            iLoad
            .When(x => x.LoadImage())
            .Do(x => { throw new Exception(); });

            bp.ClickLoad(fakePictureBox);

            //access to internal variables of the class
            Assert.AreEqual(bp.iHaveException, true);
        }
Exemplo n.º 2
0
        public void TestClickLoadWithNoException()
        {
            // Create a substitute for all interface
            var display   = Substitute.For <IDisplay>();
            var extBitmap = Substitute.For <IExtBitmap>();
            var iLoad     = Substitute.For <ILoad>();
            var iSave     = Substitute.For <ISave>();
            // Get the instance of BusinessPresentation
            BusinessPresentation bp = new BusinessPresentation(iLoad, iSave, extBitmap, display);

            // Get a fake picture from the form
            PictureBox fakePictureBox = new PictureBox();

            fakePictureBox.Image = Properties.Resources.firefox;

            bp.ClickLoad(fakePictureBox);

            //access to internal variables of the class
            Assert.AreEqual(bp.iHaveException, false);
        }