Exemple #1
0
        public void Create_Test()
        {
            ParentTask pTask = new ParentTask();

            pTask.ParentId = 1;
            pTask.TaskName = "ABCD";
            var ptasks = new List <ParentTask>();

            ptasks.Add(pTask);
            var t = ptasks.AsQueryable();
            //var mockSet = new Mock<DbSet<Task_Table>>();
            var mockSet = new Mock <DbSet <ParentTask> >();

            mockSet.As <IQueryable <ParentTask> >().Setup(m => m.Provider).Returns(t.Provider);
            mockSet.As <IQueryable <ParentTask> >().Setup(m => m.Expression).Returns(t.Expression);
            mockSet.As <IQueryable <ParentTask> >().Setup(m => m.ElementType).Returns(t.ElementType);
            mockSet.As <IQueryable <ParentTask> >().Setup(m => m.GetEnumerator()).Returns(t.GetEnumerator());


            var mockTaskMangerContext = new Mock <ProjectmanagerContext>();

            mockTaskMangerContext.Setup(c => c.ParentTasks).Returns(mockSet.Object);
            mockTaskMangerContext.Setup(c => c.Set <ParentTask>()).Returns(mockSet.Object);
            mockTaskMangerContext.Setup(p => p.SaveChanges());
            var objTestTaskrepo = new ProjectManagerRepository <ParentTask>(mockTaskMangerContext.Object);

            objTestTaskrepo.Create(pTask);
            Assert.AreEqual(mockSet.Object.ToList().Count, 1);
        }
        public async Task <IHttpActionResult> Create(ProjectManager projectManager)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (projectManager.User == null)
            {
                return(BadRequest("User can not be null"));
            }
            userRepository.Create(projectManager.User);
            projectManagerRepository.Create(projectManager);
            await db.SaveChangesAsync();

            return(Ok());
        }