public void Async_Call_HelloWorld_with_Async_ServiceClients_on_UserDefined_Routes(IServiceClient client)
        {
            HelloResponse response = null;
            client.GetAsync<HelloResponse>("/hello/World!",
                r => response = r, (r, e) => Assert.Fail("NetworkError"));

            Thread.Sleep(TimeSpan.FromSeconds(1));

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
 private static void GetStatus(IServiceClient client)
 {
     client.GetAsync(new StatusRequest(),
     (r) =>
     {
       Console.WriteLine("Result of status:" + r.Dump());
     }, (r, e) =>
     {
       Console.WriteLine("Error adding:" + e.Dump());
     });
       Wait();
 }
        public async Task Async_Call_HelloWorld_with_Async_ServiceClients_on_UserDefined_Routes(IServiceClient client)
        {
            var response = await client.GetAsync<HelloResponse>("/hello/World!");

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
        public async Task WaitForTestAgentRunsToFinishAsync(List <TestAgentRunDto> testAgentRuns, double testRunTimeout, int frequency)
        {
            var timeout   = TimeSpan.FromMinutes(testRunTimeout);
            var stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();
                var notFinishedTestAgentRunIds = testAgentRuns.Select(x => x.TestAgentRunId).ToList();
                var loggerCancellationToken    = new CancellationTokenSource();
                var loggingTask = _testAgentsLoggerService.LogTestAgentsRunsResults(loggerCancellationToken, testAgentRuns.First().TestRunId);
                var testRunId   = testAgentRuns.First().TestRunId;
                var cancellationTokenSourceLastAvailable = new CancellationTokenSource();
                var updateTestRunnerLastAvailableTask    = _taskProvider.StartNewLongRunningRepeating(
                    cancellationTokenSourceLastAvailable,
                    () =>
                {
                    UpdateTestRunnerLastAvailable(testRunId).Wait();
                },
                    60000);
                var testRun = await _testRunRepository.GetAsync(testRunId);

                do
                {
                    if (loggingTask.IsFaulted)
                    {
                        loggingTask = _testAgentsLoggerService.LogTestAgentsRunsResults(loggerCancellationToken, testAgentRuns.First().TestRunId);
                    }

                    var finishedTestAgentRunsToBeRemoved = new List <int>();

                    foreach (var testAgentRunId in notFinishedTestAgentRunIds)
                    {
                        var testAgentRun = await _testAgentRunRepository.GetAsync(testAgentRunId);

                        var testAgentRunAvailability = await _testAgentRunAvailabilityServiceClient.GetLastTestAgentRunAvailabilityForTestRun(testAgentRunId);

                        if (testAgentRunAvailability == null)
                        {
                            // DEBUG:
                            _consoleProvider.WriteLine("WaitForTestAgentRunsToFinishAsync testAgentRunAvailability is NULL");
                        }

                        if (testAgentRun == null || testAgentRun.Status == TestAgentRunStatus.Completed || testAgentRun.Status == TestAgentRunStatus.Aborted)
                        {
                            finishedTestAgentRunsToBeRemoved.Add(testAgentRunId);
                        }
                        else if (testAgentRunAvailability != null && testAgentRunAvailability.LastAvailable < _dateTimeProvider.GetCurrentTime().AddSeconds(-120))
                        {
                            var testAgent = await _testAgentRepository.GetAsync(testAgentRun.TestAgentId);

                            _consoleProvider.WriteLine($"Abort Test Agent Run because test runner lost connection with test agent on machine: {testAgent.MachineName} {testAgentRunAvailability.LastAvailable} {_dateTimeProvider.GetCurrentTime().AddSeconds(-120)} current status {testAgentRun.Status}");
                            await AbortAllTestAgentRunsInTestRunAsync(testRunId);

                            loggerCancellationToken.Cancel();
                            cancellationTokenSourceLastAvailable.Cancel();
                            loggingTask.Wait();
                            updateTestRunnerLastAvailableTask.Wait();
                            return;
                        }
                        else
                        {
                            // DEBUG:
                            ////_consoleProvider.WriteLine($"WaitForTestAgentRunsToFinishAsync: Test agent {testAgentRun.TestAgentId} is still running tests. Status: {testAgentRun.Status}");
                            if (testAgentRunAvailability != null)
                            {
                                // DEBUG:
                                ////_consoleProvider.WriteLine($"WaitForTestAgentRunsToFinishAsync: Test agent on agent {testAgentRun.TestAgentId} testAgentRunAvailability is {testAgentRunAvailability.LastAvailable}");
                            }
                        }
                    }

                    foreach (var finishedTestAgentRunToBeRemoved in finishedTestAgentRunsToBeRemoved)
                    {
                        notFinishedTestAgentRunIds.Remove(finishedTestAgentRunToBeRemoved);
                    }

                    if (notFinishedTestAgentRunIds.Count == 0)
                    {
                        // DEBUG:
                        ////_consoleProvider.WriteLine("WaitForTestAgentRunsToFinishAsync: notFinishedTestAgentRunIds.Count == 0");
                        cancellationTokenSourceLastAvailable.Cancel();
                        loggerCancellationToken.Cancel();
                        loggingTask.Wait();
                        updateTestRunnerLastAvailableTask.Wait();
                        return;
                    }

                    Thread.Sleep(frequency);

                    if (stopwatch.Elapsed.Ticks > timeout.Ticks)
                    {
                        cancellationTokenSourceLastAvailable.Cancel();
                        loggerCancellationToken.Cancel();
                        loggingTask.Wait();
                        updateTestRunnerLastAvailableTask.Wait();
                        throw new TimeoutException("Test run timeout!");
                    }
                }while (true);
            }
            catch (Exception ex)
            {
                await _logger.LogErrorAsync(ex.Message, ex);

                throw;
            }
        }
示例#5
0
        public async Task Can_download_Strings_response_Async(IServiceClient client)
        {
            var response = await client.GetAsync(new Strings { Text = "Test" });

            Assert.That(response, Is.EqualTo("Hello, Test"));
        }
 public async Task <Maybe <User> > GetAsync(string userId)
 {
     Logger.Debug($"Requesting GetAsync, userId:{userId}");
     return(await _serviceClient.GetAsync <User>(_name, $"users/{userId}"));
 }
示例#7
0
        public async Task Does_SGSendAsyncGetExternal()
        {
            var response = await client.GetAsync(new SGSendAsyncGetExternal { Value = "GET CLIENT" });

            Assert.That(response.Value, Is.EqualTo("GET CLIENT> GET SGSendAsyncGetExternal> GET SGAsyncGetExternal"));
        }
 public async Task <Maybe <T> > GetAsync <T>(Guid id) where T : class
 {
     Logger.Debug($"Requesting GetAsync, id:{id}");
     return(await _serviceClient
            .GetAsync <T>(_name, $"remarks/{id}"));
 }
 public async Task <Maybe <Remark> > GetAsync(Guid id)
 {
     Logger.Debug($"Requesting GetAsync, id:{id}, type: {typeof(Remark).FullName}");
     return(await _serviceClient
            .GetAsync <Remark>(_name, $"remarks/{id}"));
 }
        public async Task <IEnumerable <Cotizacion> > BuscarPorCliente(string clienteId)
        {
            IEnumerable <Cotizacion> _cotizaciones;
            HttpResponseMessage      response = await serviceClient.GetAsync($"/clientes/{clienteId}/cotizaciones");

            JObject respuesta = await response.Content.ReadAsJsonAsync <JObject>();

            JArray _cotizacionesJson = (JArray)respuesta.GetValue("data");

            _cotizaciones = _cotizacionesJson.Select(c => new Cotizacion {
                IdCotizacion = (int)c["idCotizacion"],
                Marca        = new Marca {
                    CodigoMarca = (c["codigoMarca"] != null) ? (string)c["codigoMarca"] : string.Empty,
                    NombreMarca = (c["nombreMarca"] != null) ? (string)c["nombreMarca"] : string.Empty
                },
                Modelo = new Modelo {
                    CodigoModelo = (c["codigoModelo"] != null) ? (string)c["codigoModelo"]: string.Empty,
                    NombreModelo = (c["nombreModelo"] != null) ? (string)c["nombreModelo"]: string.Empty
                },
                NombreColor  = (c["nombreColor"] != null) ? (string)c["nombreColor"]: string.Empty,
                NombreEstado = (c["nombreEstado"] != null) ? (string)c["nombreEstado"]: string.Empty,

                NumeroCotizacion = (string)c["numeroCotizacion"],
                FechaRegistro    = (DateTime)c["fechaRegistro"],

                FechaUltimoContacto  = (c["fechaUltimoContacto"] != null) ? (string)c["fechaUltimoContacto"]: string.Empty,
                FechaProximoContacto = (c["fechaProximoContacto"] != null) ? (string)c["fechaProximoContacto"]: string.Empty,

                MontoPrecioLista  = (c["montoPrecioLista"] != null) ? (decimal)c["montoPrecioLista"]: (decimal?)null,
                MontoPrecioVenta  = (c["montoPrecioVenta"] != null) ? (decimal)c["montoPrecioVenta"]: (decimal?)null,
                MontoPrecioCierre = (c["montoPrecioCierre"] != null) ? (decimal)c["montoPrecioCierre"]: (decimal?)null,

                Cantidad = (c["cantidad"] != null) ? (int)c["cantidad"]: (int?)null,

                Cliente = new Cliente {
                    NombreCompleto    = (string)c["nombreCliente"],
                    NumeroDocumento   = (string)c["numeroDocumento"],
                    TipoPersonaNombre = (c["tipoCliente"] != null) ? (string)c["tipoCliente"]: string.Empty
                },

                Empleado = new Empleado {
                    NombreCompleto = (string)c["nombreEmpleado"]
                },

                NombreJefeVentas = (string)c["nombreJefeVentas"],

                NombreComercial  = (string)c["nombreComercial"],
                NombreCarroceria = (string)c["nombreCarroceria"],

                CodigoFamilia  = (string)c["codigoFamilia"],
                NombreFamilia  = (string)c["nombreFamilia"],
                AñoModelo      = (string)c["añoModelo"],
                AñoFabricacion = (string)c["añoFabricacion"],

                NombreFormaPago     = (c["nombreFormaPago"] != null) ? (string)c["combreFormaPago"]: string.Empty,
                NombreModoCaptacion = (string)c["nombreModoCaptacion"],

                Observacion = (c["observacion"] != null) ? (string)c["observacion"]: string.Empty,

                PuntoVenta = new PuntoVenta {
                    IdPuntoVenta     = (int)c["idPuntoVenta"],
                    NombrePuntoVenta = (string)c["nombrePuntoVenta"],
                },

                CanalVenta = new CanalVenta {
                    CodigoCanalVenta = (string)c["codigoCanalVenta"],
                    NombreCanalVenta = (string)c["nombreCanalVenta"],
                },

                CodigoTipoVenta = (string)c["codigoTipoVenta"],
                NombreTipoVenta = (string)c["nombreTipoVenta"],

                FechaUltimoLead = (c["fechaUltimoLead"] != null) ? (DateTime)c["fechaUltimoLead"]: (DateTime?)null,

                Empresa = (c["empresa"] != null) ? (string)c["empresa"]: string.Empty,

                Ubica = new Ubicacion {
                    IdUbica = (int)c["idUbica"]
                }
            }).ToList();

            return(_cotizaciones);
        }
        public async Task Async_Call_HelloWorld_with_Async_ServiceClients_on_UserDefined_Routes(IServiceClient client)
        {
            var response = await client.GetAsync <HelloResponse>("/hello/World!");

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
示例#12
0
        public async Task <Maybe <T> > GetAsync <T>(string endpoint) where T : class
        {
            Logger.Debug($"Get data from storage, endpoint: {endpoint}");

            return(await _serviceClient.GetAsync <T>(_settings.Name, endpoint));
        }
 public async Task <Maybe <T> > GetAsync <T>(Guid requestId) where T : class
 {
     Logger.Debug($"Requesting GetAsync, requestId:{requestId}");
     return(await _serviceClient.GetAsync <T>(_name, $"/operations/{requestId}"));
 }
示例#14
0
 public async Task <Maybe <T> > IsAvailableAsync <T>(string name) where T : class
 {
     Logger.Debug($"Requesting IsAvailableAsync, name:{name}");
     return(await _serviceClient.GetAsync <T>(_name, $"users/{name}/available"));
 }