public void Builder_Should_Build_New_Poster_Instance() { var poster = new PosterBuilder() .Build(); Assert.NotNull(poster); }
public static void SendPosterToBrowser( PosterBuilder.Builder pb, HttpResponse resp, string posterFilename, PosterBuilder.ImgFormat.SupportedTypes outputFormat) { string filename = BuildFilename(posterFilename, outputFormat); resp.Clear(); // Ensure caching is off naturally resp.CacheControl = "no-cache"; resp.ContentType = PosterBuilder.ImgFormat.ToMimeType(outputFormat); resp.AddHeader("Content-Disposition", "attachment;filename=" + filename); // Call our image with our amendments and have it save to the response so we can send it back Bitmap bmp = pb.Render(); // Have the Poster build our new image and save the result to the outgoing response // ... have to do all this with MemoryStreams as PNG doesn't like being saved directly to HttpResponse.OutputStream // ... may as well do the same for all image types and be consistent using (Bitmap bitmap = pb.Render()) { using (MemoryStream ms = new MemoryStream()) { ImageFormat outFmt = PosterBuilder.ImgFormat.ToImageFormat(outputFormat); bmp.Save(ms, outFmt); ms.WriteTo(resp.OutputStream); } // using ms } // using pb // And of course, clear up after ourselves pb.Dispose(); resp.End(); }
public static string BuildFilename(string filenamePrefix, PosterBuilder.ImgFormat.SupportedTypes imgFormat) { string newFilename = ""; string extension = ""; extension = PosterBuilder.ImgFormat.ToFileExtension(imgFormat); newFilename = System.IO.Path.ChangeExtension(filenamePrefix, extension); return newFilename; }
public PosterTests() { _httpClientMock = new Mock <IHttpClient>(); var poster = new PosterBuilder() .AddHttpClient(_httpClientMock.Object) .Build(); _testGenericOrderService = poster.BuildService <IGenericOrderService>(); }
/// <summary> /// Adds <see cref="Poster"/> object to <see cref="IServiceCollection"/>. /// </summary> /// <param name="serviceCollection">The application service collection.</param> /// <param name="posterBuilderFactory">Factory of <see cref="PosterBuilder"/>.</param> /// <returns><see cref="IDiPosterBuilder"/>.</returns> public static IDiPosterBuilder AddPoster(this IServiceCollection serviceCollection, Func <PosterBuilder, Poster> posterBuilderFactory) { var posterBuilder = new PosterBuilder(); serviceCollection.AddSingleton <IPoster, Poster>(provider => { var httpClientFactory = provider.GetService <IHttpClientFactory>(); var contentSerializer = provider.GetService <IContentSerializer>(); if (httpClientFactory != null) { posterBuilder.AddHttpClientFactory(httpClientFactory); } if (contentSerializer != null) { posterBuilder.AddContentSerializer(contentSerializer); } return(posterBuilderFactory(posterBuilder)); }); return(new DefaultDiPosterBuilder(serviceCollection)); }