public async Task UpdateToDoList() { ToDoListDto updatedToDoList = await _toDoListRepository.Update(new UpdateToDoListDto { ToDoListId = 2, Description = "sell phone", UserId = 1, LabelId = 1 }); Assert.IsNotNull(updatedToDoList); Assert.AreEqual("sell phone", updatedToDoList.Description); }
public void Save(ToDoListEntity toDoListEntity) { if (toDoListEntity.Id == 0) { _toDoListRepository.Insert(toDoListEntity); } else { _toDoListRepository.Update(toDoListEntity); } }
public async Task <ToDoListViewModel> Handle(UpdateToDoListDescriptionCommand request, CancellationToken cancellationToken) { Logger.LogInformation($"Received request to update description for To Do List {request.Id} to {request.Description}"); var toDoList = await ToDoListRepository.Get(request.Id); if (toDoList == null) { throw new NotFoundException(request.Id, typeof(ToDoList)); } toDoList.Description = request.Description; var response = await ToDoListRepository.Update(toDoList); return(new ToDoListViewModel(response)); }
public void ToDoListRepository_Update_ShouldReturnUpdatedEntity() { var listToChange = new Order() { Id = 1, Name = "name" }; var dbData = new List <Order>() { listToChange, new Order() { Id = 2, Name = "name" }, new Order() { Id = 3, Name = "name" } }.AsQueryable(); var newList = new Order() { Id = 1, Name = "nameChanged" }; var dbSetMock = new Mock <DbSet <Order> >(); dbSetMock.As <IQueryable <Order> >().Setup(x => x.Provider).Returns(dbData.Provider); dbSetMock.As <IQueryable <Order> >().Setup(x => x.Expression).Returns(dbData.Expression); dbSetMock.As <IQueryable <Order> >().Setup(x => x.ElementType).Returns(dbData.ElementType); dbSetMock.As <IQueryable <Order> >().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator()); var dbContextMock = new Mock <ApplicationDbContext>(); dbContextMock.Setup(x => x.Set <Order>()).Returns(dbSetMock.Object); var repo = new ToDoListRepository(dbContextMock.Object); var result = repo.Update(newList); Assert.AreEqual(newList.Name, result.Name); }
public void ToDoListRepository_Update_ShouldReturnUpdatedEntity() { var listToChange = new Order() { Id = 1, Name = "name" }; var dbData = new List<Order>() { listToChange, new Order() { Id = 2, Name ="name" }, new Order() { Id = 3, Name ="name" } }.AsQueryable(); var newList = new Order() { Id = 1, Name = "nameChanged" }; var dbSetMock = new Mock<DbSet<Order>>(); dbSetMock.As<IQueryable<Order>>().Setup(x => x.Provider).Returns(dbData.Provider); dbSetMock.As<IQueryable<Order>>().Setup(x => x.Expression).Returns(dbData.Expression); dbSetMock.As<IQueryable<Order>>().Setup(x => x.ElementType).Returns(dbData.ElementType); dbSetMock.As<IQueryable<Order>>().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator()); var dbContextMock = new Mock<ApplicationDbContext>(); dbContextMock.Setup(x => x.Set<Order>()).Returns(dbSetMock.Object); var repo = new ToDoListRepository(dbContextMock.Object); var result = repo.Update(newList); Assert.AreEqual(newList.Name, result.Name); }
public void Update(string toDoListTitle, ToDoList toDoList) { toDoListRep.Update(toDoListTitle, toDoList); }