Beispiel #1
0
        public async Task <IActionResult> Get(string namefilter = "", CancellationToken ct = default)
        {
            try
            {
                // fetch all the records
                // todo: support paging
                var listfans = await _roboFanRepository.GetAllFilterAsync(namefilter, ct);

                if (listfans == null)
                {
                    return(NotFound());
                }

                // determine the full host URL string
                var hostpath = string.Format("{0}://{1}", Request.Scheme, Request.Host.ToString());
                _log.Information("Get: HostPath[{0}]", hostpath);

                // convert records into the correct format for the client
                var listmodels = RoboFanConverter.ConvertList(listfans, hostpath);
                return(Ok(listmodels));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Beispiel #2
0
        public void ComputeAgeWhenSameMonthSameDay()
        {
            var currentdate = DateTime.Parse("07/15/2015");
            var birthdate   = DateTime.Parse("07/15/2000");
            var age         = RoboFanConverter.GetAge(birthdate, currentdate);

            Assert.Equal(15, age);
        }
Beispiel #3
0
        public void ComputeAgeWhenFutureMonth()
        {
            var currentdate = DateTime.Parse("07/01/2015");
            var birthdate   = DateTime.Parse("08/01/2000");
            var age         = RoboFanConverter.GetAge(birthdate, currentdate);

            Assert.Equal(14, age);
        }
Beispiel #4
0
        public void VerifyRoboFanConverter()
        {
            var listfans = RoboFanGenerator.Generate(1, false, true);
            var fan      = listfans[0];

            var model = RoboFanConverter.Convert(fan);

            Assert.Equal(fan.FirstName, model.FirstName);
            Assert.Equal(fan.LastName, model.LastName);
            Assert.Equal(fan.Address, model.Address);
            Assert.Equal(fan.City, model.City);
            Assert.Equal(fan.State, model.State);
            Assert.False(string.IsNullOrEmpty(model.ImageUrl));
            Assert.Equal(fan.PrimaryTeam.Name, model.TeamName);
            Assert.Equal(fan.PrimaryTeam.ImageUrl, model.TeamImageUrl);
            Assert.NotNull(model.PosTeams);
            Assert.NotNull(model.NegTeams);
            Assert.Equal(fan.FanRankings.Count, model.PosTeams.Count + model.NegTeams.Count);
        }
Beispiel #5
0
        public async Task <IActionResult> Get(int id, CancellationToken ct = default)
        {
            try
            {
                // get the specified record
                var robofan = await _roboFanRepository.GetByIdAsync(id, ct);

                if (robofan == null)
                {
                    return(NotFound());
                }

                // convert record into the correct format for the client
                var model = RoboFanConverter.Convert(robofan);
                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }