зеркало из https://github.com/microsoft/Tx.git
Added 1 to many behavior for composite deserializer
This commit is contained in:
Родитель
12e3dcda23
Коммит
6f8570fccb
|
@ -5,5 +5,5 @@ using System.Reflection;
|
|||
[assembly: AssemblyCompany("MS Open Tech")]
|
||||
[assembly: AssemblyProduct("Tx (LINQ to Logs and Traces)")]
|
||||
[assembly: AssemblyCopyright("Copyright © MS Open Tech 2012")]
|
||||
[assembly: AssemblyVersion("1.0.51208.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.51208.0")]
|
||||
[assembly: AssemblyVersion("1.0.51230.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.51230.0")]
|
|
@ -101,7 +101,6 @@ namespace System.Reactive
|
|||
return;
|
||||
|
||||
_observer.OnNext(ts);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
namespace Tests.Tx
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
[TestClass]
|
||||
public class CompositeDeserializerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void DeserializeIntoMultipleTargets()
|
||||
{
|
||||
var cache = new List<Timestamped<object>>();
|
||||
|
||||
var deserializer = new CompositeDeserializer<Envelope>(
|
||||
Observer.Create<Timestamped<object>>(item => cache.Add(item)),
|
||||
new EnvelopeTestTypeMap(),
|
||||
new SystemClockTypeMap<Envelope>())
|
||||
{
|
||||
EndTime = DateTime.MaxValue
|
||||
};
|
||||
|
||||
deserializer.AddKnownType(typeof(string));
|
||||
deserializer.AddKnownType(typeof(Envelope));
|
||||
|
||||
deserializer.OnNext(new Envelope { Data = "data" });
|
||||
|
||||
Assert.AreEqual(2, cache.Count);
|
||||
Assert.IsInstanceOfType(cache[0].Value, typeof(string));
|
||||
Assert.IsInstanceOfType(cache[1].Value, typeof(Envelope));
|
||||
}
|
||||
|
||||
private sealed class EnvelopeTestTypeMap : ITypeMap<Envelope>
|
||||
{
|
||||
public Func<Envelope, DateTimeOffset> TimeFunction
|
||||
{
|
||||
get
|
||||
{
|
||||
return e => DateTimeOffset.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
public Func<Envelope, object> GetTransform(Type outputType)
|
||||
{
|
||||
return envelope => envelope.Data;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Envelope
|
||||
{
|
||||
public string Data;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -68,6 +68,7 @@
|
|||
</Compile>
|
||||
<Compile Include="BinaryEtw\BondEtwObserverTests.cs" />
|
||||
<Compile Include="BinaryEtw\GeneralPartitionableTypeMapTests.cs" />
|
||||
<Compile Include="CompositeDeserializerTests.cs" />
|
||||
<Compile Include="DemultiplexorTest.cs" />
|
||||
<Compile Include="EtwDeserializerTest.cs" />
|
||||
<Compile Include="EtwGeneration.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче