Beispiel #1
0
        public async Task ShouldFetchShooterSOStageBeOkHavingProvidedData()
        {
            var existingStageId = Scenario.ShooterSOStages.GroupBy(x => x.StageId).FirstOrDefault(x => x.Count() > 1)?.Key;

            if (string.IsNullOrEmpty(existingStageId))
            {
                Assert.Inconclusive("Existing stage not found");
            }

            //Conteggio gli elementi prima della creazione
            var countBefore = Scenario.ShooterSOStages.Count(x => x.StageId == existingStageId);


            //Composizione della request
            var request = new StageRequest
            {
                StageId = existingStageId,
            };

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

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

            Assert.IsTrue(parsed != null &&
                          parsed.Data.Count == countBefore
                          );
        }
Beispiel #2
0
        public void Update_ChangeStageName(string firstStageName, string secondStageName)
        {
            var context      = GetInMemoryUserService();
            var eventContext = GetInMemoryEventService();

            var createdEvent = eventContext.Create(_eventRequest, string.Empty);

            var stageRequest = new StageRequest
            {
                Name = firstStageName
            };

            var createdStage = context.Create(stageRequest, createdEvent.EventId);

            stageRequest = new StageRequest
            {
                Name    = secondStageName,
                StageId = createdStage.StageId
            };

            context.Update(stageRequest, createdEvent.EventId);

            var foundEvent = context.GetById(createdStage.StageId, createdEvent.EventId);

            Assert.Equal(secondStageName, foundEvent.Name);
        }
Beispiel #3
0
        public Task <IActionResult> FetchAvailableStageSO(StageRequest request)
        {
            //Recupero la lista dal layer
            var entities = BasicLayer.FetchAvailabelShooterSOByStageId(request.StageId);

            //Ritorno i contratti
            return(Reply(entities.As(x => ContractUtils.GenerateContract(x))));
        }
        public IActionResult Post([FromHeader] string eventId, [FromBody] StageRequest stage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _stageService.Create(stage, eventId);

            return(Ok());
        }
Beispiel #5
0
        public Task <IActionResult> FetchAllShooterSOStages(StageRequest request)
        {
            //Recupero la lista dal layer
            var entities = BasicLayer.FetchShooterSOStagesByStageId(request.StageId);

            var shooterIds = entities.Select(x => x.ShooterId).ToList();
            var shooters   = BasicLayer.FetchShootersByIds(shooterIds);

            //Ritorno i contratti
            return(Reply(entities.As(x => ContractUtils.GenerateContract(x, shooters.FirstOrDefault(s => s.Id == x.ShooterId)))));
        }
Beispiel #6
0
        public void Update(StageRequest element, string eventId)
        {
            var stage = _botEventManagementContext.Stages.Where(x => x.StageId == element.StageId && x.EventId == eventId).FirstOrDefault();

            if (element.Name != stage.Name)
            {
                stage.Name = element.Name;
            }

            _botEventManagementContext.Entry(stage).State = EntityState.Modified;
            _botEventManagementContext.SaveChanges();
        }
Beispiel #7
0
        public ResultBase Post([FromBody] StageRequest request)
        {
            ResultBase result = new ResultBase();
            User       user   = userDao.GetUser(request.UserID);

            user.Point = user.Point + request.Point;
            userDao.UpdateUser(user);
            stageResultDao.InsertStageRecord(request.UserID, request.Point);
            result.ResultCode = 1;
            result.Message    = "Success";
            return(result);
        }
Beispiel #8
0
        public async Task ShouldFetchAvailableShooterSOStagesBeOkHavingProvidedData()
        {
            // get stage with any shooterStage
            var existingStage = Scenario.Stages.FirstOrDefault(x => Scenario.ShooterSOStages.Any(s => s.StageId != x.Id));

            if (existingStage == null)
            {
                Assert.Inconclusive("Stage not found");
            }

            var existingMatch = Scenario.Matches.FirstOrDefault(x => x.Id == existingStage.MatchId);

            if (existingMatch == null)
            {
                Assert.Inconclusive("Match not found");
            }

            var shooterAssociations = Scenario.ShooterAssociationInfos.Where(x => x.SafetyOfficier && x.AssociationId == existingMatch.AssociationId)
                                      .Select(x => x.ShooterId).ToList();

            var stagesInMatch = Scenario.Stages.Where(x => x.MatchId == existingMatch.Id).Select(x => x.Id).ToList();

            var existingShooterSo = Scenario.ShooterSOStages.Where(x => stagesInMatch.Contains(x.StageId)).Select(x => x.ShooterId);

            // not a match director
            var shooterMatches = Scenario.ShooterMatches.Where(x => x.MatchId == existingMatch.Id).Select(x => x.ShooterId).ToList();

            var shooterIds = Scenario.Shooters.Where(x =>
                                                     shooterAssociations.Contains(x.Id) && !shooterMatches.Contains(x.Id) && !existingShooterSo.Contains(x.Id)).Select(x => x.Id).ToList();

            if (shooterIds.Count < 0)
            {
                Assert.Inconclusive("Shooters not found");
            }

            //Composizione della request
            var request = new StageRequest()
            {
                StageId = existingStage.Id
            };

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

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

            Assert.IsTrue(parsed != null &&
                          shooterIds.All(s => parsed.Data.Any(x => x.ShooterId == s))
                          );
            Assert.AreEqual(shooterIds.Count, parsed.Data.Count);
        }
        public Task <IActionResult> GetStage(StageRequest request)
        {
            var entity = BasicLayer.GetStage(request.StageId);

            //verifico validità dell'entità
            if (entity == null)
            {
                return(Task.FromResult <IActionResult>(NotFound()));
            }

            //Serializzazione e conferma
            return(Reply(ContractUtils.GenerateContract(entity)));
        }
