public void UpconvertGivenUpconverterAToBAndC_WithEventA_ShouldReturnEventBAndEventC() { // Arrange var sut = new Arrangements() .AddUpconverter <EventA>(UpconvertMethod) .BuildAndGetSUT(); var source = new EventA("Mr. Silly Name", 4); var expectedB = new EventB(source.Name, source.Count); var expectedC = new EventC(source.Count); // Act var upconverted = sut.Upconvert(new ItemWithType[] { 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 <EventC>(); upconverted.ToArray()[1].instance.As <EventC>().Count.Should().Be(expectedC.Count); IEnumerable <object> UpconvertMethod(EventA a) { yield return(new EventB(a.Name, a.Count)); yield return(new EventC(a.Count)); } }
public void UpconvertGivenUpconverterAToBAndUpconvertBToC_WithEventB_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 EventB("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); }