mongodb-user
[Arriba] [Todas las Listas]

Re: [mongodb-Usuario] Cómo yo mock Mongo database con moq

To: mongodb-user <mongodb-user@xxxxxxxxxxxxxxxx>
Subject: Re: [mongodb-Usuario] Cómo yo mock Mongo database con moq
From: Rajnikant Rana <rana.rajnikant@xxxxxxxxx>
Date: Tue, 15 Aug 2017 21:24:22 -0700 (PDT)
Cc: russ@xxxxxxxxxxxxxxxx
Delivery-date: Wed, 16 Aug 2017 08:43:12 -0400
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:cc:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=L0S4Fz2fPBP1VFHf/ffoUhYe43LgOk7Bs818/gqE5b4=; b=EltMsc5zeTGzFo/3gKHMOuDSp04MOQDWxKigpevsLcmNhSi6iDiXywovDaYKOey6sT XJDIPUkXnrWt6QffT+fRAua18zt59Rj7mQRLix/N2gc9VbSOFQjwRxoPakDA4fMHZOMU 6MtVoa2CTAf0e8UQ4mxGSDrqz8TuoNAUD0biK45s8I9Xb80YV1fS2n7iUei4B89/K+N9 xVFSsosBYY++zQ0sFifkcIAHrhugIpJqXcAcnPSJf7z4TFErEnsKUuCSWGXqw3PVkuVX VEtKtgBZXhKeBaJGQ3I68R8fmDQg2OWNtz/a5ffg7zLq0RhyLAxovQcRJNEN6qH5nSYI tXXQ==
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <509BC974.20302@windofkeltia.com>
List-archive: <https://groups.google.com/group/mongodb-use>
List-help: <https://groups.google.com/support/>, <mailto:mongodb-user+help@googlegroups.com>
List-id: <mongodb-user.googlegroups.com>
List-post: <https://groups.google.com/group/mongodb-user/post>, <mailto:mongodb-user@googlegroups.com>
List-subscribe: <https://groups.google.com/group/mongodb-user/subscribe>, <mailto:mongodb-user+subscribe@googlegroups.com>
List-unsubscribe: <mailto:googlegroups-manage+1044811755470+unsubscribe@googlegroups.com>, <https://groups.google.com/group/mongodb-user/subscribe>
Mailing-list: list mongodb-user@xxxxxxxxxxxxxxxx; contact mongodb-user+owners@xxxxxxxxxxxxxxxx
References: <e6f50786-e07f-457d-a3e4-55a8820c50e0@googlegroups.com> <509A9C2D.9000609@windofkeltia.com> <cc1c092f-35f8-448c-9b93-f580680f5f4c@googlegroups.com> <509BC974.20302@windofkeltia.com>
Reply-to: mongodb-user@xxxxxxxxxxxxxxxx
Sender: mongodb-user@xxxxxxxxxxxxxxxx
*Hi *Russ,

 encuentras cualquier manera puesto que, cómo a *mock *MongoDB colección?

