public void EnviarNotaFiscalAsync_ContingênciaAtivada_NãoCriaNotaPendente()
        {
            // Arrange

            Mock <ICertificadoRepository> certificadoRepositoryMock;
            Mock <ICertificateManager>    certificadoManagerMock;

            ConfigurarCertificadoDigital(out certificadoRepositoryMock, out certificadoManagerMock);

            Mock <IServiceFactory> serviceFactoryMock = ConfigurarServiceFactoryMock();

            ConfigurarConfiguracao();

            var configuracaoRepository = new ConfiguracaoRepositoryFake();
            var configuracaoService    = new Cadastro.Configuracoes.ConfiguracaoService(configuracaoRepository);

            var certificadoRepository = certificadoRepositoryMock.Object;
            var serviceFactory        = serviceFactoryMock.Object;
            var nfeConsulta           = new Mock <INFeConsulta>().Object;
            var certificateManager    = certificadoManagerMock.Object;

            var consultaStatusServicoService = new Mock <IConsultaStatusServicoService>().Object;

            var emissorService           = new Mock <IEmissorService>().Object;
            var certificadoService       = new Mock <ICertificadoService>().Object;
            var notaInutilizadaService   = new Mock <INotaInutilizadaService>().Object;
            var cancelaNotaFiscalService = new Mock <ICancelaNotaFiscalService>().Object;

            INotaFiscalRepository notaFiscalRepository = new NotaFiscalRepositoryFake();
            var notaFiscalContingenciaService          = new EmiteEmiteNotaFiscalContingenciaService(configuracaoService, certificadoRepository, certificateManager, notaFiscalRepository, emissorService, nfeConsulta, serviceFactory, certificadoService, notaInutilizadaService, cancelaNotaFiscalService);

            var notaFiscalService = new EnviaNotaFiscalService(configuracaoRepository, notaFiscalRepository,
                                                               certificadoRepository, configuracaoService, serviceFactory, nfeConsulta, certificateManager,
                                                               notaFiscalContingenciaService);

            var modoOnlineService = new NotasFiscais.Services.ModoOnlineService(notaFiscalService,
                                                                                configuracaoRepository, consultaStatusServicoService, notaFiscalRepository,
                                                                                notaFiscalContingenciaService);

            // preencher nota fiscal;
            NotaFiscal notaFiscal = PreencherNotaFiscal();

            // Act

            notaFiscalService.EnviarNotaFiscal(notaFiscal, "000001", "E3BB2129-7ED0-31A10-CCB8-1B8BAC8FA2D0");
            notaFiscalService.EnviarNotaFiscal(notaFiscal, "000001", "E3BB2129-7ED0-31A10-CCB8-1B8BAC8FA2D0");

            // Assert

            var isContingência           = configuracaoRepository.GetConfiguracao().IsContingencia;
            var quantidadeNotasPendentes = notaFiscalRepository.GetAll().Count(n => n.Status == (int)Status.PENDENTE);
            var quantidadeTotalNotas     = notaFiscalRepository.GetAll().Count();

            Assert.True(isContingência);
            Assert.Equal(3, quantidadeTotalNotas);
            Assert.Equal(1, quantidadeNotasPendentes);
        }
        public void EnviarNotaFiscalAsync_FalhaDeConexão_AtivaContingencia()
        {
            Mock <ICertificadoRepository> certificadoRepositoryMock;
            Mock <ICertificateManager>    certificadoManagerMock;

            ConfigurarCertificadoDigital(out certificadoRepositoryMock, out certificadoManagerMock);

            Mock <IServiceFactory> serviceFactoryMock = ConfigurarServiceFactoryMock();

            ConfigurarConfiguracao();

            var configuracaoRepository = new ConfiguracaoRepositoryFake();
            var configuracaoService    = new Cadastro.Configuracoes.ConfiguracaoService(configuracaoRepository);

            var notaFiscalRepositoryMock = new Mock <INotaFiscalRepository>();

            notaFiscalRepositoryMock
            .Setup(m => m.GetNotaFiscalById(It.IsAny <int>(), It.IsAny <bool>()))
            .Returns(new NotaFiscalEntity());

            var notaFiscalRepository          = notaFiscalRepositoryMock.Object;
            var certificadoRepository         = certificadoRepositoryMock.Object;
            var serviceFactory                = serviceFactoryMock.Object;
            var nfeConsulta                   = new Mock <INFeConsulta>().Object;
            var certificateManager            = certificadoManagerMock.Object;
            var notaFiscalContingenciaService = new Mock <IEmiteNotaFiscalContingenciaService>().Object;

            var consultaStatusServicoService = new Mock <IConsultaStatusServicoService>().Object;

            var notaFiscalService = new EnviaNotaFiscalService(configuracaoRepository, notaFiscalRepository,
                                                               certificadoRepository, configuracaoService, serviceFactory, nfeConsulta, certificateManager,
                                                               notaFiscalContingenciaService);
            var modoOnlineService = new NotasFiscais.Services.ModoOnlineService(notaFiscalService,
                                                                                configuracaoRepository, consultaStatusServicoService, notaFiscalRepository,
                                                                                notaFiscalContingenciaService);

            // preencher nota fiscal;
            NotaFiscal notaFiscal = PreencherNotaFiscal();

            // envia com falha de conexão no serviço;
            notaFiscalService.EnviarNotaFiscal(notaFiscal, "000001", "E3BB2129-7ED0-31A10-CCB8-1B8BAC8FA2D0");
            // verifica se modo contingência foi ativado;
            var isContingência = configuracaoRepository.GetConfiguracao().IsContingencia;

            Assert.True(isContingência);
        }