public async void UpdatingProject_ShouldUpdateProjectInDb()
        {
            var db = UnitTestHelper.CreateInMemoryDb();

            await using (var context = db.CreateContext())
            {
                context.Projects.Add(DataSeeder.NewProject(3));
                await context.SaveChangesAsync();

                context.Projects.Should().HaveCount(1);

                var projectService = new ProjectService(context, UnitTestHelper.Mapper);
                var project        = DataSeeder.NewProject(3);
                project.Name = "updated project name";
                project.Code = "updated project code";
                await projectService.UpdateOrThrow(project);
            }

            await using (var context = db.CreateContext())
            {
                context.Projects.Should().HaveCount(1);
                context.Projects.Should().Contain(x =>
                                                  x.Name == "updated project name" &&
                                                  x.Code == "updated project code");
            }
        }
        public async void UpdatingTask_ShouldUpdateTaskInDb()
        {
            var db = UnitTestHelper.CreateInMemoryDb();

            await using (var context = db.CreateContext())
            {
                context.Tasks.Should().BeEmpty();

                context.Projects.Add(DataSeeder.NewProject(3));
                context.Tasks.Add(DataSeeder.NewTask(3, 3));

                var taskService = new TaskService(context, UnitTestHelper.Mapper);

                var task = DataSeeder.NewTask(3, 3);
                task.State       = ItemState.Completed;
                task.Name        = "updated name";
                task.Description = "updated description";

                await taskService.UpdateOrThrow(task);
            }

            await using (var context = db.CreateContext())
            {
                context.Tasks.Should().Contain(x =>
                                               x.Id == 3 &&
                                               x.State == ItemState.Completed &&
                                               x.Name == "updated name" &&
                                               x.Description == "updated description");
            }
        }
예제 #3
0
        public async Task Post_ProjectWithNotExistedParentProject_ShouldResultInBadRequest()
        {
            using var client = _factory.CreateClient();
            var response = await client.PostAsJsonAsync(Endpoints.PROJECTS, DataSeeder.NewProject(3, 33)).ConfigureAwait(false);

            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task GetFile()
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            var dts = new Mock <IDateTimeService>();

            dts.Setup(x => x.UtcNow).Returns(new DateTime(2020, 4, 20));

            var db = UnitTestHelper.CreateInMemoryDb();

            await using (var context = db.CreateContext())
            {
                var task = DataSeeder.NewTask(3, 3);
                task.StartDate = new DateTime(2020, 4, 20);
                task.State     = ItemState.InProgress;

                var project = DataSeeder.NewProject(3);
                project.State = ItemState.InProgress;

                context.Projects.Add(project);
                context.Projects.Add(DataSeeder.NewProject(6));
                context.Projects.Add(DataSeeder.NewProject(9));

                context.Tasks.Add(task);
                context.Tasks.Add(DataSeeder.NewTask(6, 6));
                context.Tasks.Add(DataSeeder.NewTask(9, 9));
                context.SaveChanges();
            }

            await using (var context = db.CreateContext())
            {
                var fileController = new ReportsController(dts.Object, new ReportGeneratorService(context, dts.Object));
                var file           =
                    await fileController.Get(new DateTime(2020, 4, 20, 3, 3, 3)) as FileContentResult;

                file.Should().NotBeNull();

                await using var stream = new MemoryStream(file !.FileContents);
                using var package      = new ExcelPackage(stream);

                package.Workbook.Worksheets.Count.Should().Be(1);
                var page = package.Workbook.Worksheets[0];
                page.Cells[ReportGeneratorService.START_ROW, ReportGeneratorService.START_COLUMN]
                .Text.Should()
                .Be("InProgress projects with tasks by 4/20/2020 3:03:03 AM. Report generated at 4/20/2020 12:00:00 AM");

                page.Dimension.Columns.Should().Be(6);
                page.Dimension.Rows.Should().Be(4);
            }
        }
