コード例 #1
0
        public async Task DeleteItemCorrect()
        {
            //Arrange
            var  cls   = new InMemoryAppDbContext();
            Item item1 = new Item {
                Id = 2, SprintId = 1, AssignedUserId = "2138b181-4cee-4b85-9f16-18df308f387d", Name = "Item Name1", Description = "Description Item1", StatusId = 1, TypeId = 1, IsArchived = false, ParentId = 1, StoryPoint = 2
            };

            using (var context = cls.GetEmptyContextInMemory())
            {
                IItemRepository repo = new ItemRepository(context);
                context.Items.Add(item1);
                context.SaveChanges();
                var added = context.Items.Find(item1.Id);

                await repo.DeleteAsync(item1.Id);

                var searched = await repo.ReadAsync(item1.Id);

                //Assert
                Assert.NotNull(added);
                Assert.Null(searched);
                context.Database.EnsureDeleted();
            }
        }
コード例 #2
0
        public void CreateAsync_ShouldCreateManySprints(int id, int projectId)
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            var context = cls.GetContextWithData();

            try
            {
                ISprintRepository repository = new SprintRepository(context);
                Sprint            sprint     = new Sprint {
                    Id = id, ProjectId = projectId, StartDate = new DateTime(2020, 4, 23), EndDate = new DateTime(2020, 5, 23)
                };
                //Act
                repository.CreateAsync(sprint);
                var actual = context.Sprints.Find(id);
                //Assert
                Assert.Equal(sprint.Id, actual.Id);
                Assert.Equal(sprint.ProjectId, actual.ProjectId);
                Assert.Equal(sprint.StartDate, actual.StartDate);
                Assert.Equal(sprint.EndDate, actual.EndDate);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #3
0
        public void UpdateAsync_Should_Work()
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            int id      = 1;
            var context = cls.GetContextWithData();

            try
            {
                context.Database.EnsureDeleted();
                IProjectRepository repository = new ProjectRepository(context);
                Project            project    = context.Projects.Find(id);
                //Act
                project.Name        = "Updated name";
                project.Description = "Updated description";

                repository.UpdateAsync(project);
                Project actual = context.Projects.Find(id);

                //Assert

                Assert.NotNull(actual);
                Assert.Equal("Updated name", actual.Name);
                Assert.Equal("Updated description", actual.Description);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #4
0
        public void UpdateAsync_ShouldUpdateSprint()
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            var context = cls.GetContextWithData();

            try
            {
                ISprintRepository repository = new SprintRepository(context);
                Sprint            sprint     = context.Sprints.Find(1);
                sprint.ProjectId = 2;
                //Act
                repository.UpdateAsync(sprint);
                var actual = context.Sprints.Find(1);
                //Assert
                Assert.Equal(sprint.Id, actual.Id);
                Assert.NotEqual(1, actual.ProjectId);
                Assert.Equal(sprint.ProjectId, actual.ProjectId);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #5
0
        public void CreateAsyncWithParameters(int id, int sprintId, string assignedUserId, string name, string description, int statudId, int typeId)
        {
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetEmptyContextInMemory())
            {
                IItemRepository repository = new ItemRepository(context);
                Item            item       = new Item
                {
                    Id             = id,
                    SprintId       = sprintId,
                    AssignedUserId = assignedUserId,
                    Name           = name,
                    Description    = description,
                    StatusId       = statudId,
                    TypeId         = typeId
                };

                repository.CreateAsync(item);
                var actual = context.Items.Find(id);

                Assert.NotNull(actual);
                Assert.Equal(item.Id, actual.Id);
                context.Database.EnsureDeleted();
            }
        }
コード例 #6
0
        public void CreateAsync_ShouldWork(int id, int projectId)
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            var context = cls.GetContextWithData();

            try
            {
                ISprintRepository repository = new SprintRepository(context);
                //Act
                Sprint sprint = new Sprint {
                    Id = id, ProjectId = projectId
                };
                repository.CreateAsync(sprint);
                var actual = context.Sprints.Find(id);
                //Assert
                Assert.NotNull(actual);
                Assert.Equal(sprint.Id, actual.Id);
                Assert.Equal(sprint.ProjectId, actual.ProjectId);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #7
0
        public void GetByIdAsync_Sprint_ShouldWork_WhithCorrectId()
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            var context = cls.GetContextWithData();

            try
            {
                ISprintRepository repository = new SprintRepository(context);
                //Act
                Sprint expected  = context.Sprints.Find(1);
                Sprint actual    = repository.GetByIdAsync(1).Result;
                Sprint expected2 = context.Sprints.Find(2);
                Sprint actual2   = repository.GetByIdAsync(2).Result;
                //Assert
                Assert.Equal(expected, actual);
                Assert.Equal(expected2, actual2);

                Assert.Equal(expected.Id, actual.Id);
                Assert.Equal(expected.ProjectId, actual.ProjectId);
                Assert.Equal(expected.StartDate, actual.StartDate);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #8
0
        public void CreateAsync_ShouldWork(string name, string description)
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            var context = cls.GetContextWithData();

            try
            {
                IProjectRepository repository = new ProjectRepository(context);
                Project            newProject = new Project {
                    Name = name, Description = description
                };
                //Act
                repository.CreateAsync(newProject);
                Project actual = context.Projects.Find(newProject.Id);

                //Assert
                Assert.NotNull(actual);
                Assert.Equal(newProject.Name, actual.Name);
                Assert.Equal(newProject.Description, actual.Description);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #9
0
        private AppDbContext GetContext()
        {
            var context = InMemoryAppDbContext.GetEmptyUniqueAppDbContext();

            context.Avatars.Add(new AvatarInDb {
                Avatar = new byte[100], UserId = "421cb65f-a76d-4a73-8a1a-d792f37ef992"
            });


            context.SaveChanges();
            return(context);
        }
コード例 #10
0
        public async Task Check_DeleteNotExistRelationThrowsException(int firstId, int secondId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo          = new ItemRelationRepository(context);
                ItemRelation            startRelation = context.ItemsRelations.Find(firstId, secondId);
                startRelation.FirstItemId -= 100;
                await Assert.ThrowsAsync <InvalidOperationException>(() => repo.DeleteRecordAsync(startRelation));

                context.Database.EnsureDeleted();
            }
        }
コード例 #11
0
        public async Task UpdateAsyncNotCorrectItemAsync()
        {
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repo    = new ItemRepository(context);
                Item            item2   = context.Items.FirstOrDefault();
                string          oldName = item2.Name;
                item2.Id = -2;
                await Assert.ThrowsAsync <InvalidOperationException>(() => repo.UpdateAsync(item2));

                context.Database.EnsureDeleted();
            }
        }
コード例 #12
0
        public async Task Check_GetNotExistRecordReturnsNull(int firstId, int secondId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo             = new ItemRelationRepository(context);
                ItemRelation            expectedRelation = context.ItemsRelations.Find(firstId, secondId);
                ItemRelation            actualRelation   = await repo.GetRecordAsync(firstId, secondId);

                Assert.Null(actualRelation);
                Assert.Equal(expectedRelation, actualRelation);
                context.Database.EnsureDeleted();
            }
        }
コード例 #13
0
        public async Task Check_DeleteNotExistCommentThrowsException()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                Comment existComment = context.Comments.FirstOrDefault();

                await Assert.ThrowsAsync <ArgumentNullException>(() => repository.DeleteAsync(existComment.Id - 100));

                context.Database.EnsureDeleted();
            }
        }
