Exemplo n.º 1
0
        public async void TestReturnSkills()
        {
            var options = new DbContextOptionsBuilder <Databasecontext
                                                       >().UseInMemoryDatabase(databaseName: "Test1")
                          .Options;

            using (var context = new Databasecontext(options))
            {
                var skill = new Skill()
                {
                    SkillId     = 1,
                    SkillName   = "test",
                    Description = "test"
                };
                context.Add(skill);
                context.SaveChanges();
                SkillsController Skills = new SkillsController(context);

                var skills = await Skills.GetSkills();

                IEnumerable <Skill> result = skills.Value;
                Assert.Equal("test", result.Last().Description);
                Assert.Single(result);
            }
        }
Exemplo n.º 2
0
        public async void UpdateSkill_Put()
        {
            var query = new SkillsController(context);

            var newSkill = new Skills {
                Id = 3, Name = "ASP.NET Framework", Type = 2
            };

            // https://stackoverflow.com/questions/36856073/the-instance-of-entity-type-cannot-be-tracked-because-another-instance-of-this-t/42475617
            var local = context.Skills.Local.Where(t => t.Id == 3).FirstOrDefault();

            if (local != null)
            {
                context.Entry(local).State = EntityState.Detached; // only needed for xUnit testing
            }
            var result = await query.PutSkills(3, newSkill);       // async

            var added = await query.GetSkills(3);                  // async

            var addedGoodRequest = Assert.IsType <Skills>(added.Value);

            Assert.Equal(newSkill.Name, added.Value.Name);
            Assert.Equal(newSkill, added.Value);
            Assert.Equal(newSkill, addedGoodRequest);
            //Assert.Equal(newSkill, result); // No Content returned so can't check it without changing return value
        }
Exemplo n.º 3
0
        public void Benchmark_FetchSkill(BenchmarkContext context)
        {
            _skillFetchCounter = context.GetCounter("SkillFetchCounter");
            var postResponse = _skillController.GetSkills();

            _skillFetchCounter.Increment();
        }
Exemplo n.º 4
0
        public async void GetSkills_Returns_OK()
        {
            var query = new SkillsController(context);

            var result = await query.GetSkills(2);  // async

            Assert.IsType <ActionResult <Skills> >(result);
        }
Exemplo n.º 5
0
        public async void GetSkills_Get_Id_2()
        {
            var query = new SkillsController(context);

            var result = await query.GetSkills(2);  // async

            Assert.Equal("Javascript", result.Value.Name);
        }
Exemplo n.º 6
0
        public async void GetAllSkills_Returns_OK()
        {
            var    query  = new SkillsController(context);
            string sort   = "name";
            bool   asc    = true;
            var    result = await query.GetSkills(sort, asc); // async

            Assert.IsType <ActionResult <IEnumerable <Skills> > >(result);
        }
Exemplo n.º 7
0
        public async void GetAllSkills_Check_Order()
        {
            var    query  = new SkillsController(context);
            string sort   = "name";
            bool   asc    = true;
            var    result = await query.GetSkills(sort, asc); // async

            Assert.Equal("Angular", result.Value.First().Name);
            Assert.Equal("Javascript", result.Value.Last().Name);
        }
Exemplo n.º 8
0
        public async void Check_All_Received()
        {
            var    query  = new SkillsController(context);
            string sort   = "name";
            bool   asc    = true;
            var    result = await query.GetSkills(sort, asc); // async

            Assert.Equal(5, result.Value.ToList().Count);
            Assert.Equal(5, result.Value.Count());
        }
Exemplo n.º 9
0
        public async void PostSkills_Add()
        {
            var query = new SkillsController(context);

            var newSkill = new Skills {
                Id = 6, Name = "React", Type = 2
            };

            var result = await query.PostSkills(newSkill); // async

            var added = await query.GetSkills(6);          // async

            var resultGoodRequest = Assert.IsType <CreatedAtActionResult>(result.Result);
            var addedGoodRequest  = Assert.IsType <Skills>(added.Value);

            Assert.Equal(newSkill, added.Value);
            Assert.Equal(newSkill, resultGoodRequest.Value);
            Assert.Equal(newSkill, addedGoodRequest);
        }
        public void GetSkillsTest()
        {
            var skillsList = skillsController.GetSkills();

            Assert.IsNotNull(skillsList);
        }