Exemple #1
0
        public void Leer_KO()
        {
            AppConfig configuracion = ObtenerConfiguracionPersistenciaNextCounterDesactivada();

            Mock <ILogger>               loggerMock            = new Mock <ILogger>();
            Mock <ICounterRepository>    repositoryMock        = new Mock <ICounterRepository>();
            Mock <IOptions <AppConfig> > optionsMock           = new Mock <IOptions <AppConfig> >();
            Mock <IRepositoryFactory>    repositoryFactoryMock = new Mock <IRepositoryFactory>();

            repositoryMock.Setup(m => m.ObtenerContador()).Throws <Exception>();
            optionsMock.Setup(m => m.Value).Returns(configuracion);
            repositoryFactoryMock.Setup(m => m.Get(Claves.SELECTOR_PERSISTENCIA_REDIS)).Returns(repositoryMock.Object);

            CounterController counterController = new CounterController(loggerMock.Object, optionsMock.Object, repositoryFactoryMock.Object);

            Assert.ThrowsAsync <Exception>(() => counterController.Leer());
        }
Exemple #2
0
        public async Task Leer_OK_200()
        {
            AppConfig configuracion = ObtenerConfiguracionPersistenciaNextCounterDesactivada();

            Mock <ILogger>               loggerMock            = new Mock <ILogger>();
            Mock <ICounterRepository>    repositoryMock        = new Mock <ICounterRepository>();
            Mock <IOptions <AppConfig> > optionsMock           = new Mock <IOptions <AppConfig> >();
            Mock <IRepositoryFactory>    repositoryFactoryMock = new Mock <IRepositoryFactory>();

            ActionResult <int> resultadoEsperado = new OkObjectResult(CODIGO_RAMDOM_1);

            repositoryMock.Setup(m => m.ObtenerContador()).Returns(Task.FromResult(CODIGO_RAMDOM_1));
            optionsMock.Setup(m => m.Value).Returns(configuracion);
            repositoryFactoryMock.Setup(m => m.Get(Claves.SELECTOR_PERSISTENCIA_REDIS)).Returns(repositoryMock.Object);

            CounterController  counterController = new CounterController(loggerMock.Object, optionsMock.Object, repositoryFactoryMock.Object);
            ActionResult <int> resultado         = await counterController.Leer();

            resultado.Should().BeEquivalentTo(resultadoEsperado);
        }