コード例 #14
0
        private AppDbContext GetContext()
        {
            var context = InMemoryAppDbContext.GetEmptyUniqueAppDbContext();

            User user1 = new User {
                Id = "2138b181-4cee-4b85-9f16-18df308f387d", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Bart", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };
            User user2 = new User {
                Id = "2514591e-29f0-4a63-b0ad-87a3e7ebec3d", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Lisa", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };
            User user3 = new User {
                Id = "421cb65f-a76d-4a73-8a1a-d792f37ef992", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Homer", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };
            User user4 = new User {
                Id = "54bfd1f9-d379-4930-9c3b-4c84992c028e", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Marge", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };


            Project project1 = new Project {
                Id = 1, Name = "First Project", Description = "Some description to Project1"
            };
            Project project2 = new Project {
                Id = 2, Name = "Second Project", Description = "Some description to Project2"
            };


            ProjectUser pu1 = new ProjectUser {
                UserId = "2138b181-4cee-4b85-9f16-18df308f387d", ProjectId = 1, UserRoleId = AppUserRole.Owner.Id
            };
            ProjectUser pu2 = new ProjectUser {
                UserId = "2138b181-4cee-4b85-9f16-18df308f387d", ProjectId = 2, UserRoleId = AppUserRole.ScrumMaster.Id
            };
            ProjectUser pu3 = new ProjectUser {
                UserId = "2514591e-29f0-4a63-b0ad-87a3e7ebec3d", ProjectId = 2, UserRoleId = AppUserRole.Owner.Id
            };
            ProjectUser pu4 = new ProjectUser {
                UserId = "421cb65f-a76d-4a73-8a1a-d792f37ef992", ProjectId = 1, UserRoleId = AppUserRole.Developer.Id
            };

            context.Users.AddRange(new[] { user1, user2, user3, user4 });
            context.Projects.AddRange(new[] { project1, project2 });
            context.ProjectUsers.AddRange(new[] { pu1, pu2, pu3, pu4 });

            context.SaveChanges();
            return(context);
        }
コード例 #15
0
        public async Task Check_UpdateNotCorrectCommentThrowsException()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                Comment commentNew = context.Comments.FirstOrDefault();
                commentNew.Id = -2;
                //Assert
                await Assert.ThrowsAsync <InvalidOperationException>(() => repository.UpdateAsync(commentNew));

                context.Database.EnsureDeleted();
            }
        }
コード例 #16
0
        public void GetAllAsyncDefault()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repository = new ItemRepository(context);
                //Act
                List <Item>        expected = context.Items.ToList();
                IEnumerable <Item> actual   = repository.GetAllAsync().Result;
                //Assert
                Assert.True(actual != null);
                Assert.Equal(expected.Count, actual.ToList().Count);
                Assert.Equal(expected.Count, context.Items.ToList().Count);
                context.Database.EnsureDeleted();
            }
        }
