public void GetAllViewForaProperty() { //Now Arrange viewcontroller = Substitute.For <ViewingController>(_viewFactory, _handler); viewpropertymodel = new ViewPropertiesViewModel() { PropertyTitle = "test", ViewProperties = new List <BookViewingPropertyViewModel>() { new BookViewingPropertyViewModel() { PropertyId = 1, PropertyTitle = "test", ViewingDateTime = DateTime.Now, BuyerId = "some guid" } } }; bookviewbilderparam = Substitute.For <BookViewingBuilderParam>(); //Action var viewmodel = _viewFactory.GetViewModel <ViewingController, ViewPropertiesViewModel, BookViewingBuilderParam>(viewcontroller, bookviewbilderparam).Returns(viewpropertymodel); var actionsresult = viewcontroller.AllMyViewing(bookviewbilderparam); //Assert Assert.IsNotNull(viewmodel); Assert.IsNotInstanceOf <RedirectToRouteResult>(actionsresult); }
public async Task Download_Get_SuccessAsync() { string originalDownloadsLocation = ConfigHelpers.SharedOptions.DownloadsLocation; // remember so it can be reset at the end of this test // Arrange ConfigHelpers.SharedOptions.DownloadsLocation = Path.Combine(ConfigHelpers.SharedOptions.DownloadsLocation, "TestData"); var firstFileTitle = "2006-2007"; string firstFileLocation = Path.Combine(ConfigHelpers.SharedOptions.DownloadsLocation, $"GPGData_{firstFileTitle}.csv"); var secondFileTitle = "2005-2006"; string secondFileLocation = Path.Combine(ConfigHelpers.SharedOptions.DownloadsLocation, $"GPGData_{secondFileTitle}.csv"); var thirdFileTitle = "2004-2005"; string thirdFileLocation = Path.Combine(ConfigHelpers.SharedOptions.DownloadsLocation, $"GPGData_{thirdFileTitle}.csv"); ViewingController controller = null; try { var routeData = new RouteData(); routeData.Values.Add("Action", "Download"); routeData.Values.Add("Controller", "Viewing"); controller = UiTestHelper.GetController <ViewingController>(0, routeData); await controller.SharedBusinessLogic.FileRepository.WriteAsync(firstFileLocation, Encoding.UTF8.GetBytes($"No data for {firstFileTitle}")); await controller.SharedBusinessLogic.FileRepository.WriteAsync(secondFileLocation, Encoding.UTF8.GetBytes($"No data for {secondFileTitle}")); await controller.SharedBusinessLogic.FileRepository.WriteAsync(thirdFileLocation, Encoding.UTF8.GetBytes($"No data for {thirdFileTitle}")); // Act var result = await controller.Download() as ViewResult; // Assert Assert.NotNull(result, "Expected ViewResult"); Assert.AreEqual("Download", result.ViewName, "Incorrect view returned"); var model = result.Model as DownloadViewModel; Assert.IsNotNull(model, "Expected DownloadViewModel or Incorrect resultType returned"); Assert.IsNotNull(model.Downloads); Assert.True(result.ViewData.ModelState.IsValid, "Model was Invalid but was expected to be valid"); Assert.AreEqual(3, model.Downloads.Count, $"Expected exactly 3 Downloads but were {model.Downloads.Count}"); Assert.AreEqual(firstFileTitle, model.Downloads[0].Title); Assert.AreEqual(secondFileTitle, model.Downloads[1].Title); Assert.AreEqual(thirdFileTitle, model.Downloads[2].Title); } finally { // Cleanup if (controller != null) { await controller.SharedBusinessLogic.FileRepository.DeleteFileAsync(firstFileLocation); await controller.SharedBusinessLogic.FileRepository.DeleteFileAsync(secondFileLocation); await controller.SharedBusinessLogic.FileRepository.DeleteFileAsync(thirdFileLocation); } ConfigHelpers.SharedOptions.DownloadsLocation = originalDownloadsLocation; } }
public async Task GetCameras_Test() { // Arrange var mockMobile = new Mock <IDvtelMobileService>(); mockMobile.Setup(x => x.GetCameras()) .ReturnsAsync(new List <Camera> { new Camera { CanPlayback = true, CanRecord = true, Description = "Ptz Camera", Id = Guid.NewGuid(), IsAccessible = true, IsGhost = false, IsPTZEnabled = true, IsRecording = true, Name = "Dhua Ptz", SiteId = Guid.NewGuid() }, new Camera { CanPlayback = true, CanRecord = true, Description = "Other Camera", Id = Guid.NewGuid(), IsAccessible = true, IsGhost = false, IsPTZEnabled = false, IsRecording = true, Name = "Dhua", SiteId = Guid.NewGuid() } }); // Act var controller = new ViewingController(mockMobile.Object); IHttpActionResult actionResult = await controller.Cameras(); var contentResult = actionResult as OkNegotiatedContentResult <ModelResponseMethod>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.IsInstanceOfType(contentResult.Content.Data, typeof(List <Camera>)); Assert.AreEqual(2, ((List <Camera>)contentResult.Content.Data).Count); }
public void TestEditView() { //Now Arrange viewcontroller = Substitute.For <ViewingController>(_viewFactory, _handler); var updateviewmodel = Substitute.For <UpdateViewingPropertyViewModel>(); bookviewbilderparam = Substitute.For <BookViewingBuilderParam>(); //Action var viewmodel = _viewFactory.GetViewModel <ViewingController, UpdateViewingPropertyViewModel, BookViewingBuilderParam>(viewcontroller, bookviewbilderparam).Returns(updateviewmodel); var actionsresult = viewcontroller.EditView(bookviewbilderparam); //Assert Assert.That(viewmodel != null); Assert.IsNotInstanceOf <RedirectToRouteResult>(actionsresult); }
public async Task GetStartLive_Test() { // Arrange var mockMobile = new Mock <IDvtelMobileService>(); mockMobile.Setup(x => x.StartLive(It.IsAny <Guid>(), It.IsAny <string>())) .ReturnsAsync(new Uri("http://localhost:8081/live")); // Act var controller = new ViewingController(mockMobile.Object); IHttpActionResult actionResult = await controller.StartLive(Guid.NewGuid()); var contentResult = actionResult as OkNegotiatedContentResult <ModelResponseMethod>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.IsInstanceOfType(contentResult.Content.Data, typeof(string)); Assert.AreEqual("http://localhost:8081/live", contentResult.Content.Data); }
public async Task DownloadData_Get_SuccessAsync() { string originalDownloadsLocation = ConfigHelpers.SharedOptions.DownloadsLocation; // remember so it can be reset at the end of this test // Arrange ConfigHelpers.SharedOptions.DownloadsLocation = Path.Combine(ConfigHelpers.SharedOptions.DownloadsLocation, "TestData"); var firstFileTitle = "2001-2002"; string firstFileLocation = Path.Combine(ConfigHelpers.SharedOptions.DownloadsLocation, $"GPGData_{firstFileTitle}.csv"); string firstFileContent = $"No content available for years {firstFileTitle}."; ViewingController controller = null; try { var routeData = new RouteData(); routeData.Values.Add("Action", "DownloadData"); routeData.Values.Add("Controller", "Viewing"); controller = UiTestHelper.GetController <ViewingController>(0, routeData); await controller.SharedBusinessLogic.FileRepository.WriteAsync(firstFileLocation, Encoding.UTF8.GetBytes(firstFileContent)); var year = 2001; // Act var result = await controller.DownloadData(year) as ContentResult; // Assert Assert.IsNotNull(result); Assert.AreEqual(firstFileContent, result.Content, "Invalid download content returned"); } finally { // Cleanup if (controller != null) { await controller.SharedBusinessLogic.FileRepository.DeleteFileAsync(firstFileLocation); } ConfigHelpers.SharedOptions.DownloadsLocation = originalDownloadsLocation; } }