lundi 3 août 2015

Unit Tests and "source" parameter

I writing a unit test for:

public bool PassOrdersToProduction(List<int> ordersIds)
        {
            if(ordersIds == null)
            {
                return false;
            }

            this.db.ProductionOrders.Where(x => ordersIds.Contains(x.Id)).Update(x => new ProductionOrder
            {
                OrderState = OrderState.PassedToProduction,
                PassToProductionDate = DateTime.Now
            });

            try
            {
                this.db.SaveChanges();
            }
            catch (Exception e)
            {
                //TODO:Logging
                return false;
            }

            return true;
        }

And one of the tests that i wrote for this method is:

[Fact]
public void PassOrdersToProduction_SampleOrderIdsList_ReturnTrue()
{
     // arrange
     List<int> odersList = new List<int> { 1, 2, 3, 4 };    
     var productionOrders = new List<ProductionOrder>
          {
            new ProductionOrder { Id = 1 },
            new ProductionOrder {Id = 3 }
          }.AsQueryable();   
     this._context.Setup(m => m.ProductionOrders)
     .Returns(GetMockSetObject<ProductionOrder>(productionOrders));
     // act
     bool result = this._provider.PassOrdersToProduction(odersList);    
     // assert
     this._context.Verify(m => m.SaveChanges(null), Times.Once);
     Assert.NotNull(result);
     Assert.True(result);
 }

the problem is that the above test throws the following exception

"System.ArgumentException" - The query must be of type ObjectQuery or DbQuery. Nazwa parametru: source

Can anyone provide an explanation ?

Aucun commentaire:

Enregistrer un commentaire