コード例 #1
0
        public async Task <IActionResult> PostGenerate([FromBody] RoboFanGenerate generate, CancellationToken ct = default)
        {
            try
            {
                // ensure input values are valid
                _log.Information("PostGenerate: [{0}]", generate.Num);
                if ((generate.Num <= 0) || (generate.Num > 10))
                {
                    return(BadRequest());
                }

                // determine the robot image path and generate the requested number of fans
                var rootpath = _hostingEnvironment.WebRootPath;
                var robopath = System.IO.Path.Combine(rootpath, "images/robots");
                var listfans = await RoboFanGenerator.GenerateAsync(generate.Num, robopath, true);

                var status = await _roboFanRepository.AddManyAsync(listfans, ct);

                return(StatusCode(201, status));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
コード例 #2
0
        public void VerifyRoboFanTeamRankingsGenerator()
        {
            // generate list of teams and single robo fan
            var listfans = RoboFanGenerator.Generate(1, false, true);
            var robofan  = listfans[0];

            // generate and validate the fan team rankings
            Assert.NotNull(robofan.FanRankings);
            foreach (var ranking in robofan.FanRankings)
            {
                Assert.Equal(robofan.Id, ranking.RobotFanId);
                Assert.NotEqual(robofan.PrimaryTeamId, ranking.LeagueTeamId);
                Assert.NotEqual(0, ranking.Ranking);
            }
        }
コード例 #3
0
        public async Task <IActionResult> PostCreate([FromBody] RoboFanCreate create, CancellationToken ct = default)
        {
            try
            {
                // determine the robot image path
                _log.Information("PostCreate: [{0} {1}]", create.FirstName, create.LastName);
                var rootpath = _hostingEnvironment.WebRootPath;
                var robopath = System.IO.Path.Combine(rootpath, "images/robots");

                // generate a random fan and overide values received from this post request
                // todo: look into setting up automapper?
                var listfans = await RoboFanGenerator.GenerateAsync(1, robopath, true);

                if (!string.IsNullOrEmpty(create.FirstName))
                {
                    listfans[0].FirstName = create.FirstName;
                }
                if (!string.IsNullOrEmpty(create.LastName))
                {
                    listfans[0].LastName = create.LastName;
                }
                if (!string.IsNullOrEmpty(create.Address))
                {
                    listfans[0].Address = create.Address;
                }
                if (!string.IsNullOrEmpty(create.City))
                {
                    listfans[0].City = create.City;
                }
                if (!string.IsNullOrEmpty(create.State))
                {
                    listfans[0].State = create.State;
                }

                // add the new fan to the databasse
                var status = await _roboFanRepository.AddManyAsync(listfans, ct);

                return(StatusCode(201, status));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
コード例 #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);
        }
コード例 #5
0
        public async void Seed(string path, int numfans = 3)
        {
            // ensure the database exists and is upto to date first
            _log.Information("Migrating database (if needed).");
            _ctx.Database.Migrate();

            // ensure we have at least one fan record
            var fanexist = await _ctx.RoboFan.AnyAsync();

            if (!fanexist)
            {
                // no fan records exist in the database
                // generate some new fans and save them using the repository
                _log.Information("Seeding database with [{0}] new fans.", numfans);
                var repository = new RoboFanRepository(_ctx);
                var listfans   = RoboFanGenerator.Generate(numfans, path, true);
                var status     = await repository.AddManyAsync(listfans);
            }
        }
コード例 #6
0
        public void VerifyRoboFanGenerator()
        {
            var listfans = RoboFanGenerator.Generate(1, false, false);

            Assert.NotNull(listfans);
            Assert.Single(listfans);

            var fan = listfans[0];

            Assert.NotEmpty(fan.FirstName);
            Assert.NotEmpty(fan.LastName);
            Assert.NotEmpty(fan.Address);
            Assert.NotEmpty(fan.City);
            Assert.NotEmpty(fan.State);
            Assert.NotNull(fan.BirthDate);
            Assert.NotNull(fan.PrimaryTeam);
            Assert.NotNull(fan.RoboFanImage);
            Assert.NotNull(fan.PrimaryTeamId);
            Assert.InRange <int>((int)fan.PrimaryTeamId, 1, 24);
        }