Exemple #1
0
        public void Index()
        {
            var controller = new CompetitionController();
            var result     = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
        }
Exemple #2
0
        public async void TestCreate()
        {
            //Arrange
            var c = new Competition
            {
                Id          = 1,
                Name        = "Vorhlaup",
                Description = "Um vorhlaupid",
                Email       = "*****@*****.**",
                Phone       = "5551234",
                Sponsor     = "",
                WebPage     = "vorhlaup.is"
            };
            var cMod = new CompetitionsViewModel
            {
                Name        = "Vorhlaup",
                Description = "Um vorhlaupid",
                Email       = "*****@*****.**",
                PhoneNumber = "5551234",
                Sponsor     = "",
                WebPage     = "vorhlaup.is"
            };
            var serviceMock = new Mock <ICompetitionService>();

            serviceMock.Setup(x => x.AddAsync(cMod)).Returns(Task.FromResult(c));
            var controller = new CompetitionController(serviceMock.Object);

            //Act
            var result = await controller.Create(cMod) as RedirectToActionResult;

            //Assert
            Assert.Equal(expected: "Competitions", actual: result.ActionName);
        }
Exemple #3
0
        public void GetTest()
        {
            var con      = new CompetitionController();
            var response = con.Get();

            Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
        }
Exemple #4
0
        public async void TestDetailsAsync()
        {
            //Arrange
            int competitionId = 1;
            var serviceMock   = new Mock <ICompetitionService>();

            serviceMock.Setup(x => x.GetCompetitionByIdAsync(1)).Returns(Task.FromResult(new Competition
            {
                Id          = 1,
                Name        = "Vorhlaup",
                Description = "Um vorhlaupid",
                Email       = "*****@*****.**",
                Phone       = "5551234",
                Sponsor     = "",
                WebPage     = "vorhlaup.is",
                Deleted     = false
            }));
            var controller = new CompetitionController(serviceMock.Object);

            //Act
            var result = await controller.Details(competitionId) as ViewResult;

            var data = (Competition)result.ViewData.Model;

            //Assert
            Assert.Equal(expected: "Vorhlaup", actual: data.Name);
        }
        public void CreateTestView()
        {
            var controller = new CompetitionController();
            var result     = controller.Create() as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
        }
        public void IndexTestView()
        {
            var controller = new CompetitionController();
            var result     = controller.Index("1", "1", "1", 10) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
        }
Exemple #7
0
        public static bool ShowStartWindow(CompetitionController aController)
        {
            CompetitionParamsPanel panel = aController.GetParametersPanel();
            fStartCompetition      form  = new fStartCompetition();

            form.AppendPanel(panel);
            bool result = form.ShowDialog() == DialogResult.OK;

            return(result);
        }
Exemple #8
0
 private void CreatePanels()
 {
     FCompetitionController           = CompetitionControllers.CompetitionControllers.GetController(FCompetition);
     pnlCompetition                   = FCompetitionController.GetControl();
     pnlCompetition.OnAfterMatchEdit += new EventHandler(OnAfterMatchEdit);
     if (pnlCompetition is SwissPanel)
     {
         (pnlCompetition as SwissPanel).OnNextRoundClick += new EventHandler(OnNextRound);
     }
     pnlCompetitionParams = FCompetitionController.GetParametersPanel();
     if (pnlCompetitionParams != null)
     {
         pnlCompetitionParams.ReadOnly = true;
     }
 }
Exemple #9
0
        public void CreateByPOST_WhenDoesNotReceiveANameForTheCompetition_AddNewCompetitionToRepositoryWithARandomName()
        {
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Create(new CreateCompetitionModel());

            Assert.AreEqual(1, competitionRepository.Count);
            var compCreated = competitionRepository[0];

            Assert.IsNotNull(compCreated.Name);
        }
