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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
public void GetByIdAsync_Should_Fail_Whith_IncorrectId(int incorrectId) { //Arrange var cls = new InMemoryAppDbContext(); var context = cls.GetContextWithData(); try { IProjectRepository repository = new ProjectRepository(context); //Act Project expected = context.Projects.Find(incorrectId); Project actual = repository.GetByIdAsync(incorrectId).Result; //Assert Assert.Null(actual); Assert.Equal(expected, actual); } finally { context.Database.EnsureDeleted(); context.Dispose(); } }
public void GetAllByProjectIdAsync_Sprint_ShouldWork_WhithTheSameContext() { //Arrange var cls = new InMemoryAppDbContext(); var context = cls.GetContextWithData(); try { ISprintRepository repository = new SprintRepository(context); //Act List <Sprint> expected = context.Sprints.ToList(); IEnumerable <Sprint> actual = repository.GetAllByProjectIdAsync(1).Result; //Assert Assert.True(actual != null); Assert.Equal(expected.Count, actual.ToList().Count); Assert.Equal(expected, actual); } finally { context.Database.EnsureDeleted(); context.Dispose(); } }
public void GetAllAsync_Should_Returns_AllProjects() { //Arrange var cls = new InMemoryAppDbContext(); var context = cls.GetContextWithData(); try { IProjectRepository repository = new ProjectRepository(context); //Act List <Project> expected = context.Projects.ToList(); IEnumerable <Project> actual = repository.GetAllAsync().Result; //Assert Assert.True(actual != null); Assert.Equal(expected.Count, actual.ToList().Count); Assert.Equal(expected, actual); } finally { context.Database.EnsureDeleted(); context.Dispose(); } }
public void DeleteAsync_Should_Work() { //Arrange var cls = new InMemoryAppDbContext(); int id = 1; var context = cls.GetContextWithData(); try { IProjectRepository repository = new ProjectRepository(context); //Act repository.DeleteAsync(id); Project actual = context.Projects.Find(id); // Assert Assert.Null(actual); } finally { context.Database.EnsureDeleted(); context.Dispose(); } }