public override void Execute(JsonStringContent feedbackContent) { Subscription subscription = unitOfWork.GetByID(Convert.ToString(feedbackContent.Value("ID"))); subscription.Active = false; subscription.Status = "Stoped"; subscription.ExpiredAt = DateTime.UtcNow.Ticks; unitOfWork.Remove(Convert.ToString(feedbackContent.Value("ID"))); unitOfWork.Add(subscription); unitOfWork.Commit(); subject.Detach(observer); }
public void ApiRequestTest() { var test = "40.7484284;-73.9856546198733"; var request = "Empire State Building"; var response = client.ApiRequest(request); var compare = new JsonStringContent(response.ToString()); Assert.AreEqual(Convert.ToString(compare.Value("geolocation")), test); Assert.AreEqual(Convert.ToString(compare.Value("area")), "New York:New York County:USA"); var negativeRequest = "0123456789qwerasdf"; ApiResponse negativeResponse; Assert.Throws <ArgumentException>(() => negativeResponse = client.ApiRequest(negativeRequest), $"Unknown location { negativeRequest }."); }
public void Create(ApiResponse coordinates) { JsonStringContent geolocation = new JsonStringContent(coordinates.ToString()); var key = Convert.ToString(geolocation.Value("area")); _database.Add(key, coordinates); }
public override void Execute(JsonStringContent feedbackContent) { subject.Attach(observer); Subscription subscription = new Subscription(); subscription.ID = Convert.ToString(feedbackContent.Value("ID")); subscription.UserID = Convert.ToString(feedbackContent.Value("UserID")); subscription.Location = Convert.ToString(feedbackContent.Value("Location")); subscription.RequestsPerHour = Convert.ToInt32(feedbackContent.Value("ResponsesPerHour")); subscription.Active = true; subscription.Status = "Started"; subscription.CreatedAt = DateTime.UtcNow.Ticks; subscription.ExpiredAt = 0; subscription.LastSent = DateTime.UtcNow.Ticks; unitOfWork.Commit(); unitOfWork.Add(subscription); }
private void ControlSubscriptions() { string rabbitFeedback; JsonStringContent feedbackContent; Observer observer; while (true) { rabbitFeedback = _consumer.ReceiveQueue(_subscriptionQueueKey); if (rabbitFeedback == null) { Thread.Sleep(100); continue; } feedbackContent = new JsonStringContent(rabbitFeedback); string key = Convert.ToString(feedbackContent.Value("Subscription")); observer = new Observer(_configPath, Convert.ToString(feedbackContent.Value("UserID")), Convert.ToString(feedbackContent.Value("Location")), Convert.ToInt32(feedbackContent.Value("ResponsesPerHour")), _consumer, _publisher); SubscriptionStrategy strategy; if (key.Equals(_subscriptionKey)) { strategy = new SubscribeStrategy(_unit, _subject, observer); strategy.Execute(feedbackContent); continue; } if (key.Equals(_cancelSubscriptionKey)) { strategy = new AbortedSubscriptionStrategy(_unit, _subject, observer); strategy.Execute(feedbackContent); continue; } throw new ArgumentException($"Invalid value of {key}. Only {_subscriptionKey} and {_cancelSubscriptionKey} are excepted."); } }
public void ExecuteTest() { var positive = new Dictionary <string, string>() { { "area", "Empire State Building:New York:USA" }, { "created", "637399363231592838" }, { "geolocation", "Empire State Building:New York:USA" }, { "status", "Published" }, { "finished", "637399363231723630" } }; string positiveTest = "Empire State Building:New York:USA"; taskManager.Execute(positiveTest); var positiveEtalon = new ApiResponse(positive); var positiveFeedback = new JsonStringContent(consumer.Receive(positiveTest)); Assert.AreEqual(positiveFeedback.Value("area"), positiveEtalon.Value("area")); Assert.AreEqual(positiveFeedback.Value("geolocation"), positiveEtalon.Value("geolocation")); Assert.AreEqual(positiveFeedback.Value("status"), positiveEtalon.Value("status")); var negative = new Dictionary <string, string>() { { "area", "1234567890qwerasdf" }, { "created", "637399363231592838" }, { "geolocation", "1234567890qwerasdf" }, { "status", "Published" }, { "finished", "637399363231723630" } }; string negativeTest = "1234567890qwerasdf"; taskManager.Execute(negativeTest); var negativeEtalon = new ApiResponse(negative); var negativeFeedback = new JsonStringContent(consumer.Receive(negativeTest)); Assert.AreEqual(negativeFeedback.Value("area"), negativeEtalon.Value("area")); Assert.AreEqual(negativeFeedback.Value("geolocation"), negativeEtalon.Value("geolocation")); Assert.AreEqual(negativeFeedback.Value("status"), negativeEtalon.Value("status")); }