public async Task AddOrUpdate_callsFindAsyncAndReplaceOneAsync() { var record = new MongoRecord { Details = new Audit(TestCorrelationId, TestUser).Details }; MongoCollectionMock.Setup(x => x.FindAsync( It.IsAny <FilterDefinition <MongoRecord> >(), It.IsAny <FindOptions <MongoRecord> >(), It.IsAny <CancellationToken>())).ReturnsAsync(new TestMongoCursor <MongoRecord>(record)); MongoCollectionMock.Setup(x => x.ReplaceOneAsync( It.IsAny <FilterDefinition <MongoRecord> >(), It.IsAny <MongoRecord>(), It.IsAny <ReplaceOptions>(), It.IsAny <CancellationToken>())).ReturnsAsync(new ReplaceOneResult.Acknowledged(1, 0, new BsonString(""))); await Storage.AddOrUpdate(TestKey, TestValue); MongoCollectionMock.Verify(x => x.FindAsync( It.IsAny <FilterDefinition <MongoRecord> >(), It.IsAny <FindOptions <MongoRecord> >(), It.IsAny <CancellationToken>()), Times.Once); MongoCollectionMock.Verify(x => x.InsertOneAsync( It.IsAny <MongoRecord>(), It.IsAny <InsertOneOptions>(), It.IsAny <CancellationToken>()), Times.Never); MongoCollectionMock.Verify(x => x.ReplaceOneAsync( It.IsAny <FilterDefinition <MongoRecord> >(), It.IsAny <MongoRecord>(), It.IsAny <ReplaceOptions>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task AddOrGet_callsFindAsync() { MongoCollectionMock.Setup(x => x.FindAsync( It.IsAny <FilterDefinition <MongoRecord> >(), It.IsAny <FindOptions <MongoRecord> >(), It.IsAny <CancellationToken>())).ReturnsAsync(new TestMongoCursor <MongoRecord>(new MongoRecord())); await Storage.AddOrGet(TestKey, TestValue); MongoCollectionMock.Verify(x => x.FindAsync( It.IsAny <FilterDefinition <MongoRecord> >(), It.IsAny <FindOptions <MongoRecord> >(), It.IsAny <CancellationToken>()), Times.Once); MongoCollectionMock.Verify(x => x.InsertOneAsync( It.IsAny <IClientSessionHandle>(), It.IsAny <MongoRecord>(), It.IsAny <InsertOneOptions>(), It.IsAny <CancellationToken>()), Times.Never); }