Пример #1
0
        public async Task GivenOneMachineWithoutData_WhenReceivingItsStates_ThenOneRequest_ShouldBeSent()
        {
            // Given
            var tokenProviderMock = new Mock <ITokenProvider>();

            tokenProviderMock
            .Setup(tp => tp.ReceiveTokenAsync(It.IsAny <TapioScope>()))
            .ReturnsAsync("foo");

            var handler = new Mock <HttpMessageHandler>();

            handler
            .SetupRequest(HttpMethod.Post, "https://core.tapio.one/api/machines/state")
            .ReturnsResponse(HttpStatusCode.OK, new StringContent("[]", new UTF8Encoding(false)))
            .Verifiable();

            var httpClient = handler.CreateClient();

            var cut = new MachineStateService(httpClient, tokenProviderMock.Object, Mock.Of <ILogger <MachineStateService> >());

            // When
            _ = await cut.GetMachineStateAsync("2f5b690df6c0406982d49fd9b7a8835b", CancellationToken.None);

            // Then
            handler.VerifyAnyRequest(Times.Once());
        }
Пример #2
0
        public async Task GivenOneMachineWithThreeConditions_WhenReceivingItsStates_ThenTheResult_ShouldContainTheseConditions()
        {
            // Given
            var tokenProviderMock = new Mock <ITokenProvider>();

            tokenProviderMock
            .Setup(tp => tp.ReceiveTokenAsync(It.IsAny <TapioScope>()))
            .ReturnsAsync("foo");

            var responseContent = GetTestDataFromAssembly("SingleMachineWithSomeData.json");

            var handler = new Mock <HttpMessageHandler>();

            handler
            .SetupRequest(HttpMethod.Post, "https://core.tapio.one/api/machines/state")
            .ReturnsResponse(HttpStatusCode.OK, new StringContent(responseContent, new UTF8Encoding(false)))
            .Verifiable();

            var httpClient = handler.CreateClient();

            var cut = new MachineStateService(httpClient, tokenProviderMock.Object, Mock.Of <ILogger <MachineStateService> >());

            // When
            var result = await cut.GetMachineStateAsync("2f5b690df6c0406982d49fd9b7a8835b", CancellationToken.None);

            // Then
            result.Children().Should().HaveCount(3);
        }
 public ActionResult CambiarEstado(string documentoReferencia, string estadoNuevo, string returnUrl)
 {
     try
     {
         using (var service = FService.Instance.GetService(typeof(TransformacioneslotesModel), ContextService) as TransformacioneslotesService)
         {
             service.EjercicioId = ContextService.Ejercicio;
             using (var estadosService = new EstadosService(ContextService))
             {
                 var model                = service.get(documentoReferencia) as TransformacioneslotesModel;
                 var nuevoEstado          = estadosService.get(estadoNuevo) as EstadosModel;
                 var cambiarEstadoService = new MachineStateService();
                 cambiarEstadoService.SetState(service, model, nuevoEstado);
                 if (nuevoEstado.Tipoestado == TipoEstado.Finalizado)
                 {
                     TempData[Constantes.VariableMensajeExito] = "Transformación terminada con éxito";
                 }
             }
         }
     }
     catch (Exception ex)
     {
         TempData["errors"] = ex.Message;
     }
     return(Redirect(returnUrl));
 }
Пример #4
0
        public IEnumerable <EstadosModel> GetStates(DocumentoEstado documento, TipoEstado?estadoactual)
        {
            var service = new MachineStateService();
            var estados = estadoactual.HasValue
                ? service.GetStatesFromState(estadoactual.Value)
                : new[] { TipoEstado.Diseño };

            return(_db.Estados.Where(f => f.tipomovimiento == (int)Model.Configuracion.TipoMovimiento.Manual && (f.documento == (int)documento || f.documento == (int)DocumentoEstado.Todos) && estados.Any(j => j == (TipoEstado)f.tipoestado)).ToList().Select(h => _converterModel.GetModelView(h) as EstadosModel));
        }
 public ActionResult CambiarEstado(string documentoReferencia, string estadoNuevo, string returnUrl)
 {
     try
     {
         using (var service = FService.Instance.GetService(typeof(AlbaranesComprasModel), ContextService) as AlbaranesComprasService)
         {
             service.EjercicioId = ContextService.Ejercicio;
             using (var estadosService = new EstadosService(ContextService))
             {
                 var model                = service.get(documentoReferencia) as AlbaranesComprasModel;
                 var nuevoEstado          = estadosService.get(estadoNuevo) as EstadosModel;
                 var cambiarEstadoService = new MachineStateService();
                 cambiarEstadoService.SetState(service, model, nuevoEstado);
             }
         }
     }
     catch (Exception ex)
     {
         TempData["errors"] = ex.Message;
     }
     return(Redirect(returnUrl));
 }