public IDataResult <Guid> Add(DebitForAddDto debitForAddDto) { var fixture = fixtureService.GetById(debitForAddDto.FixtureId).Data; if (fixture.FixturePositionId != (short)FixturePositions.Position.Available) { throw new LogicException(Messages.DebitFixturePosIsNotAvailable); } var debit = new Debit() { CreatedAt = DateTime.Now, DateDebit = debitForAddDto.DateDebit, DateReturn = DateTime.MaxValue, Description = debitForAddDto.Description, FixtureId = debitForAddDto.FixtureId, IsReturn = false, UpdatedAt = DateTime.Now, UserId = debitForAddDto.UserId }; debitDal.Add(debit); fixtureService.UpdatePosition(debitForAddDto.FixtureId, FixturePositions.Position.Debit); return(new SuccessDataResult <Guid>(debit.Id, Messages.DebitAdded)); }
public IActionResult Add(DebitForAddDto debitForAddDto) { var result = debitService.Add(debitForAddDto); if (result.Success) { return(CreatedAtAction("GetById", new { id = result.Data }, result.Message)); } return(BadRequest(result.Message)); }
public void Add_WhenFixturePositionIsNotAvailable_ShouldThrowLogicException() { // Arrange DebitForAddDto debitForAddDto = new DebitForAddDto(); IDataResult <Fixture> fixtureDataResult = new SuccessDataResult <Fixture>(new Fixture() { FixturePositionId = 2 }); var mockDebitDal = new MockDebitDal().MockAdd(new Debit()); var mockFixtureService = new MockFixtureService().MockGetById(fixtureDataResult).MockUpdatePostiton(new SuccessResult()); var sut = new DebitManager(mockDebitDal.Object, mockFixtureService.Object); // Act & Assert Assert.Throws <LogicException>(() => sut.Add(debitForAddDto)); }
private async Task AddDebit() { DebitForAddDto debitForAddDto = new DebitForAddDto() { DateDebit = dtpDateDebit.Value.Date, Description = txtDescription.Text, FixtureId = _selectedFixtureId, UserId = _selectedUserId }; await DebitService.Add(debitForAddDto); MessageBox.Show(Messages.DebitAdded); await LoadDebitList(); }
public static async Task <Uri> Add(DebitForAddDto debitForAddDto) { using var client = new HttpClient(); var uri = $"{APIAddresses.DebitService}"; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FormAccessToken.Token); var response = await client.PostAsJsonAsync(uri, debitForAddDto); if (response.IsSuccessStatusCode) { return(response.Headers.Location); } var errorContent = response.Content.ReadFromJsonAsync <ErrorDetail>().Result; throw new HttpFailureException(errorContent); }
public void Add_WhenAddedNewDebit_ShouldAddAndReturnId() { // Arrange DebitForAddDto debitForAddDto = new DebitForAddDto(); IDataResult <Fixture> fixtureDataResult = new SuccessDataResult <Fixture>(new Fixture() { FixturePositionId = 1 }); var mockDebitDal = new MockDebitDal().MockAdd(new Debit()); var mockFixtureService = new MockFixtureService().MockGetById(fixtureDataResult).MockUpdatePostiton(new SuccessResult()); var sut = new DebitManager(mockDebitDal.Object, mockFixtureService.Object); // Act var result = sut.Add(debitForAddDto); // Assert Assert.Equal(new Guid(), result.Data); }
public void DebitForAddValidator_TrueStory() { // Arrange var model = new DebitForAddDto() { DateDebit = DateTime.Now.AddDays(-1), Description = "Desc Debit", FixtureId = Guid.NewGuid(), UserId = Guid.NewGuid() }; var sut = new DebitForAddValidator(); // Act var result = sut.TestValidate(model); // Assert result.ShouldNotHaveAnyValidationErrors(); }