Esempio n. 1
0
        public async Task MemoInfoControllerTest_TerminalSuccess()
        {
            // Arrange
            int lid = 589547;
            MockMemoInfoRepository repository = new MockMemoInfoRepository();
            var expectedResult = repository.GetMockMemoInfo();

            IMemoInfoRepository mockRepo      = FakeRepository();
            IDistributedCache   _cache        = FakeCache();
            IOperation          fakeOperation = FakeOperation(_cache);
            ILoggingFacade      fakeLogger    = FakeLogger();

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

            dAPI.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult);
            MemoInfoController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger);

            // Act
            var dinfo = await controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid);

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

            // Assert
            Assert.Equal(((Wp.CIS.LynkSystems.Model.MemoList)actualRecord), expectedResult.Result);
        }
Esempio n. 2
0
        public async Task MemoInfoControllerTerminalTest_GetAnException()
        {
            // Arrange
            IMemoInfoRepository mockRepo   = FakeRepository();
            IDistributedCache   _cache     = FakeCache();
            ILoggingFacade      fakeLogger = FakeLogger();

            IDistributedCache mockCache = Substitute.For <IDistributedCache>();
            IStringLocalizer <MemoInfoController> localizer
                = Substitute.For <IStringLocalizer <MemoInfoController> >();

            IOperation          fakeOperation = FakeOperation(_cache);
            IOptions <Settings> appSettings   = Substitute.For <IOptions <Settings> >();
            IMemoInfoApi        dAPI          = new MemoInfoApi(appSettings, mockRepo);

            dAPI.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, 0).ThrowsForAnyArgs(new System.Exception());
            MemoInfoController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger);

            // Act
            var dinfo = await controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, 0);

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

            // Assert
            Assert.Equal(actualRecord.StatusCode, 500);
            Assert.Equal(actualRecord.Value, "Error occured");
        }
Esempio n. 3
0
        public void MemoInfoControllerTest_ModelState_Invalid()
        {
            //Arrange
            int lid = 589547;
            MockMemoInfoRepository repository = new MockMemoInfoRepository();
            var expectedResult = repository.GetMockMemoInfo();

            IMemoInfoRepository mockRepo      = FakeRepository();
            IDistributedCache   _cache        = FakeCache();
            IOperation          fakeOperation = FakeOperation(_cache);
            ILoggingFacade      fakeLogger    = FakeLogger();

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

            dAPI.GetMemoResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).ReturnsForAnyArgs(expectedResult);
            MemoInfoController controller = FakeController(dAPI, _cache, fakeOperation, fakeLogger);

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var dinfo = controller.Get(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, lid).Result;

            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo).StatusCode.ToString(), "400");
        }