Example #1
0
        public void SetDataByOrg_ReturnOK()
        {
            // ARRANGE

            //test data
            var testInputData = new List <DefaultHolidayAllowance>();
            var testdata      = new DefaultHolidayAllowance {
                JobTitleID = 1, Allowance = 1, DateCreated = DateTime.UtcNow, JobTitleName = "C**k", LastModified = DateTime.UtcNow, YearsWorked = 1
            };

            testInputData.Add(testdata);

            //Mock the repository
            var repository = new Mock <IDefaultHolidayAllowanceRepository>(MockBehavior.Strict);

            repository.Setup(m => m.SetDataAsync(It.IsAny <int>(), It.IsAny <List <DefaultHolidayAllowance> >())).ReturnsAsync(true);

            //Mock data factory
            var dataFactory = new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetDefaultHolidayAllowanceRepository()).Returns(repository.Object);

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(m => m.IsAuthorized(It.IsAny <string>())).Returns(true);

            //Mock controller
            var controller = new DefaultHolidayAllowanceController(dataFactory.Object, authorization.Object);
            //controller.Request = new HttpRequestMessage(HttpMethod.Put, "");

            // ACT
            var response = controller.SetDataAsync("1", testInputData).Result;

            // ASSERT
            Assert.IsInstanceOfType(response, typeof(OkResult));
        }
Example #2
0
        public void GetDataByOrg_WithData_ReturnOK()
        {
            // ARRANGE

            //test data
            var repoOutput = new List <DefaultHolidayAllowance>();
            var testdata   = new DefaultHolidayAllowance {
                JobTitleID = 1, Allowance = 1, DateCreated = DateTime.UtcNow, JobTitleName = "C**k", LastModified = DateTime.UtcNow, YearsWorked = 1
            };

            repoOutput.Add(testdata);

            //Mock the repository
            var repository = new Mock <IDefaultHolidayAllowanceRepository>(MockBehavior.Strict);

            repository.Setup(m => m.GetDataAsync(It.IsAny <int>())).ReturnsAsync(repoOutput);

            //Mock data factory
            var dataFactory = new Mock <IDataFactory>(MockBehavior.Strict);

            dataFactory.Setup(d => d.GetDefaultHolidayAllowanceRepository()).Returns(repository.Object);

            //Mock Auth
            var authorization = new Mock <IAuthorizationProvider>(MockBehavior.Strict);

            authorization.Setup(m => m.IsAuthorized(It.IsAny <string>())).Returns(true);

            //Mock controller
            var controller = new DefaultHolidayAllowanceController(dataFactory.Object, authorization.Object);

            // ACT
            var response = controller.GetDataAsync("1").Result;

            // ASSERT
            //Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult));
            Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <IEnumerable <DefaultHolidayAllowance> >));
        }