Ejemplo n.º 1
0
        public async void UnitTest1()
        {
            var conf = new Mock <IConfiguration>();

            conf.Setup(x => x["UploadFolder"]).Returns(value: "TestUploadFolder");

            var env = new Mock <IHostingEnvironment>();

            env.SetupGet(x => x.WebRootPath).Returns(Path.GetTempPath());

            var controller = new UploadFilesController(env.Object, conf.Object);

            using (var stream = new MemoryStream(new byte[] { 1, 2, 3, 4 }))
            {
                // Arrange

                // create a REAL form file
                var formFile = new FormFile(stream, 0, stream.Length, "name", "filename");

                //Act
                var result = await controller.UploadFiles(new List <IFormFile> {
                    formFile
                });

                var okResult = result as OkObjectResult;

                var data = okResult.Value;

                //Assert
                Assert.IsType <OkObjectResult>(okResult);
            }
        }
Ejemplo n.º 2
0
        public UploadFileControllerTest()
        {
            _mockFileManagementServices             = new Mock <IFileManagementServices>();
            _mockZipServices                        = new Mock <IZipServices>();
            _mockEncryptionServices                 = new Mock <IEncryptionServices>();
            _mockDataManagementSystemCallerServices = new Mock <IDataManagementSystemCallerServices>();
            _mockConfiguration                      = new Mock <IConfiguration>();


            _controller = new UploadFilesController(
                _mockFileManagementServices.Object,
                _mockZipServices.Object,
                _mockEncryptionServices.Object,
                _mockDataManagementSystemCallerServices.Object,
                _mockConfiguration.Object
                );
            var httpContextMock = new Mock <HttpContext>();

            if (_controller.ControllerContext.HttpContext == null)
            {
                _controller.ControllerContext.HttpContext = new DefaultHttpContext();
            }
        }