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