Ejemplo n.º 1
0
        public void GetTaskBoard_OnNonExistingTaskBoard_ReturnsNull()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext    dbContext  = new TestDatabaseContext(options);
            TaskBoardRepository repository = new TaskBoardRepository(dbContext);

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

            // ASSERT
            taskBoardPublic.Should().BeNull();
        }
Ejemplo n.º 2
0
        public void GetUserTaskBoards_OnRequestingUsersTaskBoard_ReturnsOnlyUsersTaskBoards()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext    dbContext  = new TestDatabaseContext(options);
            TaskBoardRepository repository = new TaskBoardRepository(dbContext);

            User user1 = dbContext.Users.Add(new User()
            {
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString()
            }).Entity;

            User user2 = dbContext.Users.Add(new User()
            {
                FirstName = Guid.NewGuid().ToString(),
                LastName  = Guid.NewGuid().ToString()
            }).Entity;

            dbContext.TaskBoards.Add(new TaskBoard()
            {
                Name = Guid.NewGuid().ToString(),
                User = user1
            });

            dbContext.TaskBoards.Add(new TaskBoard()
            {
                Name = Guid.NewGuid().ToString(),
                User = user1
            });

            dbContext.TaskBoards.Add(new TaskBoard()
            {
                Name = Guid.NewGuid().ToString(),
                User = user2
            });

            dbContext.SaveChanges();

            // ACT
            IEnumerable <TaskBoardPublic> boards = repository.GetUserTaskBoards(1);

            // ASSERT
            boards.Should().HaveCount(2);
        }
Ejemplo n.º 3
0
        public void CreateTaskBoard_OnValidObject_CreatesEntityInDatabase()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext    dbContext       = new TestDatabaseContext(options);
            TaskBoardRepository repository      = new TaskBoardRepository(dbContext);
            TaskBoardPublic     taskBoardPublic = new TaskBoardPublic()
            {
                Name   = Guid.NewGuid().ToString(),
                UserID = 1
            };

            // ACT
            TaskBoardPublic taskBoardCreated = repository.CreateTaskBoard(taskBoardPublic);

            // ID powinno się zwiększyć po tym jak entity framework stworzy encje w DB
            taskBoardPublic.ID = 1;

            // ASSERT
            taskBoardCreated.Should().BeEquivalentTo <TaskBoardPublic>(taskBoardPublic);
        }
Ejemplo n.º 4
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));
        }