예제 #5
0
        public async Task Post_TaskWithParentProjectTaskId_ThatPointToAnotherProject_ShouldResultInBadRequest()
        {
            using var client = _factory.CreateClient();
            await client.PostAsJsonAsync(Endpoints.PROJECTS, DataSeeder.NewProject(3)).ConfigureAwait(false);

            await client.PostAsJsonAsync(Endpoints.PROJECTS, DataSeeder.NewProject(9)).ConfigureAwait(false);

            await client.PostAsJsonAsync(Endpoints.TASKS, DataSeeder.NewTask(3, 3)).ConfigureAwait(false);

            await client.PostAsJsonAsync(Endpoints.TASKS, DataSeeder.NewTask(9, 9)).ConfigureAwait(false);

            var response = await client.PostAsJsonAsync(Endpoints.TASKS, DataSeeder.NewTask(6, 3, 9)).ConfigureAwait(false);

            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async void PostingProject_ShouldAddProjectToDb()
        {
            var db = UnitTestHelper.CreateInMemoryDb();

            await using (var context = db.CreateContext())
            {
                context.Projects.Should().BeEmpty();

                var projectService = new ProjectService(context, UnitTestHelper.Mapper);
                await projectService.Add(DataSeeder.NewProject(3));
            }

            await using (var context = db.CreateContext())
            {
                context.Projects.Should().HaveCount(1);
            }
        }
        public async void SettingTaskStateToComplete_AlsoSetsAllParentProjectsStatesToComplete_WhenAllProjectTasksComplete()
        {
            var db = UnitTestHelper.CreateInMemoryDb(); //ensure that we have same db in the scope of the test

            await using (var context = db.CreateContext())
            {
                //arrange
                var projectService = new ProjectService(context, UnitTestHelper.Mapper);
                await projectService.Add(DataSeeder.NewProject(3));

                await projectService.Add(DataSeeder.NewProject(6, 3));

                await projectService.Add(DataSeeder.NewProject(9, 6));

                var taskService = new TaskService(context, UnitTestHelper.Mapper);
                await taskService.Add(DataSeeder.NewTask(9, 9));

                await taskService.Add(DataSeeder.NewTask(3, 3));

                //act
                var task = DataSeeder.NewTask(9, 9);
                task.State = ItemState.Completed;
                await taskService.UpdateOrThrow(task);
            }

            //assert
            await using (var context = db.CreateContext())
            {
                var projectService = new ProjectService(context, UnitTestHelper.Mapper);

                var project = await projectService.GetOrThrow(9);

                project.State.Should().Be(ItemState.Completed);

                project = await projectService.GetOrThrow(6);

                project.State.Should().Be(ItemState.Completed);

                project = await projectService.GetOrThrow(3);

                project.State.Should().Be(ItemState.Planned);
            }
        }
        public async void DeletingProject_ShouldDeleteProjectFromDb()
        {
            var db = UnitTestHelper.CreateInMemoryDb();

            await using (var context = db.CreateContext())
            {
                context.Projects.Add(DataSeeder.NewProject(3));
                await context.SaveChangesAsync();

                context.Projects.Should().HaveCount(1);

                var projectService = new ProjectService(context, UnitTestHelper.Mapper);
                await projectService.DeleteOrThrow(3);
            }

            await using (var context = db.CreateContext())
            {
                context.Projects.Should().BeEmpty();
            }
        }
        public async void SettingTaskStateToInProgress_AlsoSetsAllParentProjectsStatesToInProgress()
        {
            //arrange
            var db = UnitTestHelper.CreateInMemoryDb(); //ensure that we have same db in the scope of test

            await using (var context = db.CreateContext())
            {
                var projectService = new ProjectService(context, UnitTestHelper.Mapper);
                await projectService.Add(DataSeeder.NewProject(3));

                await projectService.Add(DataSeeder.NewProject(6, 3));

                await projectService.Add(DataSeeder.NewProject(9, 6));

                var taskService = new TaskService(context, UnitTestHelper.Mapper);
                await taskService.Add(DataSeeder.NewTask(12, 9));

                //act
                var task = DataSeeder.NewTask(12, 9);
                task.State = ItemState.InProgress;
                await taskService.UpdateOrThrow(task);
            }

            //assert
            await using (var context = db.CreateContext())
            {
                var projectService = new ProjectService(context, UnitTestHelper.Mapper);

                var project = await projectService.GetOrThrow(9).ConfigureAwait(false);

                project.State.Should().Be(ItemState.InProgress);

                project = await projectService.GetOrThrow(6).ConfigureAwait(false);

                project.State.Should().Be(ItemState.InProgress);

                project = await projectService.GetOrThrow(3).ConfigureAwait(false);

                project.State.Should().Be(ItemState.InProgress);
            }
        }
        public async void DeletingTask_SetsSubtasksParentProjectTaskIdToNull()
        {
            var db = UnitTestHelper.CreateInMemoryDb(); //ensure that we have same db in the scope of the test

            await using (var context = db.CreateContext())
            {
                //arrange
                var projectService = new ProjectService(context, UnitTestHelper.Mapper);
                await projectService.Add(DataSeeder.NewProject(3));

                var taskService = new TaskService(context, UnitTestHelper.Mapper);
                await taskService.Add(DataSeeder.NewTask(3, 3));

                await taskService.Add(DataSeeder.NewTask(33, 3, 3));

                await taskService.Add(DataSeeder.NewTask(333, 3, 3));

                //act
                var task = DataSeeder.NewTask(3, 3);
                await taskService.DeleteOrThrow(task.Id);
            }

            //assert
            await using (var context = db.CreateContext())
            {
                var tasksService = new TaskService(context, UnitTestHelper.Mapper);

                var task = await tasksService.Get(33);

                task.ParentTaskId.Should().BeNull();

                task = await tasksService.Get(333);

                task.ParentTaskId.Should().BeNull();
            }
        }