public void TestClickSaveWithExcpetionOnGetImage() { // 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 display .When(x => x.getImage(fakePictureBox)) .Do(x => { throw new Exception(); }); bp.ClickSave(fakePictureBox); //access to internal variables of the class Assert.AreEqual(bp.iHaveException, true); }
public void TestClickSaveWithNoException() { // 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.ClickSave(fakePictureBox); //access to internal variables of the class Assert.AreEqual(bp.iHaveException, false); }