Esempio n. 1
0
        public async Task GetUserJsonsAsync_Should_Return_All_User_Jsons(string username, Dictionary <DbJson, JsonModel> jsonModelsMapping)
        {
            Expression <Func <DbJson, bool> > expression = null;

            _mongoCollectionClient
            .When(x => x.FindAsync(username, Arg.Any <Expression <Func <DbJson, bool> > >()))
            .Do(info => { expression = (Expression <Func <DbJson, bool> >)info[1]; });
            _mongoCollectionClient
            .FindAsync(username, Arg.Any <Expression <Func <DbJson, bool> > >())
            .Returns(jsonModelsMapping.Keys);
            _mapper.Map <JsonModel>(Arg.Any <DbJson>())
            .Returns(x => jsonModelsMapping.FirstOrDefault(j => ((DbJson)x[0]).Id == j.Key.Id).Value);

            var result = await _jsonRepositoryInstance.GetUserJsonsAsync(username);

            Expression <Func <DbJson, bool> > expectedExpression = x => true;

            Assert.AreEqual(jsonModelsMapping.Values, result);
            Assert.IsTrue(Lambda.Eq(expectedExpression, expression));
        }