public void All_ShouldReturnView() { // Arrange Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>(); ListTelescopesViewModel listModel = this.GetListTelescopesViewModel(); telescopeService .Setup(t => t.Total()) .Returns(20); telescopeService .Setup(t => t.All(It.IsAny <int>(), It.IsAny <int>())) .Returns(this.GetListTelescopesServiceModel()); TelescopesController telescopesController = new TelescopesController(telescopeService.Object); // Act IActionResult result = telescopesController.All(2); // Assert Assert.IsType <ViewResult>(result); object model = (result as ViewResult).Model; Assert.IsType <ListTelescopesViewModel>(model); ListTelescopesViewModel returnModel = model as ListTelescopesViewModel; this.AssertPages(listModel, returnModel); this.AssertTelescopeCollection(listModel.Telescopes, returnModel.Telescopes); }
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); }
public void CreatePost_WithExistingTelescopeName_ShouldReturnView() { // Arrange Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>(); telescopeService .Setup(s => s.Exists(It.IsAny <string>())) .Returns(true); 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.Create(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); }
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); }
public void CreatePost_WithNotSuccessfullyCreatedTelescope_ShouldReturnBadRequest() { // Arrange Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>(); telescopeService .Setup(s => s.Exists(It.IsAny <string>())) .Returns(false); telescopeService .Setup(s => s.Create( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <double>(), It.IsAny <string>())) .Returns(-1); TelescopeFormServiceModel formModel = this.GetTelescopeFormModel(); TelescopesController telescopesController = new TelescopesController(telescopeService.Object); telescopesController.TempData = Mock.Of <ITempDataDictionary>(); // Act IActionResult result = telescopesController.Create(formModel); // Assert Assert.IsType <BadRequestResult>(result); }
public void CreateGet_ShouldReturnView() { // Arrange TelescopesController telescopesController = new TelescopesController(null); // Act IActionResult result = telescopesController.Create(); // Assert Assert.IsType <ViewResult>(result); }
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); }
public void Details_WithNotExistingId_ShouldReturnBadRequest() { // Arrange Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>(); TelescopeDetailsServiceModel detailsModel = null; telescopeService .Setup(t => t.Details(It.IsAny <int>())) .Returns(detailsModel); TelescopesController telescopesController = new TelescopesController(telescopeService.Object); // Act IActionResult result = telescopesController.Details(1); // Assert Assert.IsType <BadRequestResult>(result); }
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); }
public void Details_WithExistingId_ShouldReturnView() { // Arrange Mock <ITelescopeService> telescopeService = new Mock <ITelescopeService>(); TelescopeDetailsServiceModel detailsModel = this.GetTelescopeDetailsServiceModel(); telescopeService .Setup(t => t.Details(It.IsAny <int>())) .Returns(detailsModel); TelescopesController telescopesController = new TelescopesController(telescopeService.Object); // Act IActionResult result = telescopesController.Details(1); // Assert Assert.IsType <ViewResult>(result); object model = (result as ViewResult).Model; Assert.IsType <TelescopeDetailsServiceModel>(model); TelescopeDetailsServiceModel returnModel = model as TelescopeDetailsServiceModel; this.AssertTelescopeDetails(detailsModel, returnModel); }