Exemple #1
0
        public void UpdateFacility_RegularValues_OkResults()
        {
            //Arrange
            var facility = new Mock <IFacility>();

            facility.SetupGet(a => a.Id).Returns(4);
            facility.SetupGet(a => a.BuildingId).Returns(1);
            facility.SetupGet(a => a.Level).Returns(model.Level);
            facility.SetupGet(a => a.Number).Returns(model.Number);

            facade.Setup(f => f.UpdateFacility("3445", model.Id, model.Level, model.Number)).Returns(facility.Object);

            var controller = new FacilityController(facade.Object)
            {
                ControllerContext = controllerContext
            };

            //Act
            var result = controller.UpdateFacility(model);

            //Assert
            Assert.NotNull(result);

            var okresult = Assert.IsType <OkNegotiatedContentResult <GenericResponse> >(result);

            Assert.Equal(true, okresult.Content.IsSuccess);
        }
        public async Task UpdateFacilityTest(string facilityKey, int statusCode)
        {
            //Arrange
            _mockFacilityManager.Reset();
            _mockFacilityManager.Setup(b =>
                                       b.Update(Guid.Parse("22BFE608-AAFC-4BE3-9951-00536B214DFE"), It.IsAny <UpdateFacilityRequest>()))
            .ReturnsAsync(
                new BusinessResult <Model.Facility>(new Model.Facility(), CreateUpdateResultEnum.Success));

            _mockFacilityManager.Setup(b =>
                                       b.Update(Guid.Parse("32BFE608-AAFC-4BE3-9951-00536B214DFE"), It.IsAny <UpdateFacilityRequest>()))
            .ReturnsAsync(new BusinessResult <Model.Facility>(null, CreateUpdateResultEnum.NotFound));

            _mockFacilityManager.Setup(b =>
                                       b.Update(Guid.Parse("42BFE608-AAFC-4BE3-9951-00536B214DFE"), It.IsAny <UpdateFacilityRequest>()))
            .ReturnsAsync(new BusinessResult <Model.Facility>(null, CreateUpdateResultEnum.ValidationFailed));

            //Act
            var result = await _subject.UpdateFacility(Guid.Parse(facilityKey), new UpdateFacilityRequest());

            var updateResult = result as ObjectResult;

            //Assert
            Assert.NotNull(updateResult);
            Assert.Equal(statusCode, updateResult.StatusCode);
            _mockFacilityManager.Verify();
        }
Exemple #3
0
        public void UpdateFacility_ThrowsError_BadModel()
        {
            //Arrange
            var controller = new FacilityController(facade.Object)
            {
                ControllerContext = controllerContext
            };

            controller.ModelState.AddModelError("Key", "ErrorMessage");

            //Act
            var result = controller.UpdateFacility(model);

            //Assert
            Assert.NotNull(result);
            Assert.IsType <InvalidModelStateResult>(result);
        }
Exemple #4
0
        public void UpdateFacility_ThrowsError_InternalError()
        {
            //Arrange
            var exception = new ConnApsDomain.Exceptions.InternalException();

            facade.Setup(f => f.UpdateFacility("3445", model.Id, model.Level, model.Number)).Throws(exception);

            var controller = new FacilityController(facade.Object)
            {
                ControllerContext = controllerContext
            };

            //Act
            var result = controller.UpdateFacility(model);

            //Assert
            Assert.NotNull(result);

            Assert.IsType <InternalServerErrorResult>(result);
        }
Exemple #5
0
        public void UpdateFacility_InvalidValues_BadRequest()
        {
            //Arrange
            var exception = new ConnApsDomain.Exceptions.NotFoundException("Facility");

            facade.Setup(f => f.UpdateFacility("3445", model.Id, model.Level, model.Number)).Throws(exception);

            var controller = new FacilityController(facade.Object)
            {
                ControllerContext = controllerContext
            };

            //Act
            var result = controller.UpdateFacility(model);

            //Assert
            Assert.NotNull(result);

            var badRequest = Assert.IsType <BadRequestErrorMessageResult>(result);

            Assert.Equal("The Facility you requested was not found. Please search again.", badRequest.Message);
        }