public void CreateAnswerWorks()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("TechnicalndexRedirects")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                TechnicalController tc = new TechnicalController(context);

                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                Answer answer = new Answer();
                answer.Content = "testContent";
                answer.BQID    = 100;


                var x = tc.CreateAnswer(100);



                Assert.Equal("testContent", answer.Content);
            }
        }
        public void CreateAnswerRedirectsAsync()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("CreateAnswerRedirect")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                TechnicalController tc = new TechnicalController(context);

                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                Answer answer = new Answer();



                CreateAnswerViewModel cavm = new CreateAnswerViewModel();

                try
                {
                    var x = tc.CreateAnswer(cavm);
                }
                catch (Exception ex)
                {
                    Assert.True(ex is NullReferenceException);
                }
            }
        }
        public void HomeReturnsIActionResult()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("HomeIndexReturns")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                HomeController hc = new HomeController(context, Configuration);

                var x = hc.Index();


                Assert.IsAssignableFrom <IActionResult>(x);
            }
        }
예제 #4
0
        /// <summary>
        /// From the id of the TQ, find all answers associated with it and make it into a list of answers
        /// Find the TQ from the id from the API and deserialize
        /// </summary>
        /// <param name="id">ID of the TQ</param>
        /// <param name="context">DBContext</param>
        /// <returns>ViewModel</returns>
        public static async Task <OneTQViewModel> FromIDAsync(int?id, FunemploymentDbContext context)
        {
            OneTQViewModel oneTQView = new OneTQViewModel();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://funemploymentapi.azurewebsites.net");
                var response = client.GetAsync($"/api/technical/{id}").Result;
                if (response.EnsureSuccessStatusCode().IsSuccessStatusCode)
                {
                    var stringResult = await response.Content.ReadAsStringAsync();

                    oneTQView.technicalQuestion = JsonConvert.DeserializeObject <TechnicalQuestion>(stringResult);
                }
                oneTQView.Answers = await context.AnswerTable.Where(a => a.TQID == id).Select(s => s).ToListAsync();

                return(oneTQView);
            }
        }
        public void HomeIndexRedirectsWorks()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("HomeIndexRedirects")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                HomeController hc = new HomeController(context, Configuration);

                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                var x = hc.Index(player.Username);


                Assert.IsType <RedirectToActionResult>(x);
            }
        }
        public void ErrorReturnsIActionResult()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("ShowAllReturns")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                ProfileController pc = new ProfileController(context, Configuration);

                var x = pc.Error(player.ID);


                Assert.IsAssignableFrom <IActionResult>(x);
            }
        }
        public void PlayerAllAnswersReturnsIActionResult()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("AllResultsReturns")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                ProfileController pc = new ProfileController(context, Configuration);

                var x = pc.PlayerAllAnswers(player.ID);


                Assert.IsType <RedirectToActionResult>(x.Result);
            }
        }
        public void TechnicalGetONeWorks()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("TechnicalGetOne")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                TechnicalController tc = new TechnicalController(context);

                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                var x = tc.GetOneTQ(null);


                Assert.IsType <NoContentResult>(x.Result);
            }
        }
        public void ProfileControllerCanCreate()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("PCCreates")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                ProfileController pc = new ProfileController(context, Configuration);

                var x = pc.Create(player);

                var results = context.PlayerTable.Where(p => p.Username == "testUser");

                Assert.Equal(1, results.Count());
            }
        }
예제 #10
0
        public async System.Threading.Tasks.Task BehaviorIndexWorksAsync()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("BehaviorIndexRedirects")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                BehavioralController bc = new BehavioralController(context);

                Player player = new Player();
                player.Username = "******";
                player.Location = "testLocation";
                player.About    = "testAbout";

                var x = bc.Index();

                var y = await OneBQViewModel.FromIDAsync(1, context);

                Assert.NotEmpty(y.behaviorQuestion.Content);
                Assert.IsType <ViewResult>(x.Result);
            }
        }
        public async void DbCanSave()
        {
            DbContextOptions <FunemploymentDbContext> options = new DbContextOptionsBuilder <FunemploymentDbContext>()
                                                                .UseInMemoryDatabase("DbCanSave")
                                                                .Options;

            using (FunemploymentDbContext context = new FunemploymentDbContext(options))
            {
                Funemployment.Models.Player player = new Funemployment.Models.Player();
                player.Username = "******";
                player.Location = "testPlace";
                player.About    = "testAbout";

                await context.PlayerTable.AddAsync(player);

                await context.SaveChangesAsync();

                var results = context.PlayerTable.Where(person => person.Username == "testName");


                Assert.Equal(1, results.Count());
            }
        }
        public static async Task <PlayerAllAnswersViewModel> FromPlayerIDAsync(int id, FunemploymentDbContext context, List <Answer> bQanswers, List <Answer> tQanswer)
        {
            PlayerAllAnswersViewModel paavm = new PlayerAllAnswersViewModel();

            paavm.Player = await context.PlayerTable.FirstOrDefaultAsync(p => p.ID == id);

            paavm.BehaviorAnswers = bQanswers;

            //await context.AnswerTable.Where(a => a.PID == id && a.BQID != 0).Select(s => s).ToListAsync();

            paavm.TechnicalAnswers = tQanswer;

            List <BehaviorQuestion>  bqList = new List <BehaviorQuestion>();
            List <TechnicalQuestion> tqList = new List <TechnicalQuestion>();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://funemploymentapi.azurewebsites.net");

                foreach (var item in paavm.BehaviorAnswers)
                {
                    var response = client.GetAsync($"/api/behavior/{item.BQID}").Result;

                    if (response.EnsureSuccessStatusCode().IsSuccessStatusCode)
                    {
                        var stringResult = await response.Content.ReadAsStringAsync();

                        BehaviorQuestion bq = JsonConvert.DeserializeObject <BehaviorQuestion>(stringResult);
                        bqList.Add(bq);
                    }
                }
                var newBqlist = bqList.GroupBy(g => g.Content).Select(s => s.First());
                paavm.BehaviorQuestions = newBqlist.ToList();

                foreach (var item in paavm.TechnicalAnswers)
                {
                    var response = client.GetAsync($"/api/technical/{item.TQID}").Result;

                    if (response.EnsureSuccessStatusCode().IsSuccessStatusCode)
                    {
                        var stringResult = await response.Content.ReadAsStringAsync();

                        TechnicalQuestion tq = JsonConvert.DeserializeObject <TechnicalQuestion>(stringResult);
                        tqList.Add(tq);
                    }
                }
                var newTqlist = tqList.GroupBy(g => g.ProblemDomain).Select(s => s.First());
                paavm.TechnicalQuestions = newTqlist.ToList();
            }
            return(paavm);
        }
예제 #13
0
 public ProfileController(FunemploymentDbContext context, IConfiguration configuration)
 {
     _context      = context;
     Configuration = configuration;
 }
 public ProfileController(FunemploymentDbContext context)
 {
     _context = context;
 }
 public TechnicalController(FunemploymentDbContext context)
 {
     _context = context;
 }
 public BehavioralController(FunemploymentDbContext context)
 {
     _context = context;
 }
예제 #17
0
 public HomeController(FunemploymentDbContext context)
 {
     _context = context;
 }