public void Can_GetByDate()
        {
            Models.Data.EmployeeCost costData = null;
            var details = new List<Models.Data.EmployeeCostDetail>();
            DateTime today = DateTime.Today;

            using (var conn = factory.OpenDbConnection())
            {
                Guid dataId = Guid.NewGuid();

                costData = new Models.Data.EmployeeCost
                {
                    Id = dataId,
                    Date = today,
                    Total = 100000
                };

                conn.InsertParam(costData);

                for (int i = 0; i < 2; i++)
                {
                    var employee = new Employee
                    {
                        Active = true,
                        Id = Guid.NewGuid(),
                        Name = "Employee-" + i,
                        Salary = 50000
                    };

                    conn.InsertParam(employee);

                    var detail = new Models.Data.EmployeeCostDetail();
                    detail.CostId = dataId;
                    detail.Description = "Desc" + i;
                    detail.Present = true;
                    detail.Salary = 50000;
                    detail.EmployeeId = employee.Id;

                    conn.InsertParam(detail);
                    details.Add(detail);
                }

                var cost = service.GetByDate(today);
                Compare(costData, details, cost);
            }
        }
        public void Can_SaveNewCost()
        {
            var employee = new Employee
            {
                Active = true,
                Id = Guid.NewGuid(),
                Name = "Employee #1",
                Salary = 50000
            };

            using (var conn = factory.OpenDbConnection())
            {
                conn.InsertParam(employee);
            }

            var cost = new Models.EmployeeCost
                {
                    Date = DateTime.Today,
                    Total = 100000,
                    Details = new List<EmployeeCostDetail>()
                        {
                            new EmployeeCostDetail
                                {
                                    EmployeeId = employee.Id,
                                    Description = "Desc",
                                    Present = true,
                                    Salary = 100000
                                }
                        }
                };

            service.Save(cost);

            using (var conn = factory.OpenDbConnection())
            {
                var costData = conn.FirstOrDefault<Models.Data.EmployeeCost>(c => c.Date == cost.Date);
                var details = conn.Where<Models.Data.EmployeeCostDetail>(new {CostId = costData.Id});
                Compare(costData, details, cost);
            }
        }
        public void Can_SearchByDate()
        {
            var employee = new Employee
            {
                Active = true,
                Id = Guid.NewGuid(),
                Name = "Employee #1",
                Salary = 50000
            };

            var costData = new Models.Data.EmployeeCost
            {
                Id = Guid.NewGuid(),
                Date = DateTime.Today,
                Total = 1000
            };

            using (var conn = factory.OpenDbConnection())
            {
                conn.InsertParam(employee);
                conn.InsertParam(costData);
            }

            var result = service.Search(new DateRangeSearchInfo
                {
                    Start = DateTime.Today.AddDays(-1),
                    End = DateTime.Today.AddDays(10),
                    PageIndex = 1,
                    PageSize = 10
                });

            Assert.Equal(1, result.Total);
            Compare(costData, null, result.Items[0]);
        }
        public void Can_SaveExistingCost()
        {
            var employee = new Employee
            {
                Active = true,
                Id = Guid.NewGuid(),
                Name = "Employee #1",
                Salary = 50000
            };

            Guid id = Guid.NewGuid();

            Models.Data.EmployeeCost costData = null;
            Models.Data.EmployeeCostDetail costDetail = null;

            using (var conn = factory.OpenDbConnection())
            {
                conn.InsertParam(employee);

                costData = new Models.Data.EmployeeCost
                {
                    Id =id,
                    Date = DateTime.Today,
                    Total = 1000
                };

                conn.InsertParam(costData);

                costDetail = new Models.Data.EmployeeCostDetail
                    {
                        CostId = id,
                        EmployeeId = employee.Id,
                        Description = "desc",
                        Present = true,
                        Salary = 1000
                    };

                conn.InsertParam(costDetail);
            }

            var model = new Models.EmployeeCost
                {
                    Id = id,
                    Date = DateTime.Today.AddDays(1),
                    Total = 10000,
                    Details = new List<EmployeeCostDetail>
                        {
                            new EmployeeCostDetail
                                {
                                    Description = "des",
                                    EmployeeId = employee.Id,
                                    Present = false,
                                    Salary = 10000
                                }
                        }
                };

            service.Save(model);

            using (var conn = factory.OpenDbConnection())
            {
                costData = conn.FirstOrDefault<Models.Data.EmployeeCost>(c => c.Date == model.Date);
                var details = conn.Where<Models.Data.EmployeeCostDetail>(new { CostId = costData.Id });
                Compare(costData, details, model);
            }
        }