public async Task <RequestVoteResponse> Send(RequestVote requestVote) { try { var serverToSendMessageTo = _serviceRegistry.Get(RaftyServiceDiscoveryName.Get()).First(x => x.Id == requestVote.VoterId); var json = JsonConvert.SerializeObject(requestVote, Formatting.None, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); var httpContent = new StringContent(json); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (var httpClient = new HttpClient()) { httpClient.BaseAddress = serverToSendMessageTo.Location; var response = await httpClient.PostAsync(_requestVoteUrl, httpContent); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); var requestVoteResponse = JsonConvert.DeserializeObject <RequestVoteResponse>(content); return(requestVoteResponse); } } catch (Exception exception) { _logger.LogError(new EventId(1), exception, "Error in Send(RequestVote requestVote)"); throw; } }
private void GivenAListOfRegisteredServices() { for (int i = 0; i < 5; i++) { var registerService = new RegisterService(RaftyServiceDiscoveryName.Get(), Guid.NewGuid(), new Uri($"www.rafty.co.uk:123{i}")); _inMemoryServiceRegistry.Register(registerService); } }
public void can_register_service() { var registerService = new RegisterService(RaftyServiceDiscoveryName.Get(), Guid.NewGuid(), new Uri("http://www.rafty.co.uk")); this.Given(x => GivenAServiceToRegister(registerService)) .When(x => WhenIRegisterTheService()) .Then(x => ThenItIsRegistered()) .BDDfy(); }
private void WhenIGetTheRegisteredServices() { _result = _inMemoryServiceRegistry.Get(RaftyServiceDiscoveryName.Get()); }