private void HandleStreamingCollections(string type, JObject data) { var collectionResult = data.ToObject <CollectionResult>(JsonSerializer); if (collectionResult.Name == null) { return; } var collection = _collectionDatabase.GetOrAddCollection(collectionResult.Name); switch (type) { case "added": collection.Added(collectionResult.Id, collectionResult.Fields); break; case "changed": collection.Changed(collectionResult.Id, collectionResult.Fields); break; case "removed": collection.Removed(collectionResult.Id); break; default: throw new InvalidOperationException($"Encountered a unknown subscription update type {type}."); } }
public void Added_message_should_add_to_a_streaming_collection() { var payload = new { collection = AutoFixture.Create <string>(), id = AutoFixture.Create <string>(), fields = new { id = AutoFixture.Create <string>() } }; var mockCollection = Substitute.For <IStreamCollection>(); _mockCollectionDatabase.GetOrAddCollection(payload.collection).Returns(mockCollection); // Act _mockClient.DataReceivedRaw += Raise.Event <DataReceived>("added", JObject.FromObject(payload)); // Assert mockCollection.Received().Added(payload.id, Arg.Any <JObject>()); }