public void UpconvertGivenUpconverterAToBAndCAndUpconvertCToD_WithEventA_ShouldReturnEventBAndEventD() { // Arrange var sut = new Arrangements() .AddUpconverter <EventA>(UpconvertMethod) .AddUpconverter <EventC, EventD>(x => new EventD(x.Count)) .BuildAndGetSUT(); var source = new EventA("Mr. Silly Name", 4); var expectedB = new EventB(source.Name, source.Count); var expectedD = new EventD(source.Count); // Act var upconverted = sut.Upconvert(new [] { new ItemWithType(source) }); // Assert upconverted.Should().NotBeNullOrEmpty(); upconverted.Count().Should().Be(2); upconverted.ToArray()[0].type.Should().Be <EventB>(); upconverted.ToArray()[0].instance.As <EventB>().MyName.Should().Be(expectedB.MyName); upconverted.ToArray()[0].instance.As <EventB>().Count.Should().Be(expectedB.Count); upconverted.ToArray()[1].type.Should().Be <EventD>(); upconverted.ToArray()[1].instance.As <EventD>().MyCount.Should().Be(expectedD.MyCount); IEnumerable <object> UpconvertMethod(EventA a) { yield return(new EventB(a.Name, a.Count)); yield return(new EventC(a.Count)); } }
GetFromTypes_WithwithOneUpconverterInChainFromEventAToEventB_ShouldReturnDictionaryWithOneUpconvertFromEventAToEventB() { // Arrange var types = new[] { typeof(UpconverterAToB) }; UpconvertFunc upconverter = null; var originalEvent = new EventA("Mr. Silly Name", 5); var expectedEvent = new EventB(originalEvent.Name, originalEvent.Count); // Act upconverter = UpconverterCompiler.GetFrom(types)[typeof(EventA)]; // Assert upconverter.Should().NotBeNull(); upconverter(new ItemWithType(originalEvent)).isSingleItem.Should().BeTrue(); upconverter(new ItemWithType(originalEvent)).single.type.Should().Be <EventB>(); upconverter(new ItemWithType(originalEvent)).single.instance.As <EventB>().MyName.Should().Be(expectedEvent.MyName); upconverter(new ItemWithType(originalEvent)).single.instance.As <EventB>().Count.Should().Be(expectedEvent.Count); }
public void UpconvertGivenUpconverterAToB_WithEventA_ShouldReturnEventB() { // Arrange var sut = new Arrangements() .AddUpconverter <EventA, EventB>(a => new EventB(a.Name, a.Count)) .BuildAndGetSUT(); var source = new EventA("Mr. Silly Name", 5); var expected = new EventB(source.Name, source.Count); // Act var upconverted = sut.Upconvert(new ItemWithType[] { new ItemWithType(source) }); // Assert upconverted.Should().NotBeNullOrEmpty(); upconverted.Count().Should().Be(1); upconverted.First().type.Should().Be <EventB>(); upconverted.First().instance.As <EventB>().MyName.Should().Be(expected.MyName); upconverted.First().instance.As <EventB>().Count.Should().Be(expected.Count); }
public void UpconvertGivenUpconverterAToBAndUpconvertBToC_WithEventA_ShouldReturnEventC() { // Arrange var sut = new Arrangements() .AddUpconverter <EventA, EventB>(x => new EventB(x.Name, x.Count)) .AddUpconverter <EventB, EventC>(x => new EventC(x.Count)) .BuildAndGetSUT(); var source = new EventA("Mr. Silly Name", 4); var expected = new EventC(source.Count); // Act var upconverted = sut.Upconvert(new ItemWithType[] { new ItemWithType(source) }); // Assert upconverted.Should().NotBeNullOrEmpty(); upconverted.Count().Should().Be(1); upconverted.ToArray()[0].type.Should().Be <EventC>(); upconverted.ToArray()[0].instance.As <EventC>().Count.Should().Be(expected.Count); }
public void GetFromTypes_WithwithOneMultiEventUpconverterFromAToBAndC_ShouldReturnDictionaryWithUpconvertFromAToEnumerableWithBAndC() { var types = new[] { typeof(UpconverterAToBAndC) }; UpconvertFunc upconverter = null; var originalEvent = new EventA("Mr. Silly Name", 5); var expectedB = new EventB(originalEvent.Name, originalEvent.Count); var expectedC = new EventC(originalEvent.Count); // Act upconverter = UpconverterCompiler.GetFrom(types)[typeof(EventA)]; var result = upconverter(new ItemWithType(originalEvent)); // Assert upconverter.Should().NotBeNull(); result.isSingleItem.Should().BeFalse(); result.multiple.ToArray()[0].type.Should().Be <EventB>(); result.multiple.ToArray()[0].instance.As <EventB>().Count.Should().Be(expectedB.Count); result.multiple.ToArray()[0].instance.As <EventB>().MyName.Should().Be(expectedB.MyName); result.multiple.ToArray()[1].type.Should().Be <EventC>(); result.multiple.ToArray()[1].instance.As <EventC>().Count.Should().Be(expectedC.Count); }