public async Task UpdateFile_ExpectedBehaviour()
        {
            //Arrange
            var authClient = await GetAuthorizedClientAsync();

            var command = new FileUpdateCommand()
            {
                Author     = "testowy update",
                CreatedAt  = DateTime.Now.AddDays(3),
                ExpiredAt  = DateTime.Now.AddDays(4),
                FileState  = FileState.Confirmed,
                FileType   = FileType.Claim,
                ShareMails = new string[0],
                Name       = "testowy update",
            };

            //Act
            var result = await authClient.PutAsJsonAsync($"/file/{WebAppFactory<Startup>.FileForUpdate}", command);

            var jsonResult = await result.Content.ReadAsAsync <FileDto>();

            //Assert
            Assert.NotNull(jsonResult);
            Assert.Equal(WebAppFactory <Startup> .FileForUpdate, jsonResult.Id);
            Assert.Equal(command.Name, jsonResult.Name);
            Assert.Equal(command.FileType, jsonResult.FileType);
            Assert.Equal(command.FileState, jsonResult.FileState);
            Assert.Equal(command.Author, jsonResult.Author);
        }
示例#2
0
        public async Task <FileDto> UpdateAsync(string fileId, FileUpdateCommand command)
        {
            var file = await _context.Files
                       .Include(x => x.Recivers)
                       .FirstOrDefaultAsync(x => x.Id == fileId);

            if (file == null)
            {
                return(null);
            }

            file.Author    = command.Author;
            file.CreatedAt = command.CreatedAt;
            file.ExpiredAt = command.ExpiredAt;
            file.Name      = command.Name;
            file.FileType  = command.FileType;
            file.FileState = command.FileState;

            file.Recivers.Clear();

            await _context.SaveChangesAsync();

            foreach (var email in command.ShareMails)
            {
                file.Recivers.Add(new FileReciver()
                {
                    Email  = email,
                    FileId = fileId
                });
            }

            await _context.SaveChangesAsync();

            return(await FindAsync(fileId));
        }
示例#3
0
        public async Task <IActionResult> Update(string id, [FromBody] FileUpdateCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorsArray()));
            }

            var result = await _fileService.UpdateAsync(id, command);

            if (result == null)
            {
                return(BadRequest(new [] { "Nie znaleziono pliku." }));
            }

            return(Ok(result));
        }