public void Can_Save_New_Income() { Income newIncome = new Income( "AnyIncome", 23000, "any-stffs-id-12ert" ); var service = new IncomeService(_mockIncomeRepository.Object); service.CreateIncome(newIncome); _mockIncomeRepository.Verify(x => x.Create(It.Is <Income>(inc => inc.Description == "AnyIncome" ))); }
public void Can_Update_Saved_Income() { Income newIncome = _sampleIncomes[0]; var service = new IncomeService(_mockIncomeRepository.Object); service.CreateIncome(newIncome); _mockIncomeRepository.Verify(x => x.Update(It.Is <Income>( inc => inc.Description == newIncome.Description && inc.Amount == newIncome.Amount && inc.StaffId == newIncome.StaffId && inc.Staff == newIncome.Staff && inc.Id == newIncome.Id)) ); }
public async Task <IActionResult> PostIncome(IncomeModel income) { try { if (income.WalletId == null) { throw new NullReferenceException(); } await _incomeService.CreateIncome(userId, income); return(Ok()); } catch (Exception e) { return(BadRequest()); } }
public IHttpActionResult Post([FromBody] object value) { var json = JObject.Parse(value.ToString()); var username = json["Username"].ToString(); var date = DateTime.Parse(json["Date"].ToString()).ToString("yyyy-MM-dd"); var description = json["Description"].ToString(); float.TryParse(json["Amount"].ToString(), out var amount); if (!String.IsNullOrEmpty(username) && !date.IsNullOrWhiteSpace() && !String.IsNullOrEmpty(description) && amount > -1) { if (incomeService.CreateIncome(amount, date, username, description)) { return(Content(HttpStatusCode.OK, "Indtægt oprettet")); } } return(Content(HttpStatusCode.BadRequest, "Forkert input, tjek værdierne og prøv igen.")); }