예제 #1
0
        public async Task GetAthlete_ShouldReturnStatusCode400()
        {
            const string accessToken         = "hfhkfhajkfhasjkfsjkafkasjhf";
            var          mockedStravaService = new Mock <IStravaService>();
            var          ctrl = new AthleteController(mockedStravaService.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext
                    {
                        Items = new Dictionary <object, object> {
                            { "access_token", accessToken }
                        }
                    }
                }
            };

            mockedStravaService.Setup(e => e.GetAthlete(accessToken))
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.BadRequest)
            {
                Content = new StringContent("{\"message\": \"problem\", \"errors\":[ \"resource\": \"Athlete\",\"field\": \"access_token\",\"code\": \"invalid\"]}")
            }));

            var response = await ctrl.GetAthlete();

            var result = response as BadRequestResult;

            Assert.NotNull(result);
            Assert.True(result is BadRequestResult);
            Assert.Equal(StatusCodes.Status400BadRequest, result.StatusCode);
        }
예제 #2
0
        public async Task GetAthlete_ShouldReturn200StatusCode_And_AthleteObject()
        {
            const string accessToken         = "hfhkfhajkfhasjkfsjkafkasjhf";
            var          mockedStravaService = new Mock <IStravaService>();
            var          ctrl = new AthleteController(mockedStravaService.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext
                    {
                        Items = new Dictionary <object, object> {
                            { "access_token", accessToken }
                        }
                    }
                }
            };

            mockedStravaService.Setup(e => e.GetAthlete(accessToken))
            .Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"firstName\": \"Matt\"}")
            }));

            var response = await ctrl.GetAthlete();

            var result = response as OkObjectResult;

            Assert.NotNull(result);
            Assert.True(result is OkObjectResult);
            Assert.IsType <Athlete>(result.Value);
            Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
        }
 public void TestGetAthletesByMeetId()
 {
     AthleteController athleteController = new AthleteController();
     var athletesList = athleteController.GetAthletesByMeetId(2);
 }
 public void TestGetAthleteByAthleteId()
 {
     AthleteController athletesController = new AthleteController();
     var newAthlete = athletesController.GetAthleteByAthleteId(5);
 }
        public void TestGetAllAthletes()
        {
            AthleteController athletesController = new AthleteController();

            athletesController.GetAllAthletes();
        }
        // Add athlete results for specific event
        async Task AddAthleteResults(string filePath,
                                     int eventId,
                                     AthleteController athleteController,
                                     EntriesController entriesController,
                                     MarksController markController)
        {
            var entriesInfoList = entriesController.GetEntriesByEventId(eventId);
            List <ResultsEntry> entryResultsList = new List <ResultsEntry>();

            foreach (Entry item in entriesInfoList)
            {
                entryResultsList.Add(new ResultsEntry
                {
                    FlightPlace = item.FlightPlace.ToString(),
                    AthleteId   = item.AthleteID.ToString(),
                    // CompetePosition = item.CompetePosition.ToString(), This will has the potential to cause errors in the Field Lynx application
                    EventPlace  = string.Empty, // Not concerned about event place for mvp
                    LastName    = item.LastName,
                    FirstName   = item.FirstName,
                    Affiliation = item.TeamName,
                    Wind        = string.Empty // Not concerned about wind for mvp
                });

                // Add the marks to the entry result
                if (item.Marks.Count() > 0)
                {
                    StringBuilder marksString = new StringBuilder();

                    foreach (Mark markItem in item.Marks)
                    {
                        marksString.Append(String.Concat(markItem.mark, ","));
                    }

                    entryResultsList.Last().Mark = marksString.ToString();
                }
                else
                {
                    entryResultsList.Last().Mark = String.Empty;
                }
            }

            StringBuilder entryText = new StringBuilder();

            foreach (ResultsEntry item in entryResultsList)
            {
                // Adds the header to each file
                using (StreamWriter writer = new StreamWriter(filePath, true))
                {
                    entryText.Append(String.Concat(
                                         item.FlightPlace.ToString(), ",",
                                         item.AthleteId.ToString(), ",",
                                         String.Empty, ",", // This is where compete position would be
                                         item.EventPlace, ",",
                                         item.LastName, ",",
                                         item.FirstName, ",",
                                         item.Affiliation, ",",
                                         item.Mark,
                                         item.Wind, ",", Environment.NewLine));

                    await writer.WriteAsync(entryText.ToString());

                    entryText.Clear();
                    writer.Close();
                }
            }
        }
        public async void CreateAllResultsFiles(int meetId, string folderPath)
        {
            if (folderPath.Last() != '\\')
            {
                folderPath += "\\";
            }

            // Before building the results file delete all existing results files
            DeleteAllResultsFiles(folderPath, ".lff");

            EventsController  eventContoller    = new EventsController();
            AthleteController athleteController = new AthleteController();
            EntriesController entriesController = new EntriesController();
            MarksController   markController    = new MarksController();

            List <ResultsHeader> resultsHeader = new List <ResultsHeader>();

            var eventsList = eventContoller.GetEventsByMeetId(meetId);

            foreach (Event item in eventsList)
            {
                resultsHeader.Add(new ResultsHeader
                {
                    EventId           = item.EventId,
                    EventNum          = item.EventNum,
                    RoundNum          = item.FlightNum,
                    FlightNum         = item.FlightNum,
                    EventName         = item.EventName,
                    MeasurementSystem = item.MeasurementType
                });
            }

            StringBuilder headerText    = new StringBuilder();
            StringBuilder eventFileName = new StringBuilder();

            foreach (ResultsHeader item in resultsHeader)
            {
                // Build the file name for the event results file
                eventFileName.Append(
                    String.Concat(
                        folderPath,
                        item.EventNum.ToString().Length < 3 ? item.EventNum.ToString().PadLeft(3, '0') : item.EventNum.ToString(), "-",
                        item.RoundNum.ToString(), "-",
                        item.FlightNum.ToString(), ".lff"));

                // Adds the header to each file
                using (StreamWriter writer = new StreamWriter(eventFileName.ToString(), true))
                {
                    headerText.Append(String.Concat(
                                          item.EventNum.ToString(), ",",
                                          item.RoundNum.ToString(), ",",
                                          item.FlightNum.ToString(), ",",
                                          item.EventName, ",",
                                          item.MeasurementSystem, Environment.NewLine));

                    await writer.WriteAsync(headerText.ToString());

                    writer.Close();
                    headerText.Clear();
                }

                await AddAthleteResults(
                    eventFileName.ToString(),
                    item.EventId,
                    athleteController,
                    entriesController,
                    markController);

                // Clear the StringBuilder for the next file name
                eventFileName.Clear();
            }
        }
 public AthleteControllerTests()
 {
     mockAthleteService = new Mock <IAthleteService>();
     athleteController  = new AthleteController(mockAthleteService.Object);
 }
예제 #9
0
 public void Setup()
 {
     context    = TestUtils.GetMockContext();
     controller = new AthleteController(context);
     controller.ControllerContext.HttpContext = TestUtils.SetUserContext(context, 2);
 }