Example #1
0
        public async Task UpdateFacilityTest()
        {
            //Arrange
            var facilityKey      = Guid.NewGuid();
            var creationDate     = DateTimeOffset.Now;
            var modificationDate = DateTimeOffset.Now;
            var facility         = GetMockFacility(facilityKey, creationDate, modificationDate);


            _mockRepo.Reset();
            _mockRepo.Setup(b => b.GetAsync(facilityKey))
            .ReturnsAsync(facility);
            _mockRepo.Setup(b => b.UpdateFacility(facility))
            .ReturnsAsync(true);

            //Act
            var result = await _subjectUnderTest.Update(facilityKey, new UpdateFacilityRequest()
            {
                FacilityName = "New Name"
            });


            //Assert
            _mockRepo.VerifyAll();
            Assert.NotNull(result);
            Assert.Equal(CreateUpdateResultEnum.Success, result.OperationResult);
            Assert.Equal("New Name", result.Object.FacilityName);
        }
        public async Task <IActionResult> UpdateFacility(Guid facilitykey, [FromBody] UpdateFacilityRequest request)
        {
            if (ModelState.IsValid)
            {
                _logger.LogDebug("Update Facility Request called with {@UpdateRequest}", request);
                var facilityUpdate = await _facilityManager.Update(facilitykey, request);

                if (facilityUpdate.OperationResult == CreateUpdateResultEnum.Success)
                {
                    _logger.LogInformation("Facility successfully saved updated result : {UpdateResult}", facilityUpdate);
                    return(Ok(facilityUpdate.Object));
                }

                if (facilityUpdate.OperationResult == CreateUpdateResultEnum.NotFound)
                {
                    _logger.LogError("No Result Found for facility  {FacilityKey}.", facilitykey);
                    ModelState.AddModelError("facilitykey", "Error Processing Request");
                }
                if (facilityUpdate.OperationResult == CreateUpdateResultEnum.ValidationFailed)
                {
                    _logger.LogError("Error updating facility  {FacilityKey} as validation failed from database.", facilitykey);
                    ModelState.AddModelError("facilitykey", "Error Processing Request");
                }
            }
            _logger.LogDebug("ModelState validation failed :{@Data}", request);
            return(BadRequest(new ModelStateRequestValidationAdaptor(ModelState)));
        }