Пример #1
0
        public async Task ShouldCreateShooterAssociationBeBadRequestHaavingProvidedWrongAssociation()
        {
            var existing = Scenario.Shooters.FirstOrDefault();

            //Conteggio gli elementi prima della creazione
            var countBefore = Scenario.ShooterAssociations.Count;

            //Composizione della request
            var request = new ShooterAssociationCreateRequest
            {
                AssociationId    = RandomizationUtils.GenerateRandomString(5),
                ShooterId        = existing.Id,
                RegistrationDate = DateTime.Now,
                Classification   = RandomizationUtils.GenerateRandomString(5),
                Division         = RandomizationUtils.GenerateRandomString(5)
            };

            //Invoke del metodo
            var response = await Controller.UpsertShooterAssociation(request);

            //Conteggio gli elementi dopo la creazione
            var countAfter = Scenario.ShooterAssociations.Count;

            //Parsing della risposta e assert
            var parsed = ParseExpectedBadRequest(response);

            Assert.AreEqual(countBefore, countAfter);
            Assert.IsTrue(parsed != null &&
                          parsed.Data.Count > 0);
        }
Пример #2
0
        public async Task ShouldCreateShooterAssociationBeOkHavingProvidedData()
        {
            // select a shooter with shooterassociationInfo but withtout any classification
            var match = Scenario.ShooterAssociationInfos.Select(x => new { x.ShooterId, x.AssociationId })
                        .GroupJoin(Scenario.ShooterAssociations, x => x, x => new { x.ShooterId, x.AssociationId },
                                   (x, y) => new
            {
                x,
                match = y.DefaultIfEmpty()
            }).FirstOrDefault(x => x.match == null)?.x;

            if (match == null)
            {
                Assert.Inconclusive("No shooter without association exists");
            }
            //Conteggio gli elementi prima della creazione
            var countBefore = Scenario.ShooterAssociations.Count;

            var existingAssociation = Scenario.Associations.FirstOrDefault(x => x.Id == match.AssociationId);

            //Composizione della request
            var request = new ShooterAssociationCreateRequest
            {
                AssociationId    = existingAssociation.Id,
                ShooterId        = match.ShooterId,
                RegistrationDate = DateTime.Now,
                Classification   = existingAssociation.Classifications.FirstOrDefault(),
                Division         = existingAssociation.Divisions.FirstOrDefault()
            };

            //Invoke del metodo
            var response = await Controller.UpsertShooterAssociation(request);

            //Conteggio gli elementi dopo la creazione
            var countAfter = Scenario.ShooterAssociations.Count;

            //Parsing della risposta e assert
            var parsed = ParseExpectedOk <OkResponse>(response);

            var updatedEntity = Scenario.ShooterAssociations.FirstOrDefault(x => x.AssociationId == request.AssociationId && x.ShooterId == request.ShooterId);

            Assert.IsTrue(parsed != null &&
                          countAfter == countBefore + 1 &&
                          updatedEntity != null &&
                          updatedEntity.AssociationId == request.AssociationId &&
                          updatedEntity.ShooterId == request.ShooterId &&
                          updatedEntity.RegistrationDate == request.RegistrationDate &&
                          updatedEntity.Classification == request.Classification &&
                          updatedEntity.Division == request.Division
                          );
        }
        public Task <IActionResult> UpsertShooterAssociation(ShooterAssociationCreateRequest request)
        {
            var availableAssociationIds = BasicLayer.FetchAllShooterAssociationInfos(request.ShooterId).Select(x => x.AssociationId);

            IList <ValidationResult> validations = new List <ValidationResult>();

            if (!availableAssociationIds.Contains(request.AssociationId))
            {
                validations.Add(new ValidationResult("User is not registered for the selected association"));
                return(BadRequestTask(validations));
            }

            var entity = this.BasicLayer.GetActiveShooterAssociationByShooterAndAssociationAndDivision(request.ShooterId, request.AssociationId, request.Division);


            if (entity != null)
            {
                entity.ExpireDate = entity.RegistrationDate.AddDays(-1);
                validations       = BasicLayer.UpsertShooterAssociation(entity);

                if (validations.Count > 0)
                {
                    return(BadRequestTask(validations));
                }
            }

            entity                  = new ShooterAssociation();
            entity.ShooterId        = request.ShooterId;
            entity.AssociationId    = request.AssociationId;
            entity.Classification   = request.Classification;
            entity.Division         = request.Division;
            entity.RegistrationDate = request.RegistrationDate;

            //Invocazione del service layer
            validations = BasicLayer.UpsertShooterAssociation(entity);

            if (validations.Count > 0)
            {
                return(BadRequestTask(validations));
            }

            //Return contract
            return(Reply(new OkResponse {
                Status = true
            }));
        }
Пример #4
0
        public async Task ShouldUpdateShooterAssociationBeOkHavingProvidedData()
        {
            var existing = Scenario.ShooterAssociations.FirstOrDefault();
            //Conteggio gli elementi prima della creazione
            var countBefore = Scenario.ShooterAssociations.Count;

            //Composizione della request
            var request = new ShooterAssociationCreateRequest
            {
                AssociationId    = existing.AssociationId,
                ShooterId        = existing.ShooterId,
                RegistrationDate = DateTime.Now,
                Classification   = existing.Classification,
                Division         = existing.Division
            };

            //Invoke del metodo
            var response = await Controller.UpsertShooterAssociation(request);

            //Conteggio gli elementi dopo la creazione
            var countAfter = Scenario.ShooterAssociations.Count;

            //Parsing della risposta e assert
            var parsed = ParseExpectedOk <OkResponse>(response);

            var oldEntity = Scenario.ShooterAssociations.FirstOrDefault(x => x.Id == existing.Id);

            var updatedEntity = Scenario.ShooterAssociations.FirstOrDefault(x => x.AssociationId == request.AssociationId && x.ShooterId == request.ShooterId && !x.ExpireDate.HasValue);

            Assert.AreEqual(countBefore + 1, countAfter);
            Assert.IsTrue(parsed != null
                          // the old one should be closed with end date
                          && oldEntity.ExpireDate != null &&
                          updatedEntity.AssociationId == request.AssociationId &&
                          updatedEntity.ShooterId == request.ShooterId &&
                          updatedEntity.RegistrationDate == request.RegistrationDate &&
                          updatedEntity.Classification == request.Classification &&
                          updatedEntity.Division == request.Division
                          );
        }