public async Task GetAsync() { 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.GetAsync(It.IsAny <Expression <Func <Customer, bool> > >(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <Expression <Func <Customer, bool> > >(), It.IsAny <Expression <Func <Customer, string> > >(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <IQueryOptions <Customer> >(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <IQueryOptions <Customer> >(), It.IsAny <Expression <Func <Customer, string> > >(), It.IsAny <CancellationToken>())); var readOnlyService = new ReadOnlyServiceWrapper <Customer, int>(mock.Object); await readOnlyService.GetAsync(predicate); await readOnlyService.GetAsync(predicate, selector); await readOnlyService.GetAsync(options); await readOnlyService.GetAsync(options, selector); mock.Verify(x => x.GetAsync(predicate, default(CancellationToken)), Times.Once); mock.Verify(x => x.GetAsync(predicate, selector, default(CancellationToken)), Times.Once); mock.Verify(x => x.GetAsync(options, default(CancellationToken)), Times.Once); mock.Verify(x => x.GetAsync(options, selector, default(CancellationToken)), Times.Once); }
public async Task GetWithIdAsync() { 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.GetAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <IFetchQueryStrategy <Customer> >(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <string[]>(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <string[]>())); mock.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <Expression <Func <Customer, object> >[]>(), It.IsAny <CancellationToken>())); mock.Setup(x => x.GetAsync(It.IsAny <int>(), It.IsAny <Expression <Func <Customer, object> >[]>())); var readOnlyService = new ReadOnlyServiceWrapper <Customer, int>(mock.Object); await readOnlyService.GetAsync(key); await readOnlyService.GetAsync(key, fetchStrategy); await readOnlyService.GetAsync(key, new[] { string.Empty }, default(CancellationToken)); await readOnlyService.GetAsync(key, string.Empty); await readOnlyService.GetAsync(key, (Expression <Func <Customer, object> >[]) null); await readOnlyService.GetAsync(key, (Expression <Func <Customer, object> >[]) null, default(CancellationToken)); mock.Verify(x => x.GetAsync(key, default(CancellationToken)), Times.Once); mock.Verify(x => x.GetAsync(key, fetchStrategy, default(CancellationToken)), Times.Once); mock.Verify(x => x.GetAsync(key, new[] { string.Empty }, default(CancellationToken)), Times.Once); mock.Verify(x => x.GetAsync(key, string.Empty), Times.Once); mock.Verify(x => x.GetAsync(key, (Expression <Func <Customer, object> >[])null), Times.Once); mock.Verify(x => x.GetAsync(key, (Expression <Func <Customer, object> >[])null, default(CancellationToken)), Times.Once); }