コード例 #1
0
        /// <inheritdoc/>
        public TaskBoardPublic UpdateTaskBoard(TaskBoardPublic taskBoard)
        {
            Ensure.ParamNotNull(taskBoard, nameof(taskBoard));

            TaskBoardConverter converter = new TaskBoardConverter(mDBContext);
            TaskBoardLogic     logic     = new TaskBoardLogic(mDBContext);

            TaskBoard createdTaskBoard = logic.UpdateTaskBoard(converter.Convert(taskBoard));

            mDBContext.SaveChanges();

            return(converter.Convert(createdTaskBoard));
        }
コード例 #2
0
        public void Convert_ConvertsNonExistingServiceModelToEntity_ReturnsConvertedEntity()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext   dbContext       = new TestDatabaseContext(options);
            TaskBoardConverter converter       = new TaskBoardConverter(dbContext);
            TaskBoardPublic    taskBoardPublic = new TaskBoardPublic()
            {
                ID     = 1,
                Name   = "Test",
                UserID = 1
            };

            // ACT
            TaskBoard taskBoard = converter.Convert(taskBoardPublic);

            // ASSERT
            taskBoard.Should().BeEquivalentTo <TaskBoard>(new TaskBoard()
            {
                ID = 0, Name = "Test", UserID = 1
            });
            taskBoard.User.Should().BeNull();
        }
コード例 #3
0
        /// <inheritdoc/>
        public IEnumerable <TaskBoardPublic> GetUserTaskBoards(int ID)
        {
            List <TaskBoard>   taskBoards = mDBContext.TaskBoards.Where(tb => tb.User.ID == ID).ToList();
            TaskBoardConverter converter  = new TaskBoardConverter(mDBContext);

            foreach (TaskBoard taskBoard in taskBoards)
            {
                yield return(converter.Convert(taskBoard));
            }
        }
コード例 #4
0
        /// <inheritdoc/>
        public TaskBoardPublic GetTaskBoard(int ID)
        {
            TaskBoard taskBoard = mDBContext.TaskBoards.FirstOrDefault(tb => tb.ID == ID);

            // Taskboard o takim ID nie został znaleziony.
            if (taskBoard == null)
            {
                return(null);
            }

            TaskBoardConverter converter = new TaskBoardConverter(mDBContext);

            return(converter.Convert(taskBoard));
        }
コード例 #5
0
        public void GetTaskBoard_OnExistingTaskBoard_ReturnsTaskBoard()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext    dbContext  = new TestDatabaseContext(options);
            TaskBoardRepository repository = new TaskBoardRepository(dbContext);
            TaskBoardConverter  converter  = new TaskBoardConverter(dbContext);
            TaskBoard           taskBoard  = new TaskBoard()
            {
                Name = Guid.NewGuid().ToString(),
            };

            dbContext.TaskBoards.Add(taskBoard);

            dbContext.SaveChanges();

            // ACT
            TaskBoardPublic taskBoardPublic = repository.GetTaskBoard(1);

            // ASSERT
            taskBoardPublic.Should().BeEquivalentTo <TaskBoardPublic>(converter.Convert(taskBoard));
        }