public void Command_PublishSuccessMessage_IfSaveSuccess() { var cost = new Models.EmployeeCost(); command.Cost = cost; command.Execute(null); brokerMock.Verify(b => b.Publish(CommonMessages.SaveEmployeeCostSuccess, null)); }
public void Command_PublishFailedMessage_IfSaveFailed() { var cost = new Models.EmployeeCost(); serviceMock.Setup(s => s.Save(cost)).Throws<ServiceException>(); command.Cost = cost; command.Execute(null); brokerMock.Verify(b => b.Publish(CommonMessages.SaveEmployeeCostFailed, It.IsAny<Error>())); }
public void Command_PublishFailedMessage_IfSaveFailed() { var cost = new Models.EmployeeCost(); serviceMock.Setup(s => s.Save(cost)).Throws <ServiceException>(); command.Cost = cost; command.Execute(null); brokerMock.Verify(b => b.Publish(CommonMessages.SaveEmployeeCostFailed, It.IsAny <Error>())); }
public void Save(Models.EmployeeCost cost) { if (cost.IsNew) { base.CreatePostRequest(cost); } else { base.CreatePutRequest(cost.Id, 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_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_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); } }
void Compare(Models.Data.EmployeeCost costData, List <Models.Data.EmployeeCostDetail> details, Models.EmployeeCost cost) { Assert.Equal(costData.Id, cost.Id); Assert.Equal(costData.Date, cost.Date); Assert.Equal(costData.Total, cost.Total); if (details != null) { Assert.Equal(details.Count, cost.Details.Count); foreach (var detailData in details) { var detail = cost.Details.FirstOrDefault(d => d.EmployeeId == detailData.EmployeeId); Assert.Equal(detailData.Description, detail.Description); Assert.Equal(detailData.Present, detail.Present); Assert.Equal(detailData.Salary, detail.Salary); } } }
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); } }