public void TestCargarEstudiantes() { // 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/listaEstudianteTest.csv"); FileStream fileStream = new FileStream(filePath, FileMode.Open); //Cargamos el mock Mock <HttpPostedFileBase> uploadedFile = new Mock <HttpPostedFileBase>(); uploadedFile.Setup(x => x.FileName).Returns("listaEstudianteTest.csv"); uploadedFile.Setup(x => x.ContentType).Returns("listaEstudianteTest.csv"); uploadedFile.Setup(x => x.InputStream).Returns(fileStream); HttpPostedFileBase[] httpPostedFileBases = { uploadedFile.Object }; // Act ViewResult result = controller.Index(httpPostedFileBases[0]) as ViewResult; // Assert Assert.IsNotNull(result); }
public void TestIndex() { // Arrange Init("*****@*****.**"); CurrentUser.setCurrentUser("*****@*****.**", "Superusuario", "0000000001", "0000000001"); CSVController controller = new CSVController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }