public async Task <IActionResult> CreateShooterAssociationInfo(ShooterAssociationInfoCreateRequest request) { var(validations, shooter, association) = CheckRequest(request.ShooterId, request.AssociationId, request.Categories); if (validations.Count > 0) { return(BadRequest(validations)); } var entity = new ShooterAssociationInfo { ShooterId = request.ShooterId, AssociationId = request.AssociationId, CardNumber = request.CardNumber, SafetyOfficier = request.SafetyOfficier, RegistrationDate = request.RegistrationDate, Categories = request.Categories }; //Invocazione del service layer validations = await BasicLayer.CreateShooterAssociationInfo(entity, PlatformUtils.GetIdentityUserId(User)); if (validations.Count > 0) { return(BadRequest(validations)); } //Return contract return(Ok(ContractUtils.GenerateContract(entity, association, shooter))); }
public async Task ShouldCreateShooterAssociationInfoBeOkHavingProvidedData() { var shooterIds = Scenario.ShooterAssociationInfos.Select(x => x.ShooterId).ToList(); var existing = Scenario.Shooters.FirstOrDefault(x => !shooterIds.Contains(x.Id)); if (existing == null) { Assert.Inconclusive("No shooter without association exists"); } //Conteggio gli elementi prima della creazione var countBefore = Scenario.ShooterAssociationInfos.Count; var existingAssociation = Scenario.Associations.FirstOrDefault(); //Composizione della request var request = new ShooterAssociationInfoCreateRequest { AssociationId = existingAssociation.Id, ShooterId = existing.Id, SafetyOfficier = true, RegistrationDate = RandomizationUtils.GetRandomDate(), CardNumber = RandomizationUtils.GenerateRandomString(5), Categories = new List <string> { existingAssociation.Categories.FirstOrDefault() } }; //Invoke del metodo var response = await Controller.CreateShooterAssociationInfo(request); //Conteggio gli elementi dopo la creazione var countAfter = Scenario.ShooterAssociationInfos.Count; //Parsing della risposta e assert var parsed = ParseExpectedOk <ShooterAssociationInfoContract>(response); Assert.IsTrue(parsed != null && countAfter == countBefore + 1 && parsed != null && parsed.Data.Association.AssociationId == request.AssociationId && parsed.Data.Shooter.ShooterId == request.ShooterId && parsed.Data.RegistrationDate == request.RegistrationDate && parsed.Data.SafetyOfficier == request.SafetyOfficier && parsed.Data.CardNumber == request.CardNumber && parsed.Data.Categories.All(x => request.Categories.Contains(x)) ); }
public async Task ShouldCreateShooterAssociationInfoBeBadRequestHavingProvidedWrongCategories() { var shooterIds = Scenario.ShooterAssociationInfos.Select(x => x.ShooterId).ToList(); var existing = Scenario.Shooters.FirstOrDefault(x => !shooterIds.Contains(x.Id)); if (existing == null) { Assert.Inconclusive("No shooter without association exists"); } //Conteggio gli elementi prima della creazione var countBefore = Scenario.ShooterAssociationInfos.Count; var existingAssociation = Scenario.Associations.FirstOrDefault(); //Composizione della request var request = new ShooterAssociationInfoCreateRequest { AssociationId = existingAssociation.Id, ShooterId = existing.Id, SafetyOfficier = false, CardNumber = RandomizationUtils.GenerateRandomString(5), Categories = new List <string> { RandomizationUtils.GenerateRandomString(5) } }; //Invoke del metodo var response = await Controller.CreateShooterAssociationInfo(request); //Conteggio gli elementi dopo la creazione var countAfter = Scenario.ShooterAssociationInfos.Count; //Parsing della risposta e assert var parsed = ParseExpectedBadRequest(response); Assert.AreEqual(countBefore, countAfter); Assert.IsTrue(parsed != null && // the old one should be closed with end date parsed.Data.Any() ); }