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); }
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); }
private FixtureDto BuildDto(FixtureModelIn modelIn) { return(new FixtureDto() { fixtureName = modelIn.FixtureName, initialDate = modelIn.InitialDate, daysBetweenRounds = modelIn.DaysBetweenRounds, roundLength = modelIn.RoundLength }); }
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); }
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); }
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); }
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)); } }
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); }