コード例 #1
0
        public async void GetAllSkillsOfAllEmployees_All_Skill_Of_2_Employees()
        {
            var query = new EmployeeSkillsController(context);

            var users = new string[] { "a1", "a2" };

            var result = await query.GetAllSkillsOfAllEmployees(users, 0);  // async

            var resultAsArray = result.Value.OrderBy(x => x.UserId).ThenBy(x => x.SkillsId).ToArray();

            Assert.Equal(8, resultAsArray.Length);
            Assert.Equal(1, resultAsArray[0].SkillsId);
            Assert.Equal(2, resultAsArray[1].SkillsId);
            Assert.Equal(3, resultAsArray[2].SkillsId);
            Assert.Equal(7, resultAsArray[3].SkillsId);
            Assert.Equal(2, resultAsArray[4].SkillsId);
            Assert.Equal(4, resultAsArray[5].SkillsId);
            Assert.Equal(5, resultAsArray[6].SkillsId);
            Assert.Equal(6, resultAsArray[7].SkillsId);
            Assert.Equal("a1", resultAsArray[0].UserId);
            Assert.Equal("a1", resultAsArray[1].UserId);
            Assert.Equal("a1", resultAsArray[2].UserId);
            Assert.Equal("a1", resultAsArray[3].UserId);
            Assert.Equal("a2", resultAsArray[4].UserId);
            Assert.Equal("a2", resultAsArray[5].UserId);
            Assert.Equal("a2", resultAsArray[6].UserId);
            Assert.Equal("a2", resultAsArray[7].UserId);
        }
コード例 #2
0
        public async void UpdateEmployeeSkill_Put_Adjusted_Value_Of_EmployeeSkill_Already_Added()
        {
            var query = new EmployeeSkillsController(context);

            var newEmployeeSkill = new EmployeeSkills {
                Id = 9, SkillsId = 1, Experience = 2, UserId = "a1"
            };

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

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

            var added = await query.GetEmployeeSkillById(9);                  // async

            Assert.NotEqual(newEmployeeSkill.SkillsId, added.Value.SkillsId); // skill already in db therefore cannot update
            Assert.Equal(7, added.Value.SkillsId);                            // what is was before trying to update
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Contains("already added to this employee", badRequestResult.Value.ToString());
            Assert.Equal(400, badRequestResult.StatusCode);
            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #3
0
        public async void DeleteEmployeeSkills_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var result = await query.DeleteEmployeeSkills(3);  // async

            Assert.IsType <ActionResult <EmployeeSkills> >(result);
        }
コード例 #4
0
        public async void GetEmployeeSkillById_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var result = await query.GetEmployeeSkillById(5);  // async

            Assert.IsType <ActionResult <EmployeeSkillsToReturn> >(result);
        }
コード例 #5
0
        public async void GetEmployeeSkills_All_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var result = await query.GetEmployeeSkills();  // async

            Assert.IsType <ActionResult <IEnumerable <EmployeeSkills> > >(result);
        }
コード例 #6
0
        public async void Check_All_Received()
        {
            var query = new EmployeeSkillsController(context);

            var result = await query.GetEmployeeSkills();  // async

            Assert.Equal(9, result.Value.ToList().Count);
            Assert.Equal(9, result.Value.Count());
        }
コード例 #7
0
        public async void GetAllSkillsOfAllEmployees_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var users = new string[] { "a1", "a2" };

            var result = await query.GetAllSkillsOfAllEmployees(users, 2);   // async

            Assert.IsType <ActionResult <IEnumerable <EmployeeSkillsToReturn> > >(result);
        }
コード例 #8
0
        public async void GetAllEmployeeSkills_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var userId = "a1";

            var result = await query.GetAllEmployeeSkills(userId);  // async

            Assert.IsType <ActionResult <IEnumerable <EmployeeSkillsToReturn> > >(result);
        }
コード例 #9
0
        public async void DeleteEmployeeSkills_Delete_Id_5()
        {
            var query = new EmployeeSkillsController(context);

            var result = await query.DeleteEmployeeSkills(5);  // async

            Assert.Equal(2, result.Value.SkillsId);
            Assert.Equal(3, result.Value.Experience);
            Assert.Equal("a2", result.Value.UserId);
            Assert.Equal(5, result.Value.Id);
        }
コード例 #10
0
        public async void PostEmployeeSkill_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var newEmployeeSkill = new EmployeeSkills {
                Id = 10, SkillsId = 2, Experience = 3, UserId = "a3"
            };

            var result = await query.PostEmployeeSkills(newEmployeeSkill);  // async

            Assert.IsType <ActionResult <EmployeeSkills> >(result);
            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
コード例 #11
0
        public async void GetAllSkillsOfAllEmployees_One_Skill()
        {
            var query = new EmployeeSkillsController(context);

            var users = new string[] { "a1", "a2" };

            var result = await query.GetAllSkillsOfAllEmployees(users, 2);  // async

            Assert.Equal(2, result.Value.Count());
            Assert.Equal(2, result.Value.First(x => x.UserId == "a1").SkillsId);
            Assert.Equal(2, result.Value.First(x => x.UserId == "a1").Experience);
            Assert.Equal("a1", result.Value.First(x => x.UserId == "a1").UserId);
            Assert.Equal(2, result.Value.First(x => x.UserId == "a2").SkillsId);
            Assert.Equal(3, result.Value.First(x => x.UserId == "a2").Experience);
            Assert.Equal("a2", result.Value.First(x => x.UserId == "a2").UserId);
        }
