public async Task Create_ShouldReturnNotFound_WhenWrongValues()
        {
            // Arrange
            var attachedDocRequest = new AttachedDocCreateRequest
            {
                Designation = "NewCreate",
                Name        = "NewCreate",
            };
            string json        = JsonSerializer.Serialize(attachedDocRequest);
            var    httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var    endpoint    = $"/api/marks/{999}/attached-docs";

            // Act
            var response = await _httpClient.PostAsync(endpoint, httpContent);

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task Create_ShouldReturnUnauthorized_WhenNoAccessToken()
        {
            // Arrange
            int markId             = 2;
            var attachedDocRequest = new AttachedDocCreateRequest
            {
                Designation = "NewCreate",
                Name        = "NewCreate",
            };
            string json        = JsonSerializer.Serialize(attachedDocRequest);
            var    httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            var    endpoint    = $"/api/marks/{markId}/attached-docs";

            // Act
            var response = await _authHttpClient.PostAsync(endpoint, httpContent);

            // Assert
            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
예제 #3
0
        public ActionResult Create(
            int markId, [FromBody] AttachedDocCreateRequest attachedDocRequest)
        {
            var attachedDocModel = _mapper.Map <AttachedDoc>(attachedDocRequest);

            try
            {
                _service.Create(
                    attachedDocModel,
                    markId);
            }
            catch (ArgumentNullException)
            {
                return(NotFound());
            }
            catch (ConflictException)
            {
                return(Conflict());
            }
            return(Created($"docs/{attachedDocModel.Id}", null));
        }