public Stream Serialize(object graph) { var stream = new PreservedMemoryStream(); binaryFormatter.Serialize(stream, graph); stream.Position = 0; return stream; }
public dynamic GetContent() { if (!blob.Exists()) return new JObject(); var s = new PreservedMemoryStream(); blob.DownloadToStream(s); using (var sr = new StreamReader(s)) using (var jr = new JsonTextReader(sr)) { return JToken.ReadFrom(jr); } }
public void UpdateContent(dynamic obj) { var accessCondition = string.IsNullOrEmpty(blob.Properties.ETag) ? AccessCondition.GenerateEmptyCondition() : AccessCondition.GenerateIfMatchCondition(blob.Properties.ETag); var s = new PreservedMemoryStream(); using (var sw = new StreamWriter(s)) using (var jw = new JsonTextWriter(sw)) { JObject jo = JObject.FromObject(obj); jo.WriteTo(jw); } blob.UploadFromStream(s, accessCondition); }
public void it_will_deserialise_a_brokered_msg_to_a_raised_event() { var body = @"{""Thumbprint"":""3BBADAF3-C41E-4697-9552-8E28439D2FDC"",""Event"":{""$type"":""Test.Honeycomb.Azure.DummyEvent, Test.Honeycomb.Azure"",""Prop"":""value""},""RaisedTimestamp"":""2013-01-14T21:46:22+00:00"",""TransactionId"":""txid""}"; var stream = new PreservedMemoryStream(); using (var sw = new StreamWriter(stream)) sw.Write(body); var expected = new BrokeredMessageWrapper(new BrokeredMessage(stream, true)); var actual = expected.ConvertToEvent(); actual.Event.ShouldBeType<DummyEvent>(); ((DummyEvent) actual.Event).Prop.ShouldEqual("value"); actual.RaisedTimestamp.ShouldEqual(new DateTimeOffset(2013, 01, 14, 21, 46, 22, TimeZoneInfo.Utc.BaseUtcOffset)); actual.TransactionId.ShouldEqual("txid"); }
protected override void Given() { session = Substitute.For<ISerializationSession>(); var backingStore = Substitute.For<IBackingStore>(); var registry = new Registry(backingStore); registry.RegisterGraph<IsolatedClass>(); registry.RegisterGraph<ComposingClass>(); subject = new JsonSerializer<ComposingClass>((IRegisteredGraph<ComposingClass>)registry.RegisteredGraphs[typeof(ComposingClass)]); expectedInternalId = new InternalId(Guid.NewGuid()); jsonSource = @"{""Composed"":{""__StashInternalId"":""" + expectedInternalId + @"""},""AnotherProperty"":""another property""}"; serialised = new PreservedMemoryStream(); using(var sw = new StreamWriter(serialised)) sw.Write(jsonSource); expected = new IsolatedClass(); session.TrackedGraphForInternalId(expectedInternalId).Returns(expected); }