Exemple #10
0
        public void Admin_WhenThereAreNoCompetitions_ReturnAnEmptyListOfCompetitions()
        {
            var controller = new CompetitionController();

            controller.CompetitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            var result = controller.Admin() as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as IList <Competition>;

            Assert.IsNotNull(model);
            Assert.AreEqual(0, model.Count);
        }
Exemple #11
0
        public void DeleteByPOST_WhenExecuteCorrectly_RemoveTheCompetitionFromTheRepository()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Delete(competition.Id, new FormCollection());

            Assert.IsFalse(competitionRepository.Contains(competition), "The competition should have been removed from the repository");
        }
        public async Task EnterCompetition_ReturnsStatus200()
        {
            // Arrange
            var expectedStatusCode = (int)HttpStatusCode.OK;
            var request            = _fixture.Create <EnterCompetition>();

            _mediatorMock.Setup(x => x.Send(request, default)).ReturnsAsync(new Unit());
            var controller = new CompetitionController(_mediatorMock.Object);

            // Act
            var response = await controller.EnterCompetition(request);

            var actualResponse = (OkObjectResult)response;

            // Assert
            actualResponse.StatusCode.Should().Be(expectedStatusCode);
        }
        public async Task EnterCompetition_MediatorSendsCorrectInput()
        {
            // Arrange
            var request             = _fixture.Create <EnterCompetition>();
            EnterCompetition actual = null;

            _mediatorMock.Setup(x => x.Send(request, default))
            .Callback((IRequest <Unit> req, CancellationToken token) => actual = req as EnterCompetition)
            .ReturnsAsync(new Unit());
            var controller = new CompetitionController(_mediatorMock.Object);

            // Act
            var response = await controller.EnterCompetition(request);

            // Assert
            actual.Should().Be(request);
        }
Exemple #14
0
        public void FixturesAndResults_ReturnsWithAViewResult_WithAListOfLeagues()
        {
            // Arrange
            var serviceMock = new Mock <ILeagueService>();
            var hostingMock = new Mock <IHostingEnvironment>();

            serviceMock.Setup(x => x.GetAll(hostingMock.Object.WebRootPath)).Returns(GetTestLeagues());
            var controller = new CompetitionController(serviceMock.Object, hostingMock.Object);

            // Act
            var result = controller.FixturesAndResults();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <League> >(viewResult.ViewData.Model);

            Assert.Equal(3, model.Count());
        }
Exemple #15
0
        public void Delete_LoadTheCompetitionOnTheViewModel()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id);

            var result = actionResult as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(competition, result.Model);
        }
 public void OneTimeSetUp()
 {
     _data = new Dictionary <string, object> {
         { "Authorization", _token }
     };
     _competitionController = new CompetitionController
     {
         Configuration = new HttpConfiguration(),
         Request       = new HttpRequestMessage(HttpMethod.Get, "http://localhost:9000/")
     };
     _context    = new OwinContext(_data);
     _authHeader = new AuthenticationHeaderValue(_token);
     _competitionController.Request.SetOwinContext(_context);
     _competitionController.Request.GetOwinContext().Request.RemoteIpAddress = _ip;
     _competitionController.Request.Headers.Authorization = _authHeader;
     _competitionManager =
         SingletonManager.Instance.SetCompetitionManager(Substitute.For <ICompetitionManager>());
     SingletonManager.Instance.SetTokenManager(new TokenManager());
 }
