public void NewToOld() //strong to weak { IList<MassTransit.ServiceBus.Subcriptions.Subscription> subs = new List<MassTransit.ServiceBus.Subcriptions.Subscription>(); subs.Add(new MassTransit.ServiceBus.Subcriptions.Messages.Subscription("the_message", new Uri("http://bob/phil"))); var oldMsg = new MassTransit.ServiceBus.Subcriptions.Messages.OldCacheUpdateResponse(subs); var oldold = Factory.ConvertToOldCacheUpdateResponse(oldMsg); using (var newStream = new MemoryStream()) { PlainFormatter.Serialize(newStream, oldold); newStream.Position = 0; using (var oldStream = new MemoryStream()) { using (var str = File.OpenRead(_pathToFile)) { var buff = new byte[str.Length]; str.Read(buff, 0, buff.Length); oldStream.Write(buff, 0, buff.Length); } var newFileName = ".\\new-{0}.txt".FormatWith(oldMsg.GetType().Name); if(File.Exists(newFileName)) File.Delete(newFileName); using(var fs = File.OpenWrite(newFileName)) { fs.Write(newStream.ToArray(), 0, newStream.ToArray().Length); } //TODO: Hmmm Weird Assert.AreEqual(oldStream.Length, newStream.Length - 2); //StreamAssert.AreEqual(oldStream, newStream); } } }
public void NewToOld() //strong to weak { IList <MassTransit.ServiceBus.Subcriptions.Subscription> subs = new List <MassTransit.ServiceBus.Subcriptions.Subscription>(); subs.Add(new MassTransit.ServiceBus.Subcriptions.Messages.Subscription("the_message", new Uri("http://bob/phil"))); var oldMsg = new MassTransit.ServiceBus.Subcriptions.Messages.OldCacheUpdateResponse(subs); var oldold = Factory.ConvertToOldCacheUpdateResponse(oldMsg); using (var newStream = new MemoryStream()) { PlainFormatter.Serialize(newStream, oldold); newStream.Position = 0; using (var oldStream = new MemoryStream()) { using (var str = File.OpenRead(_pathToFile)) { var buff = new byte[str.Length]; str.Read(buff, 0, buff.Length); oldStream.Write(buff, 0, buff.Length); } var newFileName = ".\\new-{0}.txt".FormatWith(oldMsg.GetType().Name); if (File.Exists(newFileName)) { File.Delete(newFileName); } using (var fs = File.OpenWrite(newFileName)) { fs.Write(newStream.ToArray(), 0, newStream.ToArray().Length); } //TODO: Hmmm Weird Assert.AreEqual(oldStream.Length, newStream.Length - 2); //StreamAssert.AreEqual(oldStream, newStream); } } }