Esempio n. 1
0
        public async Task DeleteTask()
        {
            var options = new DbContextOptionsBuilder <Models.ProjectManagerDBContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectManagerDB")
                          .Options;

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                context.Tasks.Add(new Models.Task()
                {
                    ID          = 256,
                    Priority    = 3,
                    TaskgroupID = 9,
                    Name        = "originalname",
                    Description = "originaldesc",
                    Deadline    = new System.DateTime(2020, 12, 09, 18, 30, 52),
                });
                context.SaveChanges();
            }

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                var controller = new TaskController(context);

                var result = await controller.DeleteProject(256);

                result.Result.Should().BeOfType <Microsoft.AspNetCore.Mvc.OkObjectResult>();

                Assert.AreEqual(null, await context.Tasks.FindAsync(256));
            }
        }
Esempio n. 2
0
        public async Task UpdateTaskPriority()
        {
            var options = new DbContextOptionsBuilder <Models.ProjectManagerDBContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectManagerDB")
                          .Options;

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                context.Tasks.Add(new Models.Task()
                {
                    ID = 100, Priority = 3, TaskgroupID = 9
                });
                context.Tasks.Add(new Models.Task()
                {
                    ID = 101, Priority = 2, TaskgroupID = 9
                });
                context.SaveChanges();
            }

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                var controller = new TaskController(context);

                var result = await controller.UpdateTask(100, new Models.Task()
                {
                    ID = 100, Priority = 2, TaskgroupID = 9
                }) as Microsoft.AspNetCore.Mvc.NoContentResult;

                Assert.IsNotNull(result);
                Assert.AreEqual(204, result.StatusCode);

                Assert.AreEqual(2, (await context.Tasks.FindAsync(100)).Priority);
                Assert.AreEqual(3, (await context.Tasks.FindAsync(101)).Priority);
            }
        }
Esempio n. 3
0
        public async Task TryUpdateTaskWithWrongID()
        {
            var options = new DbContextOptionsBuilder <Models.ProjectManagerDBContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectManagerDB")
                          .Options;

            var task = new Models.Task()
            {
                ID = 76
            };

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                context.Tasks.Add(task);
                context.SaveChanges();
            }

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                var controller = new TaskController(context);

                var result = await controller.UpdateTask(72, task) as Microsoft.AspNetCore.Mvc.BadRequestResult;

                Assert.IsNotNull(result);
                Assert.AreEqual(400, result.StatusCode);
            }
        }
Esempio n. 4
0
        public async Task UpdateTaskData()
        {
            var options = new DbContextOptionsBuilder <Models.ProjectManagerDBContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectManagerDB")
                          .Options;

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                context.Tasks.Add(new Models.Task()
                {
                    ID          = 128,
                    Priority    = 3,
                    TaskgroupID = 9,
                    Name        = "originalname",
                    Description = "originaldesc",
                    Deadline    = new System.DateTime(2020, 12, 09, 18, 30, 52),
                });
                context.SaveChanges();
            }

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                var controller = new TaskController(context);

                var result = await controller.UpdateTask(128, new Models.Task()
                {
                    ID          = 128,
                    Priority    = 3,
                    TaskgroupID = 9,
                    Name        = "newname",
                    Description = "newdesc",
                    Deadline    = new System.DateTime(2020, 12, 09, 18, 50, 52),
                }) as Microsoft.AspNetCore.Mvc.NoContentResult;

                Assert.IsNotNull(result);
                Assert.AreEqual(204, result.StatusCode);

                var updatedTask = await context.Tasks.FindAsync(128);

                Assert.AreEqual("newname", updatedTask.Name);
                Assert.AreEqual("newdesc", updatedTask.Description);
                Assert.AreEqual(new System.DateTime(2020, 12, 09, 18, 50, 52), updatedTask.Deadline);
            }
        }
Esempio n. 5
0
        public async Task GetExistingTaskByID()
        {
            var options = new DbContextOptionsBuilder <Models.ProjectManagerDBContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectManagerDB")
                          .Options;

            var task = new Models.Task()
            {
                ID          = 42,
                TaskgroupID = 2,
                Name        = "test",
                Description = "teeeeest",
                Priority    = 1,
                Deadline    = new System.DateTime(2020, 11, 29, 18, 30, 52),
            };

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                context.Tasks.Add(task);
                context.SaveChanges();
            }

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                var controller = new TaskController(context);

                var result = await controller.GetTask(42);

                result.Result.Should().BeOfType <Microsoft.AspNetCore.Mvc.OkObjectResult>();

                var resultData = (Microsoft.AspNetCore.Mvc.OkObjectResult)result.Result;

                Assert.AreEqual(((Models.Task)resultData.Value).ID, task.ID);
                Assert.AreEqual(((Models.Task)resultData.Value).TaskgroupID, task.TaskgroupID);
                Assert.AreEqual(((Models.Task)resultData.Value).Name, task.Name);
                Assert.AreEqual(((Models.Task)resultData.Value).Description, task.Description);
                Assert.AreEqual(((Models.Task)resultData.Value).Priority, task.Priority);
                Assert.AreEqual(((Models.Task)resultData.Value).Deadline, task.Deadline);
            }
        }
Esempio n. 6
0
        public async Task GetTasksByTaskgroupID()
        {
            var options = new DbContextOptionsBuilder <Models.ProjectManagerDBContext>()
                          .UseInMemoryDatabase(databaseName: "ProjectManagerDB")
                          .Options;

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                context.Tasks.Add(new Models.Task()
                {
                    TaskgroupID = 5
                });
                context.Tasks.Add(new Models.Task()
                {
                    TaskgroupID = 3
                });
                context.Tasks.Add(new Models.Task()
                {
                    TaskgroupID = 5
                });
                context.SaveChanges();
            }

            using (var context = new Models.ProjectManagerDBContext(options))
            {
                var controller = new TaskController(context);

                var result = await controller.GetGroup(5);

                result.Result.Should().BeOfType <Microsoft.AspNetCore.Mvc.OkObjectResult>();

                var resultData = (Microsoft.AspNetCore.Mvc.OkObjectResult)result.Result;

                Assert.AreEqual(((List <Models.Task>)resultData.Value).Count, 2);
            }
        }