Exemple #1
0
        public async Task <bool> SaveUploadFile()
        {
            try
            {
                var file     = Request.Form.Files[0];
                var periodId = Request.Form["PERIOD"][0];

                IEnumerable <Claim> claims = ((ClaimsIdentity)User.Identity).Claims;
                var userId = claims.First(c => c.Type == "sub");

                return(await _accountPeriodBalanceService.UploadAndImportFile(Int32.Parse(periodId), file.OpenReadStream(), file.FileName, Int32.Parse(userId.Value)));
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async Task UploadAndImportFile()
        {
            // Arrange
            _mockConfiguration.Setup(c => c.GetValue(It.IsAny <string>())).Returns("accountperiodbalanceservice-test-04");
            _fileAccessor.Setup(c => c.WriteFileAsync(It.IsAny <Stream>(), It.IsAny <FileUploadModel>())).Returns(Task.FromResult(true));
            _importProcess.Setup(c => c.ProcessFileAsync(It.IsAny <FileUploadModel>())).Returns(Task.FromResult(0));


            using (var uow = _applicationDbFactory.BeginUnitOfWorkAsync().Result)
            {
                await SeedAccounts(uow);

                // Act
                var actualResult = await _accountPeriodBalanceService.UploadAndImportFile(1, null, "testFile.txt", 1);

                // Assert
                Assert.IsTrue(actualResult, "UploadAndImportFile error");
            }
        }