Beispiel #10
0
        public async Task <ActionResult> Edit(string id, StageRequest stageRequest)
        {
            try
            {
                await _eventManagerApi.UpdateStageOfAnEventAsync(TempData.Peek("EventId").ToString(), id, stageRequest);

                return(RedirectToAction(nameof(Index), "Stage", new { id = TempData.Peek("EventId").ToString() }));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #11
0
        public Stage Create(StageRequest element, string eventId)
        {
            Stage stage = new Stage
            {
                StageId = Guid.NewGuid().ToString(),
                Name    = element.Name,
                EventId = eventId
            };

            _botEventManagementContext.Stages.Add(stage);
            _botEventManagementContext.SaveChanges();

            return(stage);
        }
Beispiel #12
0
        public void Add_CreateStage(string stageName)
        {
            var context      = GetInMemoryUserService();
            var eventContext = GetInMemoryEventService();

            var createdEvent = eventContext.Create(_eventRequest, string.Empty);

            var stageRequest = new StageRequest
            {
                Name = stageName
            };

            var createdStage = context.Create(stageRequest, createdEvent.EventId);
            var foundStage   = context.GetById(createdStage.StageId, createdEvent.EventId);

            Assert.Equal(stageName, foundStage.Name);
            Assert.Equal(createdEvent.EventId, createdStage.EventId);
        }
Beispiel #13
0
        public void Delete_RemoveStage(string stageName)
        {
            var context      = GetInMemoryUserService();
            var eventContext = GetInMemoryEventService();

            var createdEvent = eventContext.Create(_eventRequest, string.Empty);

            var stageRequest = new StageRequest
            {
                Name = stageName
            };

            var createdStage = context.Create(stageRequest, createdEvent.EventId);

            context.Delete(createdEvent.EventId, createdStage.StageId);

            var foundStage = context.GetById(createdStage.StageId, createdEvent.EventId);

            Assert.Null(foundStage);
        }
Beispiel #14
0
        public void Get_GetTwoCreatedStages(string firstStageName, string secondStageName)
        {
            var context      = GetInMemoryUserService();
            var eventContext = GetInMemoryEventService();

            var createdEvent = eventContext.Create(_eventRequest, string.Empty);

            var stageRequest = new StageRequest
            {
                Name = firstStageName
            };

            context.Create(stageRequest, createdEvent.EventId);

            stageRequest.Name = secondStageName;

            context.Create(stageRequest, createdEvent.EventId);

            var stages = context.GetAll(createdEvent.EventId);

            Assert.Equal(2, stages.Count);
        }
        public Task <IActionResult> DeleteStage(StageRequest request)
        {
            //Recupero l'elemento dal business layer
            var entity = BasicLayer.GetStage(request.StageId);

            //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo
            if (entity == null)
            {
                return(Task.FromResult <IActionResult>(NotFound()));
            }

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

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

            //Return contract
            return(Reply(ContractUtils.GenerateContract(entity)));
        }
        public IActionResult Put([FromHeader] string eventId, [FromRoute] string stageId, [FromBody] StageRequest stageRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (stageId != stageRequest.StageId)
            {
                return(BadRequest("This id doesn't corresponde with object"));
            }

            _stageService.Update(stageRequest, eventId);
            return(NoContent());
        }
        public static byte[] GenerateStageOne(StageRequest request)
        {
            var tmpPath = CreateTempDirectory();
            var compilerRequest = new Compiler.CompilationRequest
            {
                AssemblyName = "AgentStage",
                OutputKind = OutputKind.DynamicallyLinkedLibrary,
                Platform = Platform.AnyCpu,
                ReferenceDirectory = request.TargetFramework == TargetFramework.Net35 ? ReferencesDirectory + Path.DirectorySeparatorChar + "net35" : ReferencesDirectory + Path.DirectorySeparatorChar + "net40",
                TargetDotNetVersion = (Compiler.DotNetVersion)request.TargetFramework,
                SourceDirectory = tmpPath,
                References = new List<Compiler.Reference>
                {
                    new Compiler.Reference
                    {
                        File = "mscorlib.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.Core.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.Net.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.IO.Pipes.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.XML.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.Runtime.Serialization.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    },
                    new Compiler.Reference
                    {
                        File = "System.Management.Automation.dll",
                        Framework = (Compiler.DotNetVersion)request.TargetFramework,
                        Enabled = true
                    }
                }
            };
            
            CloneStageOneSourceCode(tmpPath);

            return Compiler.Compile(compilerRequest);
        }