Ejemplo n.º 1
0
        public async Task ShouldUpdateTeamHolderBeOkHavingProvidedData()
        {
            var existing = Scenario.TeamHolders.FirstOrDefault();
            //Conteggio gli elementi prima della creazione
            var countBefore = Scenario.TeamHolders.Count;

            //Composizione della request
            var request = new TeamHolderCreateRequest
            {
                TeamId      = existing.TeamId,
                ShooterId   = existing.ShooterId,
                Description = RandomizationUtils.GenerateRandomString(5)
            };

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

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

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

            var updatedEntity = Scenario.TeamHolders.FirstOrDefault(x => x.Id == parsed.Data.TeamHolderId);

            Assert.IsNotNull(parsed);
            Assert.AreEqual(countAfter, countBefore);
            Assert.IsTrue(updatedEntity.TeamId == request.TeamId &&
                          updatedEntity.ShooterId == request.ShooterId &&
                          updatedEntity.Description == request.Description
                          );
        }
Ejemplo n.º 2
0
        public Task <IActionResult> UpsertTeamHolder(TeamHolderCreateRequest request)
        {
            var entity = this.BasicLayer.GetTeamHolderByTeamAndShooterId(request.TeamId, request.ShooterId);

            if (entity == null)
            {
                entity = new TeamHolder
                {
                    ShooterId = request.ShooterId,
                    TeamId    = request.TeamId
                };
            }

            entity.Description = request.Description;

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

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

            //Return contract
            return(Reply(ContractUtils.GenerateContract(entity)));
        }
Ejemplo n.º 3
0
        public async Task ShouldCreateTeamHolderBeOkHavingProvidedData()
        {
            var shooterIds = Scenario.TeamHolders.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.TeamHolders.Count;

            var existingTeam = Scenario.Teams.FirstOrDefault();

            //Composizione della request
            var request = new TeamHolderCreateRequest
            {
                TeamId      = existingTeam.Id,
                ShooterId   = existing.Id,
                Description = RandomizationUtils.GenerateRandomString(15)
            };

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

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

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

            var updatedEntity = Scenario.TeamHolders.FirstOrDefault(x => x.Id == parsed.Data.TeamHolderId);

            Assert.IsTrue(parsed != null &&
                          countAfter == countBefore + 1 &&
                          updatedEntity.TeamId == request.TeamId &&
                          updatedEntity.ShooterId == request.ShooterId &&
                          updatedEntity.Description == request.Description
                          );
        }