Beispiel #1
0
        public async Task ParametersControllerTerminalTest_GetAnException()
        {
            // Arrange
            MockParametersRepository repository = new MockParametersRepository();
            var expectedResult             = repository.GetMockData();
            IParametersRepository mockRepo = FakeRepository();
            IDistributedCache     _cache   = FakeCache();

            IDistributedCache mockCache = Substitute.For <IDistributedCache>();
            IStringLocalizer <ParametersController> localizer
                = Substitute.For <IStringLocalizer <ParametersController> >();
            string key             = "GenericError";
            string value           = "Error occured";
            var    localizedString = new LocalizedString(key, value);

            localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString);
            IOperation          fakeOperation = FakeOperation(_cache);
            IOptions <Settings> appSettings   = Substitute.For <IOptions <Settings> >();
            IParametersApi      dAPI          = new ParametersApi(appSettings, mockRepo);

            dAPI.GetParameters(null).ThrowsForAnyArgs(new System.Exception());
            ParametersController controller = FakeController(_cache, dAPI, localizer, fakeOperation, FakeLogger());


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

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

            // Assert
            Assert.Equal(actualRecord.StatusCode, 500);
            Assert.Equal(actualRecord.Value, "Error occured");
        }
Beispiel #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));
        }
Beispiel #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);
        }