public async Task <IActionResult> UpdateShooterAssociationInfo(ShooterAssociationInfoUpdateRequest request) { var entity = this.BasicLayer.GetShooterAssociationInfo(request.ShooterAssociationInfoId); if (entity == null) { return(NotFound()); } var(validations, shooter, association) = CheckRequest(request.ShooterId, request.AssociationId, request.Categories); if (validations.Count > 0) { return(BadRequest(validations)); } entity.ShooterId = request.ShooterId; entity.AssociationId = request.AssociationId; entity.CardNumber = request.CardNumber; entity.SafetyOfficier = request.SafetyOfficier; entity.Categories = request.Categories; entity.RegistrationDate = request.RegistrationDate; //Invocazione del service layer validations = await BasicLayer.UpdateShooterAssociationInfo(entity, PlatformUtils.GetIdentityUserId(User)); if (validations.Count > 0) { return(BadRequest(validations)); } //Return contract return(Ok(ContractUtils.GenerateContract(entity, association, shooter))); }
public async Task ShouldUpdateShooterAssociationInfoBeOkHavingProvidedData() { var existing = Scenario.ShooterAssociationInfos.FirstOrDefault(); //Conteggio gli elementi prima della creazione var countBefore = Scenario.ShooterAssociationInfos.Count; var existingAssociation = Scenario.Associations.FirstOrDefault(x => x.Id == existing.AssociationId); //Composizione della request var request = new ShooterAssociationInfoUpdateRequest { ShooterAssociationInfoId = existing.Id, AssociationId = existing.AssociationId, ShooterId = existing.ShooterId, RegistrationDate = RandomizationUtils.GetRandomDate(), SafetyOfficier = !existing.SafetyOfficier, CardNumber = RandomizationUtils.GenerateRandomString(5), Categories = new List <string> { existingAssociation.Categories.LastOrDefault() } }; //Invoke del metodo var response = await Controller.UpdateShooterAssociationInfo(request); //Conteggio gli elementi dopo la creazione var countAfter = Scenario.ShooterAssociationInfos.Count; //Parsing della risposta e assert var parsed = ParseExpectedOk <ShooterAssociationInfoContract>(response); Assert.AreEqual(countBefore, countAfter); Assert.IsTrue(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 ShouldUpdateShooterAssociationInfoBeBadRequestHavingProvidedSameCardId() { var existing = Scenario.ShooterAssociationInfos.FirstOrDefault(); var another = Scenario.ShooterAssociationInfos.FirstOrDefault(x => x.ShooterId != existing.ShooterId && x.AssociationId == existing.AssociationId); if (another == null) { Assert.Inconclusive("Another shooter association not found"); } //Conteggio gli elementi prima della creazione var countBefore = Scenario.ShooterAssociationInfos.Count; //Composizione della request var request = new ShooterAssociationInfoUpdateRequest { ShooterAssociationInfoId = existing.Id, AssociationId = existing.AssociationId, ShooterId = existing.ShooterId, SafetyOfficier = !existing.SafetyOfficier, CardNumber = another.CardNumber, }; //Invoke del metodo var response = await Controller.UpdateShooterAssociationInfo(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() ); }
public async Task ShouldUpdateShooterAssociationInfoBeBadRequestHavingProvidedWrongCategories() { var existing = Scenario.ShooterAssociationInfos.FirstOrDefault(); //Conteggio gli elementi prima della creazione var countBefore = Scenario.ShooterAssociationInfos.Count; //Composizione della request var request = new ShooterAssociationInfoUpdateRequest { ShooterAssociationInfoId = existing.Id, AssociationId = existing.AssociationId, ShooterId = existing.ShooterId, SafetyOfficier = !existing.SafetyOfficier, CardNumber = existing.CardNumber, Categories = new List <string> { RandomizationUtils.GenerateRandomString(5) } }; //Invoke del metodo var response = await Controller.UpdateShooterAssociationInfo(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() ); }