コード例 #1
0
        public async Task ShouldUpdateMatchBeOkHavingProvidedData()
        {
            //Recupero una Match esistente
            var existing = Scenario.Matches.FirstOrDefault();

            if (existing == null)
            {
                Assert.Inconclusive("Match does not exists");
            }

            var existingAssociation = Scenario.Associations.FirstOrDefault(x => x.Id != existing.AssociationId);
            var existingPlace       = Scenario.Places.FirstOrDefault(x => x.Id != existing.PlaceId);

            //conteggio esistenti
            var countBefore = Scenario.Matches.Count;


            //Composizione della request
            var request = new MatchUpdateRequest
            {
                MatchId              = existing.Id,
                Name                 = RandomizationUtils.GenerateRandomString(50),
                AssociationId        = existingAssociation.Id,
                PlaceId              = existingPlace.Id,
                MatchDateTimeStart   = DateTime.Now,
                MatchDateTimeEnd     = DateTime.Now.AddDays(1),
                OpenMatch            = !existing.OpenMatch,
                UnifyClassifications = !existing.UnifyClassifications
            };

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

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

            //conteggio esistenti
            var countAfter = Scenario.Matches.Count;


            Assert.IsTrue(parsed != null &&
                          parsed.Data.Name == request.Name &&
                          parsed.Data.Association.AssociationId == request.AssociationId &&
                          parsed.Data.Place.PlaceId == request.PlaceId &&
                          parsed.Data.MatchDateTimeStart == request.MatchDateTimeStart &&
                          parsed.Data.MatchDateTimeEnd == request.MatchDateTimeEnd &&
                          parsed.Data.OpenMatch == request.OpenMatch &&
                          parsed.Data.UnifyClassifications == request.UnifyClassifications);

            //verifica contatori
            Assert.AreEqual(countBefore, countAfter);
        }
コード例 #2
0
        public async Task ShouldUpdateMatchBeNotFoundHavingProvidedWrongId()
        {
            //conteggio esistenti
            var countBefore = Scenario.Matches.Count;

            var existingAssociation = Scenario.Associations.FirstOrDefault();
            var existingPlace       = Scenario.Places.FirstOrDefault();

            //Composizione della request
            var request = new MatchUpdateRequest
            {
                MatchId              = RandomizationUtils.GenerateRandomString(10),
                Name                 = RandomizationUtils.GenerateRandomString(50),
                AssociationId        = existingAssociation.Id,
                PlaceId              = existingPlace.Id,
                MatchDateTimeStart   = DateTime.Now,
                MatchDateTimeEnd     = DateTime.Now.AddDays(1),
                OpenMatch            = false,
                UnifyClassifications = false
            };

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

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

            //conteggio esistenti
            var countAfter = Scenario.Matches.Count;


            Assert.IsTrue(parsed != null &&
                          parsed.Data == null);

            //verifica contatori
            Assert.AreEqual(countBefore, countAfter);
        }
コード例 #3
0
        public async Task <IActionResult> UpdateMatch([EntityId] MatchUpdateRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetMatch(request.MatchId);

            //modifica solo se admin o se utente richiedente è lo stesso che ha creato
            if (entity == null)
            {
                return(NotFound());
            }

            //Aggiornamento dell'entità
            entity.Name = request.Name;
            entity.MatchDateTimeStart   = request.MatchDateTimeStart;
            entity.MatchDateTimeEnd     = request.MatchDateTimeEnd;
            entity.AssociationId        = request.AssociationId;
            entity.PlaceId              = request.PlaceId;
            entity.OpenMatch            = request.OpenMatch;
            entity.UnifyClassifications = request.UnifyClassifications;
            entity.Cost           = request.Cost;
            entity.PaymentDetails = request.PaymentDetails;

            //Salvataggio
            var validations = await BasicLayer.UpdateMatch(entity, PlatformUtils.GetIdentityUserId(User));

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

            var association = BasicLayer.GetAssociation(entity.AssociationId);
            var place       = BasicLayer.GetPlace(entity.PlaceId);

            //Confermo
            return(Ok(ContractUtils.GenerateContract(entity, association, place)));
        }