コード例 #17
0
        public async Task UpdateAsyncCorrectItemAsync()
        {
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repo    = new ItemRepository(context);
                Item            item2   = context.Items.FirstOrDefault();
                string          oldName = item2.Name;
                item2.Name += "1111";
                await repo.UpdateAsync(item2);

                Item updatedItem = context.Items.Find(item2.Id);

                Assert.NotEqual(updatedItem.Name, oldName);
                context.Database.EnsureDeleted();
            }
        }
コード例 #18
0
        public async Task Check_ReadNotExistCommentReturnNull(int commentId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                var expected = await context.Comments.Where(r => r.Id == commentId).FirstOrDefaultAsync();

                Comment actual = await repository.ReadAsync(commentId);

                //Assert
                Assert.Null(actual);
                Assert.Equal(expected, actual);
                context.Database.EnsureDeleted();
            }
        }
コード例 #19
0
        public async Task GetByItemIdReturnsCorrect(int itemId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                List <Comment> expected = await context.Comments.Where(r => r.ItemId == itemId).ToListAsync();

                IEnumerable <Comment> actual = await repository.GetByItemIdAsync(itemId);

                //Assert
                Assert.True(actual != null);
                Assert.Equal(expected.Count, actual.ToList().Count);
                context.Database.EnsureDeleted();
            }
        }
コード例 #20
0
        public async Task Check_GetRelatedItemsReturnEmptyCollection(int itemId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo = new ItemRelationRepository(context);
                var expected = await context.ItemsRelations
                               .Where(r => r.FirstItemId == itemId || r.SecondItemId == itemId)
                               .ToListAsync();

                var actual = await repo.GetRelatedItems(itemId);

                Assert.Empty(actual);
                Assert.Equal(expected, actual);
                context.Database.EnsureDeleted();
            }
        }
コード例 #21
0
        public async Task Check_DeleteCommentIsCorrect()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                Comment existComment = context.Comments.FirstOrDefault();

                await repository.DeleteAsync(existComment.Id);

                var actual = context.Comments.Find(existComment.Id);
                //Assert
                Assert.NotNull(existComment);
                Assert.Null(actual);
                context.Database.EnsureDeleted();
            }
        }
コード例 #22
0
        public async void CreateAsyncDefault()
        {
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetEmptyContextInMemory())
            {
                IItemRepository repository = new ItemRepository(context);

                Item item = new Item {
                    Id = 5, SprintId = 1, AssignedUserId = "d7f1b614-bf60-4340-9daa-c8dce98fd400", Name = "Item Name5", Description = "Description Item1", StatusId = 1, TypeId = 1
                };
                await repository.CreateAsync(item);

                var actual = context.Items.Find(5);

                Assert.NotNull(actual);
                Assert.Equal(item.Id, actual.Id);
                context.Database.EnsureDeleted();
            }
        }
コード例 #23
0
        public void GetByIdAsync_Sprint_ShouldReturnNull_WithIncorrectID(int id)
        {
            //Arrange
            var cls     = new InMemoryAppDbContext();
            var context = cls.GetContextWithData();

            try
            {
                ISprintRepository repository = new SprintRepository(context);
                //Act
                Sprint actual = repository.GetByIdAsync(id).Result;
                //Assert
                Assert.Null(actual);
            }
            finally
            {
                context.Database.EnsureDeleted();
                context.Dispose();
            }
        }
コード例 #24
0
        public async Task Check_DeleteRelationWorkingRight(int firstId, int secondId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo          = new ItemRelationRepository(context);
                ItemRelation            startRelation = context.ItemsRelations.Find(firstId, secondId);

                await repo.DeleteRecordAsync(startRelation);

                var actualRelation = context.ItemsRelations.Find(firstId, secondId);

                Assert.NotNull(startRelation);
                Assert.Null(actualRelation);

                context.Database.EnsureDeleted();
            }
        }
コード例 #25
0
        public async Task GetBySprintIdNonCorrectAsync(int sprintId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repository = new ItemRepository(context);
                //Act
                List <Item>        expected = context.Items.Where(r => r.SprintId == sprintId).ToList();
                IEnumerable <Item> actual   = await repository.GetBySprintIdAsync(sprintId + 1);

                //Assert

                foreach (var item in actual)
                {
                    Assert.False(item.SprintId == sprintId);
                }
                context.Database.EnsureDeleted();
            }
        }
コード例 #26
0
        public async Task Check_UpdateCommentIsCorrect()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                Comment commentNew = context.Comments.FirstOrDefault();
                commentNew.Text = "NEW TEXT";
                await repository.UpdateAsync(commentNew);

                var actual = context.Comments.Find(commentNew.Id);
                //Assert
                Assert.NotNull(actual);
                Assert.Equal(commentNew, actual);
                Assert.Equal(commentNew.Text, actual.Text);
                context.Database.EnsureDeleted();
            }
        }
コード例 #27
0
        public async Task Check_CreateCommentIsCorrect()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                ICommentRepository repository = new CommentRepository(context);
                //Act
                Comment commentNew = new Comment {
                    Id = 10, ItemId = 1, Text = "Comment text10", UserId = "2138b181-4cee-4b85-9f16-18df308f387d", Date = DateTime.Today
                };
                await repository.CreateAsync(commentNew);

                var actual = context.Comments.Find(commentNew.Id);
                //Assert
                Assert.NotNull(actual);
                Assert.Equal(commentNew, actual);
                context.Database.EnsureDeleted();
            }
        }
コード例 #28
0
        public async Task ReadAsyncNotExistingItemDefault()
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repository = new ItemRepository(context);
                //Act
                Item expected = new Item {
                    Id = 1, SprintId = 1, AssignedUserId = "2138b181-4cee-4b85-9f16-18df308f387d", Name = "Item Name1", Description = "Description Item1", StatusId = 1, TypeId = 1, IsArchived = false, ParentId = 1, StoryPoint = 2
                };
                Item actual = await repository.ReadAsync(-2);

                //Assert

                Assert.Null(actual);
                Assert.Null(context.Items.FirstOrDefault(r => r.Id == -2));
                context.Database.EnsureDeleted();
            }
        }
コード例 #29
0
        public async Task GetChildWithSpecificStatusCorrect(int itemId, int statusId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repository = new ItemRepository(context);
                //Act
                List <Item>        expected = context.Items.Where(r => r.ParentId == itemId && r.StatusId == statusId && r.IsArchived == false).ToList();
                IEnumerable <Item> actual   = await repository.GetChildWithSpecificStatusAsync(itemId, statusId);

                //Assert

                foreach (var item in actual)
                {
                    Assert.True(item.ParentId == itemId && item.StatusId == statusId);
                }
                context.Database.EnsureDeleted();
            }
        }
コード例 #30
0
        public async Task GetAllChildsNotExistingItemAsync(int parentId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRepository repository = new ItemRepository(context);
                //Act
                List <Item>        expected = context.Items.Where(r => r.ParentId == parentId).ToList();
                IEnumerable <Item> actual   = await repository.GetAllChildAsync(parentId + 10);

                //Assert
                Assert.True(actual != null);
                foreach (var item in actual)
                {
                    Assert.True(item.ParentId != parentId);
                }
                context.Database.EnsureDeleted();
            }
        }