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
        //Would be revisiting to modify the actual way of call method.
        public void ParametersTest_Success()
        {
            // Arrange
            int lid = 191809;

            MockParametersRepository repository = new MockParametersRepository();
            var expectedResult = repository.GetMockData();
            IOptions <DataContext>     optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            IParametersRepository      mockRepo          = Substitute.For <IParametersRepository>();

            mockRepo.GetParametersAsync(lid).ReturnsForAnyArgs(expectedResult.Result);

            // Act
            var actualRecord = mockRepo.GetParametersAsync(lid).Result;

            // Assert
            Assert.Equal((actualRecord), expectedResult.Result);
        }
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);
        }
Beispiel #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);
        }
Beispiel #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");
        }