private string GenerateRulesText() { List <string> rulesTextStrings = new List <string>(); if (AdditionalCost != null) { StringBuilder additionalCostBuilder = new StringBuilder("As an additional cost to "); if ((Supertype & Supertype.Maneuver) > 0) { additionalCostBuilder.Append("initiate "); } else { additionalCostBuilder.Append("deploy "); } additionalCostBuilder.Append(Title); additionalCostBuilder.Append(", "); additionalCostBuilder.Append(AdditionalCost.ToString(this)); additionalCostBuilder.Append("."); rulesTextStrings.Add(additionalCostBuilder.ToString()); } if (_abilities != null) { foreach (Ability ability in _abilities) { rulesTextStrings.Add(ability.ToString(this)); } } return(string.Join(Environment.NewLine, rulesTextStrings)); }
public void GetId_ThrowsErrorsIfNotFound() { Guid id = Guid.NewGuid(); AdditionalCost cost = null; costServiceMock.Setup(s => s.Get(id)).Returns(cost); Assert.Throws <HttpResponseException>(() => controller.GetById(id)); }
public void Can_GetId() { Guid id = Guid.NewGuid(); var cost = new AdditionalCost(); costServiceMock.Setup(s => s.Get(id)).Returns(cost); Assert.Equal(cost, controller.GetById(id)); }
public void Put_ReturnsOK() { Guid id = Guid.NewGuid(); var cost = new AdditionalCost { Id = id, Name = "a", Value = 1 }; var msg = controller.Put(id, cost); Assert.Equal(HttpStatusCode.OK, msg.StatusCode); }
public void Post_GetBadRequest_IfNameIsNull() { var cost = new AdditionalCost { Value = 1 }; var msg = controller.Post(cost); Assert.Equal(HttpStatusCode.BadRequest, msg.StatusCode); AssertPropertyError(msg, "Name"); }
public static AdditionalCostResponse AdditionalCostToAdditionalCostResponse(AdditionalCost additionalCost) { return(new AdditionalCostResponse { Id = additionalCost.Id, Description = additionalCost.Description, Date = additionalCost.Date, Price = additionalCost.Price }); }
public void Post_GetBadRequest_IfValueIsZero() { var cost = new AdditionalCost { Name = "a" }; var msg = controller.Post(cost); Assert.Equal(HttpStatusCode.BadRequest, msg.StatusCode); AssertPropertyError(msg, "Value"); }
public void Post_ReturnsCreated() { var cost = new AdditionalCost { Name = "a", Value = 1 }; var msg = controller.Post(cost); //TODO: try find an easier way to mock Url.Link //Assert.Equal(HttpStatusCode.Created, msg.StatusCode); }
public void Save(AdditionalCost model) { if (model.IsNew) { CreatePostRequest(model); } else { CreatePutRequest(model.Id, model); } }
public void Post_ReturnsInternalServerError_IfSavingFailed() { var cost = new AdditionalCost { Name = "a", Value = 1 }; costServiceMock.Setup(c => c.Save(cost)).Throws(new Exception("Whatever")); var msg = controller.Post(cost); Assert.Equal(HttpStatusCode.InternalServerError, msg.StatusCode); }
public void Put_GetBadRequest_IfNameIsNull() { Guid id = Guid.NewGuid(); var cost = new AdditionalCost { Id = id, Value = 1 }; var msg = controller.Put(id, cost); Assert.Equal(HttpStatusCode.BadRequest, msg.StatusCode); AssertPropertyError(msg, "Name"); }
public async Task <IActionResult> AddExpense([Bind("ID,Start,End,Amount,Description")] AdditionalCost expense) { AdditionalCost newExpense = expense; if (ModelState.IsValid) { context.BoardTable.Add(newExpense); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(expense)); }
public static BaseAdditionalCostModel ToBaseAdditionalCost(this AdditionalCost additionalCost) { BaseAdditionalCostModel _result = new BaseAdditionalCostModel(); _result.Id = additionalCost.Id; _result.VoucherTypeId = additionalCost.VoucherTypeId; _result.LedgerId = additionalCost.LedgerId; _result.VoucherNumber = additionalCost.VoucherNumber; _result.Debit = additionalCost.Debit; _result.Credit = additionalCost.Credit; _result.CreatedDate = additionalCost.CreatedDate; _result.ModifiedDate = additionalCost.ModifiedDate; return(_result); }
public async Task EditAsyncShouldEditCostCorrectly() { // Arrange var inputModel = new AddCostEditInputModel { Id = 1, Name = "Print", Description = "Drawings", PricePerQuantity = 5.50M, Quantity = 20, }; var cost = new AdditionalCost { Id = 1, Name = "Print 2", Description = "Drawings Many", PricePerQuantity = 10.50M, Quantity = 20, }; await this.PlanItDbContext.AdditionalCosts.AddAsync(cost); await this.PlanItDbContext.SaveChangesAsync(); // Act var expected = new AdditionalCost { Id = 1, Name = "Print", Description = "Drawings", PricePerQuantity = 5.50M, Quantity = 20, TotalCost = 5.5M * 20, }; var actual = await this.AdditionalCostsService .EditAsync<AddCostEditInputModel>(inputModel); // Assert Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Description, actual.Description); Assert.Equal(expected.PricePerQuantity, actual.PricePerQuantity); Assert.Equal(expected.Quantity, actual.Quantity); Assert.Equal(expected.TotalCost, actual.TotalCost); }
public AdditionalCost AddCostSave(AdditionalCost addCost) { var isExists = addCostService.GetAll().Where(a => a.VoucherNo == addCost.VoucherNo && a.LedgerId == addCost.LedgerId).FirstOrDefault(); var max = addCostService.LastRow().OrderByDescending(a => a.Id).FirstOrDefault(); if (max == null) { addCost.Id = 1; } else { addCost.Id = max.Id + 1; } var result = addCostService.Save(addCost); return(result); }
public static AdditionalCost ToAdditionalCost(this BaseAdditionalCostModel additionalCost) { AdditionalCost _result = new AdditionalCost(); if (additionalCost.Id.HasValue) { _result.Id = additionalCost.Id.GetValueOrDefault(); } _result.VoucherTypeId = additionalCost.VoucherTypeId; _result.LedgerId = additionalCost.LedgerId; _result.VoucherNumber = additionalCost.VoucherNumber; _result.Debit = additionalCost.Debit; _result.Credit = additionalCost.Credit; _result.CreatedDate = additionalCost.CreatedDate; _result.ModifiedDate = additionalCost.ModifiedDate; return(_result); }
public async Task <IActionResult> Create([FromBody] AdditionalCostRequest customerRequest) { var additionalCost = new AdditionalCost { Description = customerRequest.Description, Price = customerRequest.Price, Date = customerRequest.Date }; await _additionalCostsService.CreateAsync(additionalCost); var baseurl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationuri = baseurl + "/" + ApiRoutes.AdditionalCosts.Get.Replace("{additionalCostId}", additionalCost.Id.ToString()); var response = AdditionalCostToAdditionalCostResponse(additionalCost); return(Created(locationuri, response)); }
public async Task <AdditionalCost> AddAsync <TInputModel>(TInputModel inputModel) { var input = AutoMapperConfig.MapperInstance.Map <AdditionalCost>(inputModel); var additionalCost = new AdditionalCost { Name = input.Name, Description = input.Description, PricePerQuantity = input.PricePerQuantity, Quantity = input.Quantity, TotalCost = input.PricePerQuantity * input.Quantity, ProjectId = input.ProjectId, SubProjectId = input.SubProjectId, }; await this.additionalCostsRepository.AddAsync(additionalCost); await this.additionalCostsRepository.SaveChangesAsync(); return(additionalCost); }
public async Task AddAsyncShouldAddCostCorrectly() { // Arrange var inputModel = new AddCostAddToSubProjectInputModel { Name = "Print", Description = "Drawings", PricePerQuantity = 5.50M, Quantity = 20, ProjectId = 1, SubProjectId = 1, }; // Act var expected = new AdditionalCost { Name = "Print", Description = "Drawings", PricePerQuantity = 5.50M, Quantity = 20, TotalCost = 5.5M * 20, ProjectId = 1, SubProjectId = 1, }; var actual = await this.AdditionalCostsService .AddAsync<AddCostAddToSubProjectInputModel>(inputModel); // Assert Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Description, actual.Description); Assert.Equal(expected.PricePerQuantity, actual.PricePerQuantity); Assert.Equal(expected.Quantity, actual.Quantity); Assert.Equal(expected.TotalCost, actual.TotalCost); Assert.Equal(expected.ProjectId, actual.ProjectId); Assert.Equal(expected.SubProjectId, actual.SubProjectId); }
private void delayChoice_Click(object sender, EventArgs e) { cost = AdditionalCost.Delay; }
private void mpChoice_Click(object sender, EventArgs e) { cost = AdditionalCost.MP; }