public void SetErrorMessage_InTempData_IfEditFailed() { // Arrange var mockedLakeFactory = new Mock <ILakeFactory>(); var mockedLocationFactory = new Mock <ILocationFactory>(); var mockedLake = new Lake() { Name = "Test lake", Info = "Test info" }; var mockedLakeService = new Mock <ILakeService>(); mockedLakeService.Setup(s => s.FindByName(It.IsAny <string>())).Returns(mockedLake).Verifiable(); mockedLakeService.Setup(s => s.Save()).Throws <Exception>(); var mockedLocationService = new Mock <ILocationService>(); var mockedFishService = new Mock <IFishService>(); var controller = new LakeController(mockedLakeFactory.Object, mockedLocationFactory.Object, mockedLakeService.Object, mockedLocationService.Object, mockedFishService.Object); var model = new EditLakeViewModel() { LakeName = "Test name", OldName = "Test name", LakeInfo = "Test info" }; // Act var result = controller.Edit(model, model.OldName) as ViewResult; // Assert Assert.AreEqual(GlobalMessages.EditLakeFailMessage, result.TempData[GlobalMessages.FailKey]); }
public void SetNewValuesToLake_AndSetSuccessMessage_InTempData_IfEditNotFailed() { // Arrange var mockedLakeFactory = new Mock <ILakeFactory>(); var mockedLocationFactory = new Mock <ILocationFactory>(); var mockedLake = new Lake() { Name = "Test lake", Info = "Test info" }; var mockedLakeService = new Mock <ILakeService>(); mockedLakeService.Setup(s => s.FindByName(It.IsAny <string>())).Returns(mockedLake).Verifiable(); mockedLakeService.Setup(s => s.Save()).Verifiable(); var mockedLocationService = new Mock <ILocationService>(); var mockedFishService = new Mock <IFishService>(); var controller = new LakeController(mockedLakeFactory.Object, mockedLocationFactory.Object, mockedLakeService.Object, mockedLocationService.Object, mockedFishService.Object); var model = new EditLakeViewModel() { LakeName = "Test name", OldName = "Test name", LakeInfo = "Test info" }; // Act var result = controller.Edit(model, model.OldName) as ViewResult; // Assert Assert.AreEqual(model.LakeName, mockedLake.Name); Assert.AreEqual(model.LakeInfo, mockedLake.Info); Assert.AreEqual(GlobalMessages.EditLakeSuccessMessage, result.TempData[GlobalMessages.SuccessEditKey]); mockedLakeService.Verify(s => s.FindByName(It.IsAny <string>()), Times.Once); mockedLakeService.Verify(s => s.Save(), Times.Once); }
public void GetLakeFromService_AndReturnDefaultView() { // Arrange var mockedLakeFactory = new Mock <ILakeFactory>(); var mockedLocationFactory = new Mock <ILocationFactory>(); var mockedLake = new Lake() { Name = "Test lake", Info = "Test info" }; var mockedLakeService = new Mock <ILakeService>(); mockedLakeService.Setup(s => s.FindByName(It.IsAny <string>())).Returns(mockedLake).Verifiable(); var mockedLocationService = new Mock <ILocationService>(); var mockedFishService = new Mock <IFishService>(); var controller = new LakeController(mockedLakeFactory.Object, mockedLocationFactory.Object, mockedLakeService.Object, mockedLocationService.Object, mockedFishService.Object); // Act var result = controller.Edit(It.IsAny <string>()) as ViewResult; var model = result.ViewData.Model as EditLakeViewModel; // Assert Assert.AreEqual("", result.ViewName); Assert.AreEqual(mockedLake.Name, model.LakeName); Assert.AreEqual(mockedLake.Info, model.LakeInfo); }