コード例 #1
0
        public void get_by_id_test()
        {
            moqDbContext     = new Mock <DbContextEntities>();
            moqDbSetTranfert = new Mock <DbSet <Transfert> >();
            moqDbSetCompte   = new Mock <DbSet <Compte> >();

            moqDbSetTranfert.As <IQueryable <Transfert> >().Setup(m => m.Provider).Returns(transferts.AsQueryable().Provider);
            moqDbSetTranfert.As <IQueryable <Transfert> >().Setup(m => m.Expression).Returns(transferts.AsQueryable().Expression);
            moqDbSetTranfert.As <IQueryable <Transfert> >().Setup(m => m.ElementType).Returns(transferts.AsQueryable().ElementType);
            moqDbSetTranfert.As <IQueryable <Transfert> >().Setup(m => m.GetEnumerator()).Returns(() => transferts.AsQueryable().GetEnumerator());

            transfertRepository = new TransfertRepository(moqDbContext.Object, moqDbSetTranfert.Object, moqDbSetCompte.Object);

            Transfert resultat = transfertRepository.GetByID(1);

            Assert.AreEqual(resultat.designation, transferts.ElementAt(0).designation);
            Assert.AreEqual(resultat.id, transferts.ElementAt(0).id);
        }
コード例 #2
0
 public Models.Transfert GetTransfertById(int transfertId)
 {
     return(transfertRepository.GetByID(transfertId));
 }