public void ReturnCorrectView()
        {
            // Arrange
            var mockedLakeFactory     = new Mock <ILakeFactory>();
            var mockedLocationFactory = new Mock <ILocationFactory>();
            var mockedLakeService     = new Mock <ILakeService>();
            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 view = controller.Add() as ViewResult;

            // Assert
            Assert.IsTrue(view.ViewName == ""); // If ViewName isn`t empty string, then controller retuns not his default View
        }
        public void ReturnJsonWithAllModelErrors_IfModelStateIsNotValid()
        {
            // Arrange
            var mockedLakeFactory = new Mock <ILakeFactory>();

            mockedLakeFactory.Setup(f => f.CreateLake(It.IsAny <string>(), It.IsAny <Location>(), It.IsAny <string>())).Verifiable();

            var mockedLocationFactory = new Mock <ILocationFactory>();

            mockedLocationFactory.Setup(f => f.CreateLocation(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <string>())).Verifiable();

            var mockedLakeService = new Mock <ILakeService>();

            mockedLakeService.Setup(s => s.Add(It.IsAny <Lake>())).Verifiable();
            mockedLakeService.Setup(s => s.Save()).Verifiable();

            var mockedLocationService = new Mock <ILocationService>();

            mockedLocationService.Setup(s => s.FindByName(It.IsAny <string>())).Verifiable();

            var mockedFishService = new Mock <IFishService>();

            var controller = new LakeController(mockedLakeFactory.Object, mockedLocationFactory.Object, mockedLakeService.Object, mockedLocationService.Object, mockedFishService.Object);

            controller.ModelState.AddModelError("Name", "Test error!");

            // Act
            var     result  = controller.Add(new LakeViewModel()) as JsonResult;
            dynamic dResult = result.Data;

            // Assert
            Assert.AreEqual("error", dResult.status);
            StringAssert.Contains("Test error!", dResult.message);

            mockedLakeFactory.Verify(f => f.CreateLake(It.IsAny <string>(), It.IsAny <Location>(), It.IsAny <string>()), Times.Never);

            mockedLocationFactory.Verify(f => f.CreateLocation(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <string>()), Times.Never);

            mockedLakeService.Verify(s => s.Add(It.IsAny <Lake>()), Times.Never);
            mockedLakeService.Verify(s => s.Save(), Times.Never);

            mockedLocationService.Verify(s => s.FindByName(It.IsAny <string>()), Times.Never);
        }
        public void ReturnJsonWithCorrectSuccessMessage_IfAddingLakeNotFailed()
        {
            // Arrange
            var mockedLakeFactory = new Mock <ILakeFactory>();

            mockedLakeFactory.Setup(f => f.CreateLake(It.IsAny <string>(), It.IsAny <Location>(), It.IsAny <string>())).Verifiable();

            var mockedLocationFactory = new Mock <ILocationFactory>();

            mockedLocationFactory.Setup(f => f.CreateLocation(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <string>())).Verifiable();

            var mockedLakeService = new Mock <ILakeService>();

            mockedLakeService.Setup(s => s.Add(It.IsAny <Lake>())).Verifiable();
            mockedLakeService.Setup(s => s.Save()).Verifiable();

            var mockedLocationService = new Mock <ILocationService>();

            mockedLocationService.Setup(s => s.FindByName(It.IsAny <string>())).Verifiable();

            var mockedFishService = new Mock <IFishService>();

            var controller = new LakeController(mockedLakeFactory.Object, mockedLocationFactory.Object, mockedLakeService.Object, mockedLocationService.Object, mockedFishService.Object);

            // Act
            var     result  = controller.Add(new LakeViewModel()) as JsonResult;
            dynamic dResult = result.Data;

            // Assert
            Assert.AreEqual("success", dResult.status);
            Assert.AreEqual(GlobalMessages.AddLakeSuccessMessage, dResult.message);

            mockedLakeFactory.Verify(f => f.CreateLake(It.IsAny <string>(), It.IsAny <Location>(), It.IsAny <string>()), Times.Once);

            mockedLocationFactory.Verify(f => f.CreateLocation(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <string>()), Times.Once);

            mockedLakeService.Verify(s => s.Add(It.IsAny <Lake>()), Times.Once);
            mockedLakeService.Verify(s => s.Save(), Times.Once);

            mockedLocationService.Verify(s => s.FindByName(It.IsAny <string>()), Times.Once);
        }