Exemple #17
0
        public void CreateByPOST_WhenExecuteCorrectly_AddNewCompetitionToRepository()
        {
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };
            var createCompetitionModel = new CreateCompetitionModel();

            createCompetitionModel.Name = "name";

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Create(createCompetitionModel);

            Assert.AreEqual(1, competitionRepository.Count);
            var compCreated = competitionRepository[0];

            Assert.AreEqual(createCompetitionModel.Name, compCreated.Name);
        }
        public async Task GetSubmissions_HasNoSubmissions_Produces200()
        {
            // Arrange
            var expectedStatusCode = (int)HttpStatusCode.OK;
            var request            = new GetSubmissions {
                Page = 1
            };
            var mediatorResponse = new GetSubmissionsResponse(request.Page, 1);

            _mediatorMock.Setup(x => x.Send(request, default)).ReturnsAsync(mediatorResponse);
            var controller = new CompetitionController(_mediatorMock.Object);

            // Act
            var response = await controller.GetSubmissions(request);

            var actualResponse = response as OkObjectResult;

            // Assert
            actualResponse.StatusCode.Should().Be(expectedStatusCode);
        }
Exemple #19
0
        public void CreateByPOST_WhenExecuteCorrectly_RedirectToDetailsOfTheNewCompetition()
        {
            var createCompetitionModel = new CreateCompetitionModel();

            createCompetitionModel.Name = "competitionName";

            var controller = new CompetitionController();

            controller.CompetitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };
            var actionResult = controller.Create(createCompetitionModel);

            var redirectToRouteResult = actionResult as RedirectToRouteResult;

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Details", redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual(createCompetitionModel.Name, redirectToRouteResult.RouteValues["id"]);
            Assert.AreEqual("The competition was successfully created. Now you can add participants and checkpoints to your competition.", controller.TempData["InformationMessage"]);
        }
Exemple #20
0
        public void Admin_WhenExistsAtLeastACompetition_ShowListOfExistentCompetitions()
        {
            var competition = new Competition();
            var compRep     = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            compRep.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = compRep;
            var result = controller.Admin() as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as IList <Competition>;

            Assert.IsNotNull(model);
            Assert.IsTrue(model.Contains(competition));
        }
Exemple #21
0
        public void Details_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();

            competition.Name = "testingCompetition";
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Details(competition.Name);

            var result = actionResult as ViewResult;

            Assert.AreEqual(competition, result.Model);
        }
Exemple #22
0
        public void DeleteByPOST_WhenExecuteCorrectly_RedirectToIndex()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id, new FormCollection());

            var redirectToRouteResult = actionResult as RedirectToRouteResult;

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Admin", redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual("The competition was deleted.", controller.TempData["InformationMessage"]);
        }
Exemple #23
0
        public void TestGetAllCompetitions()
        {
            //Arrange
            var serviceMock = new Mock <ICompetitionService>();

            serviceMock.Setup(x => x.GetAllCompetitions()).Returns(() => new List <Competition>()
            {
                new Competition {
                    Id          = 1,
                    Name        = "Vorhlaup",
                    Description = "Um vorhlaupid",
                    Email       = "*****@*****.**",
                    Phone       = "5551234",
                    Sponsor     = "",
                    WebPage     = "vorhlaup.is",
                    Deleted     = false
                },
                new Competition {
                    Id          = 2,
                    Name        = "Hausthlaup",
                    Description = "Um hausthlaupid",
                    Email       = "*****@*****.**",
                    Phone       = "5551234",
                    Sponsor     = "",
                    WebPage     = "hausthlaup.is",
                    Deleted     = false
                }
            });
            var controller = new CompetitionController(serviceMock.Object);

            /*
             * //Act
             * var result = controller.Index() as ViewResult;
             * var data = (List<Competition>)result.ViewData.Model;
             *
             * //Assert
             * Assert.IsType<ViewResult>(result);
             * Assert.Equal(expected: "Hausthlaup", actual: data[1].Name);
             * Assert.Equal(expected: 2, actual: data.Count);
             */
        }
Exemple #24
0
 public CompetitionControllerTest()
 {
     _mockFacade = new Mock <ICompetitionFacade>();
     _controller = new CompetitionController(_mockFacade.Object);
 }
 public void Setup()
 {
     context    = TestUtils.GetMockContext();
     controller = new CompetitionController(context);
     controller.ControllerContext.HttpContext = TestUtils.SetUserContext(context, 2);
 }