Ejemplo n.º 1
0
 /// <summary>
 ///     Creates and sets up a DbQuery mock for the specified entity.
 /// </summary>
 /// <typeparam name="TDbContext">The DbContext type.</typeparam>
 /// <typeparam name="TQuery">The query type.</typeparam>
 /// <param name="dbContext">The DbContext.</param>
 /// <param name="sequence">The sequence to use for the DbQuery.</param>
 /// <returns></returns>
 public static Mock <DbQuery <TQuery> > CreateDbQueryMockFor <TDbContext, TQuery>(this TDbContext dbContext,
                                                                                  IEnumerable <TQuery> sequence)
     where TDbContext : DbContext
     where TQuery : class
 {
     return(DbQueryHelper.CreateDbQueryMock(sequence));
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Sets up a query for a DbContext mock.
        /// </summary>
        /// <typeparam name="TDbContext">The DbContext type.</typeparam>
        /// <typeparam name="TQuery">The query type.</typeparam>
        /// <param name="dbContextMock">The DbContext mock.</param>
        /// <param name="sequence">The sequence to use for the DbQuery.</param>
        /// <returns>The DbContext mock.</returns>
        public static Mock <TDbContext> SetUpDbQueryFor <TDbContext, TQuery>(this Mock <TDbContext> dbContextMock,
                                                                             IEnumerable <TQuery> sequence)
            where TDbContext : DbContext
            where TQuery : class
        {
            var dbQueryMock = DbQueryHelper.CreateDbQueryMock(sequence);

            dbContextMock.SetUpDbQueryFor(dbQueryMock);
            return(dbContextMock);
        }
        public void TestHappyPath()
        {
            XDocument doc =
                new XDocument(
                    new XElement("Result",
                                 new XElement("param1", "param1value"),
                                 new XElement("param2", "param2value"),
                                 new XElement("param3", "param3value")
                                 )
                    );

            var mock = new Mock <IDbQueryRepository>();

            mock.Setup(s => s.Query("SELECT * FROM Test", "Key")).Returns(doc);

            var helper = new DbQueryHelper(mock.Object);

            Assert.AreEqual("param1value", helper.Query("SELECT * FROM Test", "Key"));
        }
 /// <summary>
 ///     Adds the mock set up for a query.
 /// </summary>
 /// <typeparam name="TQuery">The query type.</typeparam>
 /// <param name="expression">The DbContext property to set up.</param>
 /// <param name="sequence">The sequence to use for operations on the query.</param>
 /// <returns>The DbContext mock builder.</returns>
 public DbContextMockBuilder <TDbContext> AddSetUpFor <TQuery>(Expression <Func <TDbContext, DbQuery <TQuery> > > expression, IEnumerable <TQuery> sequence) where TQuery : class
 {
     return(AddSetUpFor(expression, DbQueryHelper.CreateDbQueryMock(sequence)));
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Creates and sets up a DbQuery mock for the specified entity.
 /// </summary>
 /// <typeparam name="TQuery">The query type.</typeparam>
 /// <param name="dbQuery">The DbQuery to mock.</param>
 /// <param name="sequence">The sequence to use for the DbQuery.</param>
 /// <returns>A DbQuery mock for the specified entity.</returns>
 public static Mock <DbQuery <TQuery> > CreateDbQueryMock <TQuery>(this DbQuery <TQuery> dbQuery,
                                                                   IEnumerable <TQuery> sequence)
     where TQuery : class
 {
     return(DbQueryHelper.CreateDbQueryMock(sequence));
 }