public void TestCargarGuia() { // Arrange //Creamos httpContextMock and serverMock: var httpContextMock = new Mock <HttpContextBase>(); var serverMock = new Mock <HttpServerUtilityBase>(); //Mock el path original serverMock.Setup(x => x.MapPath("./ArchivoCSV")).Returns(Path.GetFullPath("../../ArchivoCSVtest")); //Mockeamos el objeto HTTPContext.Server con el servidor ya mockeado: httpContextMock.Setup(x => x.Server).Returns(serverMock.Object); //Creo el controlador y su contexto CSVController controller = new CSVController(); controller.ControllerContext = new ControllerContext(httpContextMock.Object, new RouteData(), controller); //Insertamos el csv string filePath = Path.GetFullPath("../../ArchivoCSVtest/guiaTest.csv"); FileStream fileStream = new FileStream(filePath, FileMode.Open); //Cargamos el mock Mock <HttpPostedFileBase> uploadedFile = new Mock <HttpPostedFileBase>(); uploadedFile.Setup(x => x.FileName).Returns("guiaTest.csv"); uploadedFile.Setup(x => x.ContentType).Returns("guiaTest.csv"); uploadedFile.Setup(x => x.InputStream).Returns(fileStream); HttpPostedFileBase[] httpPostedFileBases = { uploadedFile.Object }; // Act ViewResult result = controller.GuiaHorarios(httpPostedFileBases[0]) as ViewResult; // Assert Assert.IsNotNull(result); }
public void TestGuia() { // Arrange Init("*****@*****.**"); CurrentUser.setCurrentUser("*****@*****.**", "Superusuario", "0000000001", "0000000001"); CSVController controller = new CSVController(); // Act ViewResult result = controller.GuiaHorarios() as ViewResult; // Assert Assert.IsNotNull(result); }