public void AddReportConverter_WithoutName_FactoryIsNotRegistered() { ServiceProvider serviceProvider = new ServiceCollection() .AddReportConverter <HtmlCell, IHtmlPropertyHandler>() .BuildServiceProvider(); IReportConverterFactory <HtmlCell> converterFactory = serviceProvider.GetService <IReportConverterFactory <HtmlCell> >(); converterFactory.Should().BeNull(); }
public void AddReportConverter_ConverterWithName_CanBeRequested() { ServiceProvider serviceProvider = new ServiceCollection() .AddReportConverter <HtmlCell>("name") .BuildServiceProvider(); IReportConverterFactory <HtmlCell> converterFactory = serviceProvider.GetService <IReportConverterFactory <HtmlCell> >(); converterFactory.Should().NotBeNull(); IReportConverter <HtmlCell> converter = converterFactory.Get("name"); converter.Should().NotBeNull(); }
public void AddReportConverter_ConverterWithWrongName_ThrowsException() { const string correctName = "name"; const string wrongName = "another"; ServiceProvider serviceProvider = new ServiceCollection() .AddReportConverter <HtmlCell>(correctName) .BuildServiceProvider(); IReportConverterFactory <HtmlCell> converterFactory = serviceProvider.GetService <IReportConverterFactory <HtmlCell> >(); converterFactory.Should().NotBeNull(); Action action = () => converterFactory.Get(wrongName); action.Should().Throw <ArgumentException>(); }
public void AddReportConverter_ConverterWithInterfaceAndName_HasHandlersImplementingInterface() { ServiceProvider serviceProvider = new ServiceCollection() .AddReportConverter <HtmlCell, IHtmlPropertyHandler>("name") .BuildServiceProvider(); IReportConverterFactory <HtmlCell> converterFactory = serviceProvider.GetService <IReportConverterFactory <HtmlCell> >(); converterFactory.Should().NotBeNull(); IReportConverter <HtmlCell> converter = converterFactory.Get("name"); (converter as ReportConverter <HtmlCell>)?.Handlers.Should() .HaveCount(2) .And.AllBeAssignableTo <IHtmlPropertyHandler>(); }
public void AddReportConverter_ConverterWithHandlerAndName_HasHandler() { HtmlCellHandler cellHandler = new HtmlCellHandler(); ServiceProvider serviceProvider = new ServiceCollection() .AddReportConverter <HtmlCell>("name", cellHandler) .BuildServiceProvider(); IReportConverterFactory <HtmlCell> converterFactory = serviceProvider.GetService <IReportConverterFactory <HtmlCell> >(); converterFactory.Should().NotBeNull(); IReportConverter <HtmlCell> converter = converterFactory.Get("name"); (converter as ReportConverter <HtmlCell>)?.Handlers.Should() .Equal(cellHandler); }
public void AddReportConverter_ConverterWithHandlerAndInterfaceAndName_HasHandlerAndAllHandlersImplementingInterface() { HtmlCellHandler cellHandler = new HtmlCellHandler(); ServiceProvider serviceProvider = new ServiceCollection() .AddReportConverter <HtmlCell, IHtmlPropertyHandler>("name", cellHandler) .BuildServiceProvider(); IReportConverterFactory <HtmlCell> converterFactory = serviceProvider.GetService <IReportConverterFactory <HtmlCell> >(); converterFactory.Should().NotBeNull(); IReportConverter <HtmlCell> converter = converterFactory.Get("name"); (converter as ReportConverter <HtmlCell>)?.Handlers.Should() .HaveCount(3) .And.Contain(h => h == cellHandler || h is IHtmlPropertyHandler); }