public async Task <IActionResult> CreateShooterTeamPayment(ShooterTeamPaymentCreateRequest request) { //Creazione modello richiesto da admin var model = new ShooterTeamPayment { ShooterId = request.ShooterId, TeamId = request.TeamId, Amount = request.Amount, Reason = request.Reason, PaymentDateTime = request.PaymentDateTime, ExpireDateTime = request.ExpireDateTime, NotifyExpiration = request.NotifyExpiration }; //Invocazione del service layer var validations = await BasicLayer.CreateShooterTeamPayment(model, PlatformUtils.GetIdentityUserId(User)); if (validations.Count > 0) { return(BadRequest(validations)); } //Return contract return(Ok(ContractUtils.GenerateContract(model))); }
public async Task ShouldCreateShooterTeamPaymentBeOkHavingProvidedData() { var shooterIds = Scenario.ShooterTeamPayments.Select(x => x.ShooterId).ToList(); var existing = Scenario.Shooters.FirstOrDefault(x => !shooterIds.Contains(x.Id)); if (existing == null) { Assert.Inconclusive("No shooter team payment without association exists"); } //Conteggio gli elementi prima della creazione var countBefore = Scenario.ShooterTeamPayments.Count; var existingTeam = Scenario.Teams.FirstOrDefault(); //Composizione della request var request = new ShooterTeamPaymentCreateRequest { TeamId = existingTeam.Id, ShooterId = existing.Id, Reason = RandomizationUtils.GenerateRandomString(15), Amount = 1, PaymentDateTime = RandomizationUtils.GetRandomDate() }; //Invoke del metodo var response = await Controller.CreateShooterTeamPayment(request); //Conteggio gli elementi dopo la creazione var countAfter = Scenario.ShooterTeamPayments.Count; //Parsing della risposta e assert var parsed = ParseExpectedOk <ShooterTeamPaymentContract>(response); var updatedEntity = Scenario.ShooterTeamPayments.FirstOrDefault(x => x.Id == parsed.Data.ShooterTeamPaymentId); Assert.IsTrue(parsed != null && countAfter == countBefore + 1 && updatedEntity.TeamId == request.TeamId && updatedEntity.ShooterId == request.ShooterId && updatedEntity.Amount == request.Amount && updatedEntity.Reason == request.Reason && updatedEntity.PaymentDateTime == request.PaymentDateTime && updatedEntity.ExpireDateTime == request.ExpireDateTime && updatedEntity.NotifyExpiration == request.NotifyExpiration ); }