コード例 #12
0
        public async void GetAllEmployeeSkills()
        {
            var query = new EmployeeSkillsController(context);

            var userId = "a1";

            var result = await query.GetAllEmployeeSkills(userId);  // async

            var resultAsArray = result.Value.OrderBy(x => x.SkillsId).ToArray();

            Assert.Equal(4, resultAsArray.Length);
            Assert.Equal(1, resultAsArray[0].SkillsId);
            Assert.Equal(2, resultAsArray[1].SkillsId);
            Assert.Equal(3, resultAsArray[2].SkillsId);
            Assert.Equal(7, resultAsArray[3].SkillsId);
        }
コード例 #13
0
        public async void UpdateEmployeeSkill_Put()
        {
            var query = new EmployeeSkillsController(context);

            var newEmployeeSkill = new EmployeeSkills {
                Id = 9, SkillsId = 7, Experience = 1, UserId = "a1"
            };

            var newEmployeeSkillToReturn = new EmployeeSkillsToReturn
            {
                Id         = 9,
                SkillsId   = 7,
                Experience = 1,
                UserId     = "a1",
                Skills     = new Skills {
                    Id = 7, Name = "ASP.NET Core", Type = 2
                },
                UserInfo = new UserInfo {
                    Id = "a1", UserName = "******", FirstName = "Sarah", LastName = "West", Email = "*****@*****.**"
                }
            };

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

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

            var added = await query.GetEmployeeSkillById(9);                 // async

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

            Assert.Equal(newEmployeeSkill.Id, added.Value.Id);
            Assert.Equal(newEmployeeSkill.SkillsId, added.Value.SkillsId);
            Assert.Equal(newEmployeeSkill.Experience, added.Value.Experience);
            Assert.Equal(newEmployeeSkill.UserId, added.Value.UserId);
            Assert.Equal(Newtonsoft.Json.JsonConvert.SerializeObject(newEmployeeSkillToReturn), Newtonsoft.Json.JsonConvert.SerializeObject(addedGoodRequest));
            //Assert.Equal(newEmployeeSkillToReturn, addedGoodRequest);
            // not sure why the objects aren't considered to be the same
            //Assert.Equal(newEmployeeSkill, result); // No Content returned so can't check it without changing return value
        }
コード例 #14
0
        public async void UpdateEmployeeSkills_Returns_OK()
        {
            var query = new EmployeeSkillsController(context);

            var newEmployeeSkill = new EmployeeSkills {
                Id = 9, SkillsId = 7, Experience = 1, UserId = "a1"
            };

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

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

            Assert.IsType <NoContentResult>(result);
        }
コード例 #15
0
        public async void PostExployeeSkills_Add_EmployeeSkill_Already_Added()
        {
            var query = new EmployeeSkillsController(context);

            var newEmployeeSkill = new EmployeeSkills {
                Id = 10, SkillsId = 1, Experience = 3, UserId = "a3"
            };

            var result = await query.PostEmployeeSkills(newEmployeeSkill); // async

            var added = await query.GetEmployeeSkillById(10);              // async

            Assert.Null(added.Value);
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result.Result);

            Assert.Contains("already added to this employee", badRequestResult.Value.ToString());
            Assert.Equal(400, badRequestResult.StatusCode);
            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
コード例 #16
0
        public async void GetEmployeeSkillById()
        {
            var query = new EmployeeSkillsController(context);

            var result = await query.GetEmployeeSkillById(5);  // async

            var skill5 = new EmployeeSkillsToReturn {
                Id       = 5, SkillsId = 2, Experience = 3, UserId = "a2",
                UserInfo = new UserInfo {
                    Id = "a2", UserName = "******", FirstName = "John", LastName = "Doe", Email = "*****@*****.**", IsManager = null
                },
                Skills = new Skills {
                    Id = 2, Name = "Javascript", Type = 1
                }
            };

            Assert.Equal(2, result.Value.SkillsId);
            Assert.Equal(3, result.Value.Experience);
            Assert.Equal("a2", result.Value.UserId);
            Assert.Equal(Newtonsoft.Json.JsonConvert.SerializeObject(skill5), Newtonsoft.Json.JsonConvert.SerializeObject(result.Value));
            // not sure why the objects aren't considered to be the same
        }
コード例 #17
0
        public async void PostExployeeSkills_Add()
        {
            var query = new EmployeeSkillsController(context);

            var newEmployeeSkill = new EmployeeSkills {
                Id = 10, SkillsId = 2, Experience = 3, UserId = "a3"
            };

            var newEmployeeSkillToReturn = new EmployeeSkillsToReturn
            {
                Id         = 10,
                SkillsId   = 2,
                Experience = 3,
                UserId     = "a3",
                Skills     = new Skills {
                    Id = 2, Name = "Javascript", Type = 1
                },
                UserInfo = new UserInfo {
                    Id = "a3", UserName = "******", FirstName = "Tim", LastName = "Wills", Email = "*****@*****.**", IsManager = null
                }
            };

            var result = await query.PostEmployeeSkills(newEmployeeSkill); // async

            var added = await query.GetEmployeeSkillById(10);              // async

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

            Assert.Equal(newEmployeeSkill.Id, added.Value.Id);
            Assert.Equal(newEmployeeSkill.SkillsId, added.Value.SkillsId);
            Assert.Equal(newEmployeeSkill.Experience, added.Value.Experience);
            Assert.Equal(newEmployeeSkill.UserId, added.Value.UserId);
            Assert.Equal(newEmployeeSkill, resultGoodRequest.Value);
            Assert.Equal(Newtonsoft.Json.JsonConvert.SerializeObject(newEmployeeSkillToReturn), Newtonsoft.Json.JsonConvert.SerializeObject(addedGoodRequest));
            //Assert.Equal(newEmployeeSkillToReturn, addedGoodRequest);
            // not sure why the objects aren't considered to be the same
        }