public void Lender_has_negative_balance() { var url = "/iou"; var payload = "{\"lender\":\"Bob\",\"borrower\":\"Adam\",\"amount\":3.0}"; var database = "[{\"name\":\"Adam\",\"owes\":{},\"owed_by\":{},\"balance\":0.0},{\"name\":\"Bob\",\"owes\":{\"Chuck\":3.0},\"owed_by\":{},\"balance\":-3.0},{\"name\":\"Chuck\",\"owes\":{},\"owed_by\":{\"Bob\":3.0},\"balance\":3.0}]"; var sut = new RestApi.Api.RestApi(database); var actual = sut.Post(url, payload); var expected = "[{\"name\":\"Adam\",\"owes\":{\"Bob\":3.0},\"owed_by\":{},\"balance\":-3.0},{\"name\":\"Bob\",\"owes\":{\"Chuck\":3.0},\"owed_by\":{\"Adam\":3.0},\"balance\":0.0}]"; Assert.Equal(expected, actual); }
public void Lender_owes_borrower_less_than_new_loan() { var url = "/iou"; var payload = "{\"lender\":\"Adam\",\"borrower\":\"Bob\",\"amount\":4.0}"; var database = "[{\"name\":\"Adam\",\"owes\":{\"Bob\":3.0},\"owed_by\":{},\"balance\":-3.0},{\"name\":\"Bob\",\"owes\":{},\"owed_by\":{\"Adam\":3.0},\"balance\":3.0}]"; var sut = new RestApi.Api.RestApi(database); var actual = sut.Post(url, payload); var expected = "[{\"name\":\"Adam\",\"owes\":{},\"owed_by\":{\"Bob\":1.0},\"balance\":1.0},{\"name\":\"Bob\",\"owes\":{\"Adam\":1.0},\"owed_by\":{},\"balance\":-1.0}]"; Assert.Equal(expected, actual); }
public void Add_user() { var url = "/add"; var payload = "{\"user\":\"Adam\"}"; var database = "[]"; var sut = new RestApi.Api.RestApi(database); var actual = sut.Post(url, payload); var expected = "{\"name\":\"Adam\",\"owes\":{},\"owed_by\":{},\"balance\":0.0}"; Assert.Equal(expected, actual); }