コード例 #1
0
        public ActionResult UpdateStorage(int id, StorageUpdateDto storageUpdateDto)
        {
            var modelFromRepo = _repository.GetStorageById(id);

            if (modelFromRepo == null)
            {
                return(NotFound());
            }

            modelFromRepo.IdUser      = _repository.GetUserById(storageUpdateDto.UserId);
            modelFromRepo.StorageName = storageUpdateDto.StorageName;

            _repository.UpdateStorage(modelFromRepo);
            _repository.SaveChanges();

            return(NoContent());
        }
コード例 #2
0
        public async Task UpdateStorage(int id)
        {
            // Arrange
            var oldStorageHttpResponseMessage = await TestClient.GetAsync(Url + id);

            var oldStorage = await oldStorageHttpResponseMessage.Content.ReadAsStringAsync();

            var old         = JsonConvert.DeserializeObject <ExpireReadDto>(oldStorage);
            var storageName = "Updated Test Storage " + id;
            StorageUpdateDto storageUpdate = new StorageUpdateDto()
            {
                UserId = old.IdUser, StorageName = storageName
            };
            var json    = JsonConvert.SerializeObject(storageUpdate);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            // Act
            var response = await TestClient.PutAsync(Url + id, content);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
        }