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); }
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); }