Exemplo n.º 1
0
 public void TravelRequestsController_Constructor_Null_SecurityHelper_Test()
 {
     ITravelRequestRepository   travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
     IEmployeeRepository        employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
     ITravelNotificationService notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();
     var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, null, notificationService);
 }
Exemplo n.º 2
0
        public async Task TravelRequestsController_Update_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            var updateTravelRequests = new TravelRequest()
            {
                TravelRequestId = 1,
            };

            travelRequestsRepository.UpdateAsyncTravelRequest = (TravelRequest) =>
            {
                Assert.IsTrue(updateTravelRequests.TravelRequestId == TravelRequest.TravelRequestId);
                called = true;

                return(Task.FromResult(string.Empty));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            await target.Update(updateTravelRequests);

            Assert.IsTrue(called);
        }
Exemplo n.º 3
0
        public async Task TravelRequestsController_UpdateStatus_Approved_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            travelRequestsRepository.GetAsyncInt32 = (id) =>
            {
                return(Task.FromResult(new TravelRequest()));
            };

            travelRequestsRepository.UpdateAsyncTravelRequest = (travel) =>
            {
                Assert.AreEqual(TravelRequestStatus.Approved, travel.Status);
                Assert.AreEqual("comments", travel.Comments);
                called = true;

                return(Task.FromResult(string.Empty));
            };

            notificationService.EmailNotifyStatusChangeTravelRequestString = (travelRequest, comments) =>
            {
                Assert.AreEqual(TravelRequestStatus.Approved, travelRequest.Status);
                return(Task.FromResult(string.Empty));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            await target.UpdateStatus(1, TravelRequestStatus.Approved, "comments");

            Assert.IsTrue(called);
        }
Exemplo n.º 4
0
 public async Task TravelRequestsController_Update_Exception_Test()
 {
     var travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
     var employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
     var notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();
     var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
     await target.Update(null);
 }
Exemplo n.º 5
0
        public async Task TravelRequestsController_GetUserTravelRequests_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            travelRequestsRepository.GetUserTravelRequestsAsyncStringStringInt32Int32Int32 = (id, filter, status, size, count) =>
            {
                called = true;
                return(Task.FromResult(new List <TravelRequest>().AsEnumerable()));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            var result = await target.GetUserTravelRequests(string.Empty, 1, 1, 1);

            Assert.IsNotNull(result);
            Assert.IsTrue(called);
        }
Exemplo n.º 6
0
        public async Task TravelRequestsController_GetAllCount_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            travelRequestsRepository.GetAllCountAsyncStringInt32 = (filter, status) =>
            {
                called = true;

                return(Task.FromResult(10));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            var result = await target.GetAllCount(string.Empty, 1);

            Assert.IsNotNull(result);
            Assert.IsTrue(called);
        }
Exemplo n.º 7
0
        public async Task TravelRequestsController_GetTeamTravelDistribution_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            travelRequestsRepository.GetTeamTravelDistributionAsyncStringInt32 = (id, numPictures) =>
            {
                called = true;

                return(Task.FromResult(new List <TravelDistribution>().AsEnumerable()));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            var result = await target.GetTeamTravelDistribution(5);

            Assert.IsNotNull(result);
            Assert.IsTrue(called);
        }
Exemplo n.º 8
0
        public async Task TravelRequestsController_Get_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            travelRequestsRepository.GetCompleteInfoAsyncInt32PictureType = (id, picture) =>
            {
                called = true;

                return(Task.FromResult(new TravelRequest()));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            var result = await target.Get(1, PictureType.Small);

            Assert.IsNotNull(result);
            Assert.IsTrue(called);
        }
Exemplo n.º 9
0
        public async Task TravelRequestsController_Add_Test()
        {
            bool called = false;
            var  travelRequestsRepository = new Data.Repositories.Fakes.StubITravelRequestRepository();
            var  employeeRepository       = new Data.Repositories.Fakes.StubIEmployeeRepository();
            var  notificationService      = new Web.Notifications.Fakes.StubITravelNotificationService();

            var newTravelRequests = new TravelRequest()
            {
                TravelRequestId = 1,
            };

            travelRequestsRepository.AddAsyncTravelRequest = (TravelRequest) =>
            {
                Assert.IsTrue(newTravelRequests.TravelRequestId == TravelRequest.TravelRequestId);
                called = true;

                return(Task.FromResult(10));
            };

            travelRequestsRepository.GetAsyncInt32 = (travelRequestId) =>
            {
                return(Task.FromResult(new TravelRequest()
                {
                    TravelRequestId = travelRequestId
                }));
            };

            travelRequestsRepository.GetWithEmployeeInfoAsyncInt32 = (travelRequestId) =>
            {
                return(Task.FromResult(new TravelRequest()
                {
                    TravelRequestId = travelRequestId
                }));
            };

            employeeRepository.GetAsyncInt32 = (id) =>
            {
                return(Task.FromResult(new Employee
                {
                    EmployeeId = id,
                    Team = new Team()
                    {
                        Manager = new Employee()
                        {
                            EmployeeId = 1,
                            Email = "*****@*****.**"
                        }
                    }
                }));
            };

            notificationService.EmailNotifyNewRequestTravelRequest = (travelRequest) =>
            {
                return(Task.FromResult(string.Empty));
            };

            var target = new TravelRequestsController(travelRequestsRepository, employeeRepository, new SecurityHelper(), notificationService);
            await target.Add(newTravelRequests);

            Assert.IsTrue(called);
        }