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 HttpResponseMessage UpdateOrder(Order order)
 {
     return CreateResponseBuilder().WithCondition(() => UserIsAdmin)
         .WithMethod(() => _orderService.Update(order));
 }
        public void ToDoItemRepository_Update_ShouldReturnUpdatedEntity()
        {
            var list = new Order();
            var itemToChange = new ToDoItem()
            {
                Id = 1,
                DateAdded = DateTime.MinValue,
                DateCompletion = default(DateTime),
                IsCompleted = false,
                IsFavourited = false,
                List = list,
                Note = "note",
                Text = "text"
            };
            var dbData = new List<ToDoItem>()
            {
                itemToChange,
                new ToDoItem()
                {
                    Id = 2,
                    DateAdded = DateTime.MinValue,
                    DateCompletion = default(DateTime),
                    IsCompleted = false,
                    IsFavourited = false,
                    List = new Order(),
                    Note = "note",
                    Text = "text"
                },
                new ToDoItem()
                {
                    Id = 3,
                    DateAdded = DateTime.MinValue,
                    DateCompletion = default(DateTime),
                    IsCompleted = false,
                    IsFavourited = false,
                    List = new Order(),
                    Note = "note",
                    Text = "text"
                }
            }.AsQueryable();

            var newItem = new ToDoItem()
            {
                Id = 1,
                DateAdded = DateTime.MinValue,
                DateCompletion = default(DateTime),
                IsCompleted = false,
                IsFavourited = false,
                List = null,
                Note = "note1",
                Text = "text1"
            };
            var dbSetMock = new Mock<DbSet<ToDoItem>>();
            dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.Provider).Returns(dbData.Provider);
            dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.Expression).Returns(dbData.Expression);
            dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.ElementType).Returns(dbData.ElementType);
            dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator());
            var dbContextMock = new Mock<ApplicationDbContext>();
            dbContextMock.Setup(x => x.Set<ToDoItem>()).Returns(dbSetMock.Object);
            var repo = new ToDoItemRepository(dbContextMock.Object);
            var result = repo.Update(newItem);

            Assert.AreEqual(newItem.Text, result.Text);
            Assert.AreEqual(newItem.DateCompletion, result.DateCompletion);
            Assert.AreEqual(newItem.Note, result.Note);
            Assert.AreEqual(newItem.IsCompleted, result.IsCompleted);
            Assert.AreSame(result.List, list);
        }
 public HttpResponseMessage PostOrder(Order order)
 {
     return CreateResponseBuilder().WithMethod(() => _orderService.Create(order));
 }