コード例 #1
0
        public void TestCanFailUpdateTQ()
        {
            DbContextOptions <FunemploymentDBContext> options =
                new DbContextOptionsBuilder <FunemploymentDBContext>()
                .UseInMemoryDatabase("TestCanFailUpdateTQ")
                .Options;

            using (FunemploymentDBContext context = new FunemploymentDBContext(options))
            {
                TechnicalQuestion TQ = new TechnicalQuestion();
                TQ.ID            = 1;
                TQ.ProblemDomain = "Problem Domain";
                TQ.Input         = "Input";
                TQ.Output        = "Output";
                TQ.Difficulty    = 7;

                TQController tc = new TQController(context);

                var test = tc.Create(TQ);

                TechnicalQuestion TQ2 = new TechnicalQuestion();
                TQ2.ProblemDomain = "no Domain";
                TQ2.Input         = "out";
                TQ2.Output        = "in";
                TQ2.Difficulty    = 7;

                var test2  = tc.Update(2, TQ2);
                var answer = test2.Result;

                Assert.IsType <CreatedAtRouteResult>(answer);
            }
        }
コード例 #2
0
        public void TestCanUpdateTQ()
        {
            DbContextOptions <FunemploymentDBContext> options =
                new DbContextOptionsBuilder <FunemploymentDBContext>()
                .UseInMemoryDatabase("TestCanUpdateTQ")
                .Options;

            using (FunemploymentDBContext context = new FunemploymentDBContext(options))
            {
                TechnicalQuestion TQ = new TechnicalQuestion();
                TQ.ID            = 1;
                TQ.ProblemDomain = "Problem Domain";
                TQ.Input         = "Input";
                TQ.Output        = "Output";
                TQ.Difficulty    = 7;

                TQController tc = new TQController(context);

                var test = tc.Create(TQ);

                TechnicalQuestion TQ2 = new TechnicalQuestion();
                TQ2.ProblemDomain = "no Domain";
                TQ2.Input         = "out";
                TQ2.Output        = "in";
                TQ2.Difficulty    = 7;

                var test2  = tc.Update(1, TQ2);
                var answer = test2.Result;

                var results = context.TechnicalQuestions.FirstOrDefault(a => a.ID == 1);

                Assert.Equal("no Domain", results.ProblemDomain);
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create([FromBody] TechnicalQuestion question)
        {
            await _context.TechnicalQuestions.AddAsync(question);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetTQ", new { id = question.ID }, question));
        }
コード例 #4
0
        public async Task <IActionResult> Update([FromRoute] int id, [FromBody] TechnicalQuestion question)
        {
            var tq = await _context.TechnicalQuestions.FindAsync(id);

            if (tq == null)
            {
                return(await Create(question));
            }

            tq.ProblemDomain = question.ProblemDomain;
            tq.Difficulty    = question.Difficulty;
            tq.Input         = question.Input;
            tq.Output        = question.Output;

            _context.TechnicalQuestions.Update(tq);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #5
0
        public async void DatabaseCanSave()
        {
            DbContextOptions <FunemploymentDBContext> options =
                new DbContextOptionsBuilder <FunemploymentDBContext>()
                .UseInMemoryDatabase("DBCanSave")
                .Options;

            using (FunemploymentDBContext context = new FunemploymentDBContext(options))
            {
                //arange
                TechnicalQuestion TQ = new TechnicalQuestion();
                TQ.ProblemDomain = "Problem domain";

                //act
                await context.TechnicalQuestions.AddAsync(TQ);

                await context.SaveChangesAsync();

                var results = context.TechnicalQuestions.Where(t => t.ProblemDomain == "Problem domain");

                Assert.Equal(1, results.Count());
            }
        }
コード例 #6
0
        public void TestCannotReadTQ()
        {
            DbContextOptions <FunemploymentDBContext> options =
                new DbContextOptionsBuilder <FunemploymentDBContext>()
                .UseInMemoryDatabase("TestCannotReadTQ")
                .Options;

            using (FunemploymentDBContext context = new FunemploymentDBContext(options))
            {
                TechnicalQuestion TQ = new TechnicalQuestion();
                TQ.ID            = 1;
                TQ.ProblemDomain = "Problem Domain";
                TQ.Input         = "Input";
                TQ.Output        = "Output";
                TQ.Difficulty    = 7;

                TQController tc = new TQController(context);

                var test  = tc.Create(TQ);
                var test2 = tc.GetByID(7).Result;

                Assert.IsType <NotFoundResult>(test2);
            }
        }
コード例 #7
0
        public void TestCanCreateTQ()
        {
            DbContextOptions <FunemploymentDBContext> options =
                new DbContextOptionsBuilder <FunemploymentDBContext>()
                .UseInMemoryDatabase("TestCanCreateTQ")
                .Options;

            using (FunemploymentDBContext context = new FunemploymentDBContext(options))
            {
                TechnicalQuestion TQ = new TechnicalQuestion();
                TQ.ProblemDomain = "Problem Domain";
                TQ.Input         = "Input";
                TQ.Output        = "Output";
                TQ.Difficulty    = 7;

                TQController tc = new TQController(context);

                var test = tc.Create(TQ);

                var results = context.TechnicalQuestions.Where(a => a.ProblemDomain == "Problem Domain");

                Assert.Equal(1, results.Count());
            }
        }