public IActionResult UpdateReferenceNameSuffix(int id, ReferenceNameSuffixDto payload)
        {
            var referenceNameSuffixInDb = _unitOfWork.ReferenceNameSuffixes.Get(id);

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

            _mapper.Map(payload, referenceNameSuffixInDb);
            _unitOfWork.Complete();

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task Update_MalformedPayload_HttpBadRequest()
        {
            // Arrange
            var randomNameSuffixId = PreDefinedData.GetRandomNameSuffixId();
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController), randomNameSuffixId.ToString());
            var apiUpdatingNameSuffix = new ReferenceNameSuffixDto
            {
                Id = randomNameSuffixId
                     // Code is required, keep it missing
            };

            // Act
            var response = await Client.PutAsync(path, new StringContent(
                                                     JsonConvert.SerializeObject(apiUpdatingNameSuffix),
                                                     Encoding.UTF8,
                                                     JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
        }
Exemplo n.º 3
0
        public async Task Create_MalformedPayload_HttpBadRequest()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController));

            var newNameSuffixDto = new ReferenceNameSuffixDto
            {
                // Code is required, keep it missing
                CreatedDate = DateTime.UtcNow
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newNameSuffixDto),
                                                      Encoding.UTF8,
                                                      JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
        }
Exemplo n.º 4
0
        public async Task Update_InvalidNameSuffix_HttpNotFound()
        {
            // Arrange
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController), int.MaxValue.ToString());
            var apiUpdatingNameSuffix = new ReferenceNameSuffixDto
            {
                Id       = int.MaxValue,
                Code     = notExistsNameSuffixCode,
                LongName = "Update Test"
            };

            // Act
            var response = await Client.PutAsync(path, new StringContent(
                                                     JsonConvert.SerializeObject(apiUpdatingNameSuffix),
                                                     Encoding.UTF8,
                                                     JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        }
        public IActionResult CreateReferenceNameSuffix(ReferenceNameSuffixDto payload)
        {
            var referenceNameSuffix = _mapper.Map <ReferenceNameSuffixDto, ReferenceNameSuffix>(payload);

            var referenceNameSuffixInDb = _unitOfWork.ReferenceNameSuffixes.Find(p => p.Code == payload.Code);

            if (referenceNameSuffixInDb.Any())
            {
                return(new ConflictResult());
            }

            _unitOfWork.ReferenceNameSuffixes.Add(referenceNameSuffix);
            _unitOfWork.Complete();

            payload.Id = referenceNameSuffix.Id;

            return(CreatedAtAction(nameof(GetReferenceNameSuffix),
                                   new
            {
                id = payload.Id
            },
                                   payload));
        }
Exemplo n.º 6
0
        public async Task Create_ExistingNameSuffix_HttpConflict()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController));
            var randomNameSuffixId = PreDefinedData.GetRandomNameSuffixId();
            var randomNameSuffix   = PreDefinedData.ReferenceNameSuffixes[randomNameSuffixId - 1];

            var newNameSuffixDto = new ReferenceNameSuffixDto
            {
                Code        = randomNameSuffix.Code,
                LongName    = "Create Test",
                CreatedDate = DateTime.UtcNow
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newNameSuffixDto),
                                                      Encoding.UTF8,
                                                      JsonMediaType));

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict));
        }
Exemplo n.º 7
0
        public async Task Create_ValidPayload_HttpCreatedAndReturnsNewNameSuffix()
        {
            // Arrange
            var path = GetRelativePath(nameof(ReferenceNameSuffixesController));
            var notExistsNameSuffixCode = PreDefinedData.GetNotExistsNameSuffixCode();
            var newNameSuffixDto        = new ReferenceNameSuffixDto
            {
                Code         = notExistsNameSuffixCode,
                LongName     = "New NameSuffix",
                CreatedDate  = DateTime.UtcNow,
                CreatedBy    = CreatedModifiedBy,
                ModifiedDate = DateTime.UtcNow,
                ModifiedBy   = CreatedModifiedBy
            };

            // Act
            var response = await Client.PostAsync(path, new StringContent(
                                                      JsonConvert.SerializeObject(newNameSuffixDto),
                                                      Encoding.UTF8,
                                                      JsonMediaType));

            var responseString = await response.Content.ReadAsStringAsync();

            // Assert
            Assert.DoesNotThrow(
                () => response.EnsureSuccessStatusCode(),
                string.Format(HttpExceptionFormattedMessage, responseString));
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));

            var apiReturnedObject =
                JsonConvert.DeserializeObject <ReferenceNameSuffixDto>(responseString);

            Assert.That(apiReturnedObject.Id, Is.GreaterThan(0));

            newNameSuffixDto.Id = apiReturnedObject.Id;
            AssertHelper.AreObjectsEqual(apiReturnedObject, newNameSuffixDto);
        }