public void ShouldNotifyWhenCallingWatchEventRaised() { var notificationService = Substitute.For <IHostNotificationService>(); var watcher = new ExposedServiceWatcher(notificationService); var exposedService = new ExposedService("test", 80); watcher.WatchEventRaised(exposedService); notificationService.Received().Notify(exposedService); }
public void Notify(ExposedService exposedService) { Log.Logger.ForContext <MessageQueueNotificationService>().Information("New container event: {@ExposedService}", exposedService); var frame = GetSerializedMessageFrame(exposedService); try { _pushSocket.SendFrame(frame); } catch (Exception exception) { Log.Logger.ForContext <MessageQueueNotificationService>().Error(exception, "Error while sending exposed service change to the message queue."); } }
public void ShouldSendFrameWhenCallingNotify() { var socket = Substitute.For <PushSocket>(string.Empty); var service = new MessageQueueNotificationService(socket); var message = new Msg(); string response = null; socket.WhenForAnyArgs(x => x.TrySend(ref message, Arg.Any <TimeSpan>(), Arg.Any <bool>())) .Do(x => { response = Encoding.UTF8.GetString(x.Arg <Msg>().Data); }); var exposedService = new ExposedService("test", 80) { State = ExposedServiceState.ServiceAdded }; service.Notify(exposedService); response.Should().Be(JsonConvert.SerializeObject(exposedService)); }
private string GetSerializedMessageFrame(ExposedService exposedService) { return(JsonConvert.SerializeObject(exposedService)); }