Пример #1
0
        public void EditPost_WithNotSuccessfullEdit_ShouldReturnBadRequest()
        {
            // Arranges
            Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>();

            TelescopeFormServiceModel formModel = this.GetTelescopeFormModel();

            telescopeService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            telescopeService
            .Setup(s => s.GetName(It.IsAny <int>()))
            .Returns(formModel.Name);

            telescopeService
            .Setup(s => s.Edit(
                       It.IsAny <int>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <double>(),
                       It.IsAny <string>()))
            .Returns(false);

            TelescopesController telescopesController = new TelescopesController(telescopeService.Object);

            // Act
            IActionResult result = telescopesController.Edit(1, formModel);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Пример #2
0
        public void EditGet_WithExistingTelescopeId_ShouldRetunView()
        {
            // Arrange
            Mock <ITelescopeService>  telescopeService = new Mock <ITelescopeService>();
            TelescopeFormServiceModel formModel        = this.GetTelescopeFormModel();

            telescopeService
            .Setup(s => s.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            TelescopesController telescopesController = new TelescopesController(telescopeService.Object);

            telescopesController.TempData = Mock.Of <ITempDataDictionary>();

            // Act
            IActionResult result = telescopesController.Edit(1);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <TelescopeFormServiceModel>(model);
            TelescopeFormServiceModel returnModel = model as TelescopeFormServiceModel;

            this.AssertTelescopes(formModel, returnModel);
        }
Пример #3
0
        public void EditPost_WithSuccessfullEdit_ShouldReturnRedirectResult()
        {
            // Arranges
            Mock <ITelescopeService>  telescopeService = new Mock <ITelescopeService>();
            TelescopeFormServiceModel formModel        = this.GetTelescopeFormModel();

            const int telescopeId = 1;

            telescopeService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(false);

            telescopeService
            .Setup(s => s.GetName(It.IsAny <int>()))
            .Returns(formModel.Name);

            telescopeService
            .Setup(s => s.Edit(
                       It.IsAny <int>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <double>(),
                       It.IsAny <string>()))
            .Returns(true);

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string successmessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => successmessage = message as string);

            TelescopesController telescopesController = new TelescopesController(telescopeService.Object);

            telescopesController.TempData = tempData.Object;

            // Act
            IActionResult result = telescopesController.Edit(telescopeId, formModel);

            // Assert
            Assert.IsType <RedirectToActionResult>(result);
            RedirectToActionResult redirectResult = result as RedirectToActionResult;

            this.AssertRedirect(telescopeId, redirectResult);
            Assert.Equal(string.Format(WebConstants.SuccessfullEntityOperation, Telescope, WebConstants.Edited), successmessage);
        }
Пример #4
0
        public void EditPost_WithNotExistingTelescopeId_ShouldRetunBadRequest()
        {
            // Arrange
            Mock <ITelescopeService>  telescopeService = new Mock <ITelescopeService>();
            TelescopeFormServiceModel formModel        = null;

            telescopeService
            .Setup(s => s.GetForm(It.IsAny <int>()))
            .Returns(formModel);

            TelescopesController telescopesController = new TelescopesController(telescopeService.Object);

            telescopesController.TempData = Mock.Of <ITempDataDictionary>();

            // Act
            IActionResult result = telescopesController.Edit(1);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Пример #5
0
        public void EditPost_WithExistingTelescopeName_ShouldReturnView()
        {
            // Arranges
            Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>();

            telescopeService
            .Setup(s => s.Exists(It.IsAny <string>()))
            .Returns(true);

            telescopeService
            .Setup(s => s.GetName(It.IsAny <int>()))
            .Returns("New Name");

            Mock <ITempDataDictionary> tempData = new Mock <ITempDataDictionary>();

            string errorMessage = null;

            tempData
            .SetupSet(t => t[WebConstants.TempDataErrorMessage]    = It.IsAny <string>())
            .Callback((string key, object message) => errorMessage = message as string);

            TelescopeFormServiceModel formModel            = this.GetTelescopeFormModel();
            TelescopesController      telescopesController = new TelescopesController(telescopeService.Object);

            telescopesController.TempData = tempData.Object;

            // Act
            IActionResult result = telescopesController.Edit(1, formModel);

            // Assert
            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <TelescopeFormServiceModel>(model);
            TelescopeFormServiceModel returnModel = model as TelescopeFormServiceModel;

            this.AssertTelescopes(formModel, returnModel);
            Assert.Equal(string.Format(WebConstants.EntryExists, Telescope), errorMessage);
        }