public async Task TestAddFolderTaskAsync_validParentFolder()
        {
            // Arrange
            var dbContext = AppDBContextMocker.GetAppDbContext(nameof(TestAddFolderTaskAsync_validParentFolder));
            var fService  = new FolderService(new FolderRepository(dbContext), new UnitOfWork(dbContext), null);


            //auto mapper configuration
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new ResourceToModelProfile());
                cfg.AddProfile(new ModelToResourceProfile());
            });

            var folderModel = new SaveFolderResource()
            {
                Name           = "validParentFolder",
                ParentFolderId = 104,
            };
            // Act
            var controller = new FoldersController(fService, mockMapper.CreateMapper(), null);
            var response   = await controller.AddFolderAsync(folderModel) as ObjectResult;

            dbContext.Dispose();

            // Assert
            Assert.NotNull(response);
            var folderResponce = response.Value as FolderResource;

            Assert.NotNull(folderResponce);
            Assert.NotNull(folderResponce.FolderID);
            Assert.Equal(folderResponce.Name, folderModel.Name);
            Assert.Null(folderModel.ParentFolderId);
        }
Beispiel #2
0
        public async Task <IActionResult> AddFolderAsync([FromBody] SaveFolderResource resource)
        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(AddFolderAsync));

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var folder = _mapper.Map <SaveFolderResource, Folder>(resource);
            var result = await _folderService.SaveAsync(folder);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var folderResource = _mapper.Map <Folder, FolderResource>(result.Folder);

            Logger?.LogInformation("The folder has been added successfully.");
            return(Ok(folderResource));
        }