Example #1
0
        public async void GetBooks()
        {
            //System.Diagnostics.Debugger.Launch();
            //Which method of the microervice is in charge of query books?

            //1. Emulate EFCore instance: BookContext
            //To emulate the actions and events from an object in unit test environment que need to use a Mock object
            //install: Moq package

            var mockContext = CreateContext();

            //2. Emulate IMapper
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingTest());
            });

            var mapper = mapConfig.CreateMapper();

            //3. Instanciate the Handler class and send as parameters the created mocks before
            Query.Handler handler = new Query.Handler(mockContext.Object, mapper);

            Query.Execute request = new Query.Execute();

            var list = await handler.Handle(request, new System.Threading.CancellationToken());

            Assert.True(list.Any());
        }
Example #2
0
        public async void GetBook()
        {
            System.Diagnostics.Debugger.Launch();
            //Que metodo dentro de mi microservice libro se esta encargando
            //de realizar la consulta dellibros de la Bd ??
            //1.Emular  a la instancia de entity framework core - LibraryContext
            //para emular las acciones y eventos de un objeto en un ambiente de unit test
            //utilizamos objetos de tipo mock
            var mockContext = CreateContext();
            //2.emular al mapping IMapper
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingTest());
            });

            var mapper = mapConfig.CreateMapper();

            //3. Instanciar a la clase Handler y pasarle como parametros los mocks que he creado
            Query.Handler handler = new Query.Handler(mockContext.Object, mapper);
            Query.Execute request = new Query.Execute();
            var           list    = await handler.Handle(request, new System.Threading.CancellationToken());

            Assert.True(list.Any());
        }