コード例 #1
0
        public void CreateHomeAwayFixtureWrongFixtureTest()
        {
            //Arrange.
            FixtureModelIn input = new FixtureModelIn()
            {
                InitialDate       = DateTime.Today,
                RoundLength       = 1,
                DaysBetweenRounds = 7,
                FixtureName       = "ObligatorioDA2.BusinessLogic.FixtureAlgorithms.HomeAwayFixture"
            };

            matchesRepo.Setup(m => m.GetAll()).Returns(homeAwayMatchCollection);
            ICollection <string> errorMessagges = TeamAlreadyHasMatchErrorMessagges(GetEncounterDtos(homeAwayMatchCollection));


            //Act.
            IActionResult          result     = controller.CreateFixture(testSport.Name, input);
            BadRequestObjectResult badRequest = result as BadRequestObjectResult;
            ErrorModelOut          error      = badRequest.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(badRequest);
            Assert.AreEqual(400, badRequest.StatusCode);
            Assert.IsTrue(errorMessagges.Contains(error.ErrorMessage));
            logger.Verify(l => l.Log(LogType.FIXTURE, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once);
        }
コード例 #2
0
        public void CreateHomeAwayFixtureTest()
        {
            //Arrange.
            FixtureModelIn input = new FixtureModelIn()
            {
                InitialDate       = DateTime.Today,
                RoundLength       = 1,
                DaysBetweenRounds = 7,
                FixtureName       = "ObligatorioDA2.BusinessLogic.FixtureAlgorithms.HomeAwayFixture"
            };

            matchesRepo.Setup(m => m.GetAll()).Returns(new List <Encounter>());

            //Act.
            IActionResult result        = controller.CreateFixture(testSport.Name, input);
            CreatedResult createdResult = result as CreatedResult;
            ICollection <EncounterModelOut> modelOut = createdResult.Value as ICollection <EncounterModelOut>;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);
            Assert.AreEqual(modelOut.Count, homeAwayMatchCollection.Count);
            logger.Verify(l => l.Log(LogType.FIXTURE, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once);
        }
コード例 #3
0
 private FixtureDto BuildDto(FixtureModelIn modelIn)
 {
     return(new FixtureDto()
     {
         fixtureName = modelIn.FixtureName,
         initialDate = modelIn.InitialDate,
         daysBetweenRounds = modelIn.DaysBetweenRounds,
         roundLength = modelIn.RoundLength
     });
 }
コード例 #4
0
        private IActionResult TryCreate(FixtureModelIn input, string sportName)
        {
            IActionResult result;
            ICollection <EncounterDto>      added         = fixtureService.AddFixture(sportName);
            ICollection <EncounterModelOut> addedModelOut = new List <EncounterModelOut>();

            foreach (EncounterDto match in added)
            {
                addedModelOut.Add(factory.CreateModelOut(match));
            }
            result = Created("fixture-generator", addedModelOut);
            return(result);
        }
コード例 #5
0
        public IActionResult CreateFixture(string sportName, FixtureModelIn input)
        {
            IActionResult result;

            if (ModelState.IsValid)
            {
                result = TryCreateFixture(sportName, input);
            }
            else
            {
                //we call the function anyways, because we want the attempt to be logged.
                TryCreateFixture(sportName, input);
                result = BadRequest(ModelState);
            }
            return(result);
        }
コード例 #6
0
        private IActionResult TryCreateFixture(string sportName, FixtureModelIn input)
        {
            IActionResult result;

            try
            {
                SetSession();
                FixtureDto fixture = BuildDto(input);
                fixtureService.SetFixtureAlgorithm(fixture, fixtureConfig.Value.DllPath);
                result = TryCreate(input, sportName);
            }
            catch (ServiceException e)
            {
                result = errors.GenerateError(e);
            }
            return(result);
        }
コード例 #7
0
 public IActionResult CreateFixture(FixtureModelIn fixtureModelIn)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         CreateSession();
         var encounters = fixtureServices.CreateFixture(fixtureModelIn.CreationAlgorithmName, fixtureModelIn.SportName, fixtureModelIn.StartingDate);
         logger.Log(loginServices.LoggedUser.UserName, $"Created a fixture using the {fixtureModelIn.CreationAlgorithmName} generator");
         return(Ok(encounters));
     }
     catch (ServicesException e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #8
0
        public void CreateHomeAwayFixtureBadModelTest()
        {
            //Arrange.
            FixtureModelIn input = new FixtureModelIn()
            {
            };

            controller.ModelState.AddModelError("", "Error");

            //Act.
            IActionResult          result     = controller.CreateFixture(testSport.Name, input);
            BadRequestObjectResult badRequest = result as BadRequestObjectResult;
            ErrorModelOut          error      = badRequest.Value as ErrorModelOut;

            //Assert.
            Assert.IsNotNull(result);
            Assert.IsNotNull(badRequest);
            Assert.AreEqual(400, badRequest.StatusCode);
            logger.Verify(l => l.Log(LogType.FIXTURE, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once);
        }