コード例 #1
0
        public void Get()
        {
            Expression <Func <Customer, bool> >   predicate = x => true;
            Expression <Func <Customer, string> > selector  = x => x.Name;
            var options = new QueryOptions <Customer>();

            var mock = new Mock <IService <Customer> >();

            mock.Setup(x => x.Get(It.IsAny <Expression <Func <Customer, bool> > >()));
            mock.Setup(x => x.Get(It.IsAny <Expression <Func <Customer, bool> > >(), It.IsAny <Expression <Func <Customer, string> > >()));
            mock.Setup(x => x.Get(It.IsAny <IQueryOptions <Customer> >()));
            mock.Setup(x => x.Get(It.IsAny <IQueryOptions <Customer> >(), It.IsAny <Expression <Func <Customer, string> > >()));

            var readOnlyService = new ReadOnlyServiceWrapper <Customer, int>(mock.Object);

            readOnlyService.Get(predicate);
            readOnlyService.Get(predicate, selector);
            readOnlyService.Get(options);
            readOnlyService.Get(options, selector);

            mock.Verify(x => x.Get(predicate), Times.Once);
            mock.Verify(x => x.Get(predicate, selector), Times.Once);
            mock.Verify(x => x.Get(options), Times.Once);
            mock.Verify(x => x.Get(options, selector), Times.Once);
        }
コード例 #2
0
        public void GetWithId()
        {
            int key = 1;
            Expression <Func <Customer, bool> > predicate = x => true;
            var fetchStrategy = new FetchQueryStrategy <Customer>();
            Expression <Func <Customer, string> > selector = x => x.Name;

            var mock = new Mock <IService <Customer> >();

            mock.Setup(x => x.Get(It.IsAny <int>()));
            mock.Setup(x => x.Get(It.IsAny <int>(), It.IsAny <IFetchQueryStrategy <Customer> >()));
            mock.Setup(x => x.Get(It.IsAny <int>(), It.IsAny <string[]>()));
            mock.Setup(x => x.Get(It.IsAny <int>(), It.IsAny <Expression <Func <Customer, object> >[]>()));

            var readOnlyService = new ReadOnlyServiceWrapper <Customer, int>(mock.Object);

            readOnlyService.Get(key);
            readOnlyService.Get(key, fetchStrategy);
            readOnlyService.Get(key, string.Empty);
            readOnlyService.Get(key, (Expression <Func <Customer, object> >[])null);

            mock.Verify(x => x.Get(key), Times.Once);
            mock.Verify(x => x.Get(key, fetchStrategy), Times.Once);
            mock.Verify(x => x.Get(key, string.Empty), Times.Once);
            mock.Verify(x => x.Get(key, (Expression <Func <Customer, object> >[])null), Times.Once);
        }