En jueves, noviembre 8, 2012 en 8:32:12 PM *UTC+5:30, Russell *Bateman escribió:
>
> he no fundar una manera a unidad-probar mi *DAO capa, aunque he buscado 
> uno. He visto un par de dentro-memoria *databases que podría, en teoría, tomar 
> el sitio de *MySQL, *PostgreSQL, *etc. En un entorno de prueba de la unidad, pero he 
> encontrado la solución lejos demasiado complicada. Yo ayuda solicitada una vez en este foro 
> para una solución, pero nadie ha venido adelante.
>
> Más de suerte; seré mirar para una respuesta. Quizás conseguiremos uno.
>
> *Russ
>
>
> En 11/8/2012 4:32 AM, Richard *Byrne escribió:
>
> es el *DAO capa estoy probando. 
>
>
>
> En miércoles, noviembre 7, 2012 5:38:15 PM *UTC, Russell *Bateman escribió: 
>>
>> Richard,
>>
>> soy un *Java *guy, pero si contestaba, ofrecería que uno  no *mock 
>> clases uno no posee. Por tanto, justo cómo  yo (personalmente) *mock 
>> *MongoDB? Yo  no. En cambio, llamo *Mongo (*Java conductor o *Morphia) de mi 
>> *DAO capa, el cual es bastante delgado en todo caso. Yo por tanto *mock mi *DAO capa. Esto 
>> trabaja perfectamente para mí.
>>
>> Utilizo *Mockito; no sé lo que disponible para *C#, pero apostaré hay abundancia de opciones.
>>
>> Hope estas ayudas,
>>
>> *Russ *Bateman
>>
>>
>> En 11/7/2012 8:27 AM, Richard *Byrne escribió:
>>
>> tengo una capa de dato que utiliza el *C# *MongoDB.Conductor. 
>>
>> Mi capa de dato tiene un público *MongoDatabase así que puedo inyectar un 
>> *mock *MongoDatabase para probar.
>>
>> Me gustaría para probar mi *datalayer por inyectar un *mock *MongoDatabase y regresando 
>> un *mocked *MongoCollection.
>>
>> He probado un número de maneras de hacer esto del 2 o 3 sugerencias hechas 
>> en la Web.
>>  
>> La Versión más tardía es adaptada de *http://*thoai-*nguyen.*blogspot.*com.*au/2012/06/qué-*i-*mock-*mongo-colección.*html 
>>   
>> Cuál *mocks una colección y no un *database
>>
>>         [Prueba()]
>>         público *void *GetAllSettingsTest()
>>             //#verbcj
>>             *MongoServerSettings *ServerSettings;
>>             *MongoServer *Server;
>>             *MongoDatabaseSettings *DatabaseSettings;
>>             *MongoDatabase *Database;
>>
>>             *ServerSettings = nuevo *MongoServerSettings
>>                 #unknown{^*Servers = Lista nueva<*MongoServerAddress
>>                 #adj *MongoServerAddress("*unittest")
>>             }
>>             };
>>
>>             *Server = nuevo *MongoServer(*ServerSettings);
>>             *DatabaseSettings = nuevo *MongoDatabaseSettings("*databaseName", 
>>                                                         nuevo 
>> *MongoCredentials("", ""), 
>>                                                         
>> *GuidRepresentation.Estándar, 
>>                                                         
>> *ReadPreference.Más cercano, 
>>                                                         *SafeMode.Cierto);
>>             *Database = nuevo *MongoDatabase(*Server, *DatabaseSettings);
>>
>>             *var *collectionSetting = nuevo 
>> *MongoCollectionSettings<*BsonDocument>(*Database, *typeof(*BsonDocument).Nombre);
>>             *var la colección = nueva 
>> *Mock<*MongoCollection<*BsonDocument>>(*Database, *collectionSetting);
>>
>>             colección.*Setup(*f => *f.*Database).Regresos(*Database);
>>             colección.*Setup(*f => *f.*Settings).Regresos(*collectionSetting);
>>
>>             *BsonDocument *doc01 = nuevo *BsonDocument();
>>             *BsonDocument *doc02 = nuevo *BsonDocument();
>>             colección.Objeto.Inserta(*doc01);
>>             colección.Objeto.Inserta(*doc02);
>>
>>             *var *mongoDatabase = nuevo *Mock<*MongoDatabase>(*Server, 
>> *DatabaseSettings);
>>             *mongoDatabase.*Setup(*f => 
>> *f.*GetCollection(*MongoCollections.*Settings)).Regresos(colección.Objeto);
>>
>>             *ILogger *logger = nuevo *Logger();
>>             *DatabaseClient.*DatabaseClient Apunta = nuevo 
>> *DatabaseClient.*DatabaseClient(*logger);
>>             Objetivo.*MongoDatabase = *mongoDatabase.Objeto;
>>
>>             //Lista
>>             de Acto<*BsonDocument> *resultList =  objetivo.*GetAllSettings();
>>         }
>>
>> En el objetivo  de línea.*MongoDatabase = *mongoDatabase.Objeto; estoy consiguiendo un *TargetInvocationException 
>> que está viniendo del Objeto del *mock.
>> Estoy pensando que esto es un problema con construir el objeto incluso aunque he suministrado los objetos de parámetro.
>>
>> Cualquiera sabe lo que estoy haciendo mal o una manera mejor de hacer esto?
>>
>> El método estoy probando es:
>>
>>         Lista pública<*BsonDocument> *GetAllSettings()
>>             #unknown{^*var colección = 
>> *MongoDatabase.*GetCollection<*BsonDocument>(*MongoCollections.*Settings);
>>             *var Consulta = de *e en colección.*AsQueryable()
>>                         Selecciona *e;
>>
>>             *var *settings = consulta.*ToList();
>>             Regreso *settings;
>>         }
>>  
>> -- 
>> recibiste este mensaje porque eres *subscribed al *Google
>> Grupos "*mongodb-grupo" de usuario.
>> A correo a este grupo, envía *email a mongod...@xxxxxxxxxxxxxxxx
>> A *unsubscribe de este grupo, envía *email a *mongodb-user...@xxxxxxxxxxxxxxxx
>> 
>> Ve también el *IRC canal -- *freenode.Neto#*mongodb
>>
>>
>> -- 
> recibiste este mensaje porque eres *subscribed al *Google
> Grupos "*mongodb-grupo" de usuario.
> A correo a este grupo, envía *email a mongod...@xxxxxxxxxxxxxxxx 
> <*javascript:>
> A *unsubscribe de este grupo, envía *email a *mongodb-user...@xxxxxxxxxxxxxxxx
>  <*javascript:>
> Ve también el *IRC canal -- *freenode.Neto#*mongodb
>
>
>

