Exemplo n.º 1
0
        /// <summary>
        /// ParametersController
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="parametersApi"></param>
        /// <param name="localizer"></param>
        /// <param name="operation"></param>
        /// <param name="loggingFacade"></param>
        public ParametersController(IDistributedCache cache, IParametersApi parametersApi
                                    , IStringLocalizer <ParametersController> localizer
                                    , IOperation operation
                                    , ILoggingFacade loggingFacade)
        {
            _loggingFacade = loggingFacade;
            _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting ParametersController", "ParametersController.cs", "ParametersController"), CancellationToken.None);

            _cache         = cache;
            _parametersApi = parametersApi;
            _localizer     = localizer;
            _operation     = operation;
        }
Exemplo n.º 2
0
        public async Task ParametersApiTest_Exception()
        {
            // Arrange
            int parameterId = 191809;

            IOptions <Settings>   optionsAccessor = Substitute.For <IOptions <Settings> >();
            IParametersRepository mockRepo        = Substitute.For <IParametersRepository>();
            IParametersApi        parametersApi   = Substitute.For <IParametersApi>();

            mockRepo.GetParametersAsync(parameterId).ThrowsForAnyArgs(new Exception());
            parametersApi = new ParametersApi(optionsAccessor, mockRepo);


            // Assert
            await Assert.ThrowsAsync <Exception>(() => parametersApi.GetParameters(parameterId));
        }
Exemplo n.º 3
0
        public void ParametersApiTest_Success()
        {
            // Arrange
            int parameterId = 589547;
            IOptions <Settings>   optionsAccessor = Substitute.For <IOptions <Settings> >();
            IParametersRepository mockRepo        = Substitute.For <IParametersRepository>();
            IParametersApi        api             = Substitute.For <IParametersApi>();

            MockParametersRepository repository = new MockParametersRepository();
            var expectedResult = repository.GetMockData().Result;

            mockRepo.GetParametersAsync(parameterId).ReturnsForAnyArgs(expectedResult);

            api = new ParametersApi(optionsAccessor, mockRepo);

            // Act
            var actualRecord = (api.GetParameters(parameterId).Result).Result;

            // Assert
            Assert.Equal((actualRecord), expectedResult);
        }
Exemplo n.º 4
0
        public async Task ParametersControllerTest_TerminalSuccess()
        {
            // Arrange
            int lid = 589547;
            MockParametersRepository repository = new MockParametersRepository();
            var expectedResult = repository.GetMockData();

            IParametersRepository mockRepo      = FakeRepository();
            IDistributedCache     _cache        = FakeCache();
            IOperation            fakeOperation = FakeOperation(_cache);

            IParametersApi dAPI = Substitute.For <IParametersApi>();

            dAPI.GetParameters(lid).ReturnsForAnyArgs(expectedResult);
            ParametersController controller = FakeController(_cache, dAPI, null, fakeOperation, FakeLogger());

            // Act
            var dinfo = await controller.GetParameters(lid);

            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).Value;

            // Assert
            Assert.Equal(actualRecord, expectedResult.Result);
        }
Exemplo n.º 5
0
        public void ParametersControllerTest_ModelState_Invalid()
        {
            //Arrange
            int lid = 589547;
            MockParametersRepository repository = new MockParametersRepository();
            var expectedResult = repository.GetMockData();

            IParametersRepository mockRepo      = FakeRepository();
            IDistributedCache     _cache        = FakeCache();
            IOperation            fakeOperation = FakeOperation(_cache);

            IParametersApi dAPI = Substitute.For <IParametersApi>();

            dAPI.GetParameters(lid).ReturnsForAnyArgs(expectedResult);
            ParametersController controller = FakeController(_cache, dAPI, null, fakeOperation, FakeLogger());

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var dinfo = controller.GetParameters(lid).Result;


            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400");
        }
Exemplo n.º 6
0
 private ParametersController FakeController(IDistributedCache mockCache, IParametersApi Parameters, IStringLocalizer <ParametersController> localizer, IOperation fakeOperation, ILoggingFacade loggingFacade)
 {
     return(new ParametersController(mockCache, Parameters, localizer, fakeOperation, loggingFacade));
 }