public void ShouldReturnDelegationDetailsVm()
        {
            var del    = SetDelegation();
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper  = config.CreateMapper();
            var delRepo = new Mock <IDelegationRepository>();

            delRepo.Setup(d => d.GetDelegationById(1)).Returns(del);
            delRepo.Setup(d => d.GetRouteById(1)).Returns(del.Routes.FirstOrDefault(r => r.Id == 1));
            var vehRepo            = new Mock <IVehicleRepository>();
            var empRepo            = new Mock <IEmployeeRepository>();
            var delServ            = new DelegationService(delRepo.Object, empRepo.Object, vehRepo.Object, mapper);
            var delDetailsVmResult = delServ.GetDelegationDetails(1);

            delDetailsVmResult.Should().BeOfType(typeof(DelegationDetailVm));
            delDetailsVmResult.Should().NotBeNull();
            delDetailsVmResult.Costs.Should().AllBeOfType(typeof(CostForListVm));
            delDetailsVmResult.Costs.Should().NotBeNullOrEmpty();
            delDetailsVmResult.Routes.Should().AllBeOfType(typeof(RouteForListVm));
            delDetailsVmResult.Routes.Should().NotBeNullOrEmpty();
        }
        public void ShouldCaluclateAndSetAllowence()
        {
            var delWith13H = SetDelegation();
            var delWith9H  = SetDelegation();
            var delWith3H  = SetDelegation();

            var routes13H = new List <Route>()
            {
                new Route {
                    Id          = 1, CreatedDateTime = DateTime.Now, DelegationId = 1, RouteTypeId = 1, TypeOfTransportId = 1,
                    RouteDetail = new RouteDetail()
                    {
                        Id         = 1, RouteRef = 1, VehicleId = 2, StartDate = DateTime.Now, EndDate = DateTime.Now,
                        StartPoint = "start", EndPoint = "end", Kilometers = 35
                    }
                },
                new Route {
                    Id          = 11, CreatedDateTime = DateTime.Now, DelegationId = 1, RouteTypeId = 2, TypeOfTransportId = 1,
                    RouteDetail = new RouteDetail()
                    {
                        Id         = 11, RouteRef = 11, VehicleId = 2, StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(13),
                        StartPoint = "start", EndPoint = "end", Kilometers = 35
                    }
                }
            };

            delWith13H.Routes = routes13H;
            var routes9h = new List <Route>()
            {
                new Route {
                    Id          = 2, CreatedDateTime = DateTime.Now, DelegationId = 2, RouteTypeId = 1, TypeOfTransportId = 1,
                    RouteDetail = new RouteDetail()
                    {
                        Id         = 2, RouteRef = 2, VehicleId = 2, StartDate = DateTime.Now, EndDate = DateTime.Now,
                        StartPoint = "start", EndPoint = "end", Kilometers = 100
                    }
                },
                new Route {
                    Id          = 22, CreatedDateTime = DateTime.Now, DelegationId = 2, RouteTypeId = 2, TypeOfTransportId = 1,
                    RouteDetail = new RouteDetail()
                    {
                        Id         = 22, RouteRef = 22, VehicleId = 2, StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(9),
                        StartPoint = "start", EndPoint = "end", Kilometers = 100
                    }
                }
            };

            delWith9H.Id     = 2;
            delWith9H.Routes = routes9h;
            var routes3h = new List <Route>()
            {
                new Route {
                    Id          = 3, CreatedDateTime = DateTime.Now, DelegationId = 3, RouteTypeId = 1, TypeOfTransportId = 1,
                    RouteDetail = new RouteDetail()
                    {
                        Id         = 3, RouteRef = 3, VehicleId = 2, StartDate = DateTime.Now, EndDate = DateTime.Now,
                        StartPoint = "start", EndPoint = "end", Kilometers = 23
                    }
                },
                new Route {
                    Id          = 33, CreatedDateTime = DateTime.Now, DelegationId = 3, RouteTypeId = 2, TypeOfTransportId = 1,
                    RouteDetail = new RouteDetail()
                    {
                        Id         = 33, RouteRef = 33, VehicleId = 2, StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(3),
                        StartPoint = "start", EndPoint = "end", Kilometers = 43
                    }
                }
            };

            delWith3H.Id     = 3;
            delWith3H.Routes = routes3h;

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper  = config.CreateMapper();
            var delRepo = new Mock <IDelegationRepository>();

            delRepo.Setup(d => d.GetDelegationById(1)).Returns(delWith13H);
            delRepo.Setup(d => d.GetRouteById(1)).Returns(delWith13H.Routes.FirstOrDefault(r => r.Id == 1));
            delRepo.Setup(d => d.GetDelegationById(2)).Returns(delWith9H);
            delRepo.Setup(d => d.GetRouteById(2)).Returns(delWith9H.Routes.FirstOrDefault(r => r.Id == 2));
            delRepo.Setup(d => d.GetDelegationById(3)).Returns(delWith3H);
            delRepo.Setup(d => d.GetRouteById(3)).Returns(delWith3H.Routes.FirstOrDefault(r => r.Id == 3));
            delRepo.Setup(d => d.GetRouteById(11)).Returns(delWith13H.Routes.FirstOrDefault(r => r.Id == 11));
            delRepo.Setup(d => d.GetRouteById(22)).Returns(delWith9H.Routes.FirstOrDefault(r => r.Id == 22));
            delRepo.Setup(d => d.GetRouteById(33)).Returns(delWith3H.Routes.FirstOrDefault(r => r.Id == 33));
            delRepo.Setup(d => d.GetSubsistanceAllowenceByDel(1)).Returns(30M);
            delRepo.Setup(d => d.GetSubsistanceAllowenceByDel(2)).Returns(30M);
            delRepo.Setup(d => d.GetSubsistanceAllowenceByDel(3)).Returns(30M);
            var vehRepo = new Mock <IVehicleRepository>();

            vehRepo.Setup(v => v.GetMilleageAllowenceByVehicle(2)).Returns(0.8395M);
            var empRepo = new Mock <IEmployeeRepository>();
            var delServ = new DelegationService(delRepo.Object, empRepo.Object, vehRepo.Object, mapper);

            var delWith13HResult = delServ.GetDelegationDetails(1);
            var delWith9HResult  = delServ.GetDelegationDetails(2);
            var delWith3HResult  = delServ.GetDelegationDetails(3);

            delWith13HResult.SubsistenceAllowence.Should().Be(30);
            delWith13HResult.MileageAllowence.Should().BeGreaterThan(50);
            delWith9HResult.SubsistenceAllowence.Should().Be(15);
            delWith9HResult.MileageAllowence.Should().BeGreaterThan(167);
            delWith3HResult.SubsistenceAllowence.Should().Be(0);
            delWith3HResult.MileageAllowence.Should().BeGreaterThan(55);
        }