-- 
recibiste este mensaje porque eres *subscribed al *Google Grupos "*mongodb-grupo"
de usuario.

Para otro *MongoDB opciones de apoyo técnico, ve: *https://*docs.*mongodb.*com/Apoyo/manual/
--- 
recibiste este mensaje porque eres *subscribed al *Google Grupos "*mongodb-grupo" de usuario.
A *unsubscribe de este grupo y la parón que recibe *emails de él, enviar un *email a *mongodb-usuario+unsubscribe@xxxxxxxxxxxxxxxx.
A correo a este grupo, envía *email a *mongodb-user@xxxxxxxxxxxxxxxx.
Visita este grupo en *https://grupos.*google.*com/Grupo/*mongodb-usuario.
Para ver esta discusión en la visita de web *https://grupos.*google.*com/*d/*msgid/*mongodb-Usuario/667*c9989-*fec5-4*f11-#uno3*ca-2*ce19*bfab8*e1%40*googlegroups.*com.
Para más opciones, visita *https://grupos.*google.*com/*d/*optout.
Hi Russ,

do you find any way for, how to mock MongoDB collection?

On Thursday, November 8, 2012 at 8:32:12 PM UTC+5:30, Russell Bateman wrote:
>
> I haven't found a way to unit-test my DAO layer, though I've looked for 
> one. I've seen a couple of in-memory databases that could, in theory, take 
> the place of MySQL, PostgreSQL, etc. in a unit test environment, but I've 
> found the solution far too complicated. I once solicited help in this forum 
> for a solution, but no one has come forward.
>
> Best of luck; I'll be watching for an answer. Maybe we'll get one.
>
> Russ
>
>
> On 11/8/2012 4:32 AM, Richard Byrne wrote:
>
> It's the DAO layer I'm testing. 
>
>
>
> On Wednesday, November 7, 2012 5:38:15 PM UTC, Russell Bateman wrote: 
>>
>> Richard,
>>
>> I'm a Java guy, but if I were answering, I'd offer that one does not mock 
>> classes one does not own. Therefore, just how do I (personally) mock 
>> MongoDB? I do not. Instead, I call Mongo (Java driver or Morphia) from my 
>> DAO layer, which is pretty thin anyway. I therefore mock my DAO layer. This 
>> works perfectly for me.
>>
>> I use Mockito; I don't know what's available for C#, but I'll bet there 
>> are plenty of options.
>>
>> Hope this helps,
>>
>> Russ Bateman
>>
>>
>> On 11/7/2012 8:27 AM, Richard Byrne wrote:
>>
>> I have a data layer that uses the C# MongoDB.Driver. 
>>
>> My data layer has a public MongoDatabase so I can inject a 
>> mock MongoDatabase for testing.
>>
>> I'd like to test my datalayer by injecting a mock MongoDatabase and 
>> returning a mocked MongoCollection.
>>
>> I've tried a number of ways to do this from the 2 or 3 suggestions made 
>> on the Web.
>>  
>> Latest version is adapted from 
>> http://thoai-nguyen.blogspot.com.au/2012/06/how-i-mock-mongo-collection.html  
>> which mocks a collection and not a database
>>
>>         [Test()]
>>         public void GetAllSettingsTest()
>>         {
>>             //Arrange
>>             MongoServerSettings ServerSettings;
>>             MongoServer Server;
>>             MongoDatabaseSettings DatabaseSettings;
>>             MongoDatabase Database;
>>
>>             ServerSettings = new MongoServerSettings
>>             {
>>                 Servers = new List<MongoServerAddress>
>>             {
>>                 new MongoServerAddress("unittest")
>>             }
>>             };
>>
>>             Server = new MongoServer(ServerSettings);
>>             DatabaseSettings = new MongoDatabaseSettings("databaseName", 
>>                                                         new 
>> MongoCredentials("", ""), 
>>                                                         
>> GuidRepresentation.Standard, 
>>                                                         
>> ReadPreference.Nearest, 
>>                                                         SafeMode.True);
>>             Database = new MongoDatabase(Server, DatabaseSettings);
>>
>>             var collectionSetting = new 
>> MongoCollectionSettings<BsonDocument>(Database, typeof(BsonDocument).Name);
>>             var collection = new 
>> Mock<MongoCollection<BsonDocument>>(Database, collectionSetting);
>>
>>             collection.Setup(f => f.Database).Returns(Database);
>>             collection.Setup(f => f.Settings).Returns(collectionSetting);
>>
>>             BsonDocument doc01 = new BsonDocument();
>>             BsonDocument doc02 = new BsonDocument();
>>             collection.Object.Insert(doc01);
>>             collection.Object.Insert(doc02);
>>
>>             var mongoDatabase = new Mock<MongoDatabase>(Server, 
>> DatabaseSettings);
>>             mongoDatabase.Setup(f => 
>> f.GetCollection(MongoCollections.Settings)).Returns(collection.Object);
>>
>>             ILogger logger = new Logger();
>>             DatabaseClient.DatabaseClient target = new 
>> DatabaseClient.DatabaseClient(logger);
>>             target.MongoDatabase = mongoDatabase.Object;
>>
>>             //Act
>>             List<BsonDocument> resultList =  target.GetAllSettings();
>>         }
>>
>> At the line  target.MongoDatabase = mongoDatabase.Object; I'm getting a TargetInvocationException 
>> which is coming from the Object of the mock.
>> I'm thinking this is a problem with constructing the object even though I 
>> have supplied the parameter objects.
>>
>> Anyone know what I'm doing wrong or a better way to do this?
>>
>> The method I'm testing is:
>>
>>         public List<BsonDocument> GetAllSettings()
>>         {
>>             var collection = 
>> MongoDatabase.GetCollection<BsonDocument>(MongoCollections.Settings);
>>             var query = from e in collection.AsQueryable()
>>                         select e;
>>
>>             var settings = query.ToList();
>>             return settings;
>>         }
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "mongodb-user" group.
>> To post to this group, send email to mongod...@xxxxxxxxxxxxxxxx
>> To unsubscribe from this group, send email to
>> mongodb-user...@xxxxxxxxxxxxxxxx
>> See also the IRC channel -- freenode.net#mongodb
>>
>>
>> -- 
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@xxxxxxxxxxxxxxxx 
> <javascript:>
> To unsubscribe from this group, send email to
> mongodb-user...@xxxxxxxxxxxxxxxx <javascript:>
> See also the IRC channel -- freenode.net#mongodb
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
--- 
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to mongodb-user@xxxxxxxxxxxxxxxx.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/667c9989-fec5-4f11-a3ca-2ce19bfab8e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<Anterior por Tema] Tema Actual [Siguiente por Tema>