public async Task TestImageServiceAsync() { var wrappedImageService = new ImageServiceAsync(); var imageService = ServiceRef.Create <IImageService>(wrappedImageService); Assert.IsTrue(ServiceRef.TryGetWrappedObject <ImageServiceAsync>(imageService, out var returnedWrappedObject)); Assert.AreSame(wrappedImageService, returnedWrappedObject); //await imageService.GetOrDownloadAsync("https://myimage"); //Assert.AreEqual(1, imageService.Images.Count); //Assert.AreEqual("https://myimage", imageService.Images[0].Url); //Assert.IsTrue(imageService.Images[0].Data.Length > 0); var callTracer = new SimpleCallMonitorTracer(); ActionQueue.BeginMonitor(callTracer); try { await imageService.GetOrDownloadAsync("https://myimage"); Assert.AreEqual(1, imageService.Images.Count); } finally { ActionQueue.ExitMonitor(callTracer); } }
public void TestImageServiceAsyncMultiple() { var imageService = ServiceRef.Create <IImageService>(new ImageServiceAsync()); var callTracer = new SimpleCallMonitorTracer(); ActionQueue.BeginMonitor(callTracer); try { Task.WaitAll( Enumerable .Range(1, 5) .Select(i => Task.Factory.StartNew(async() => { await imageService.GetOrDownloadAsync("https://myimage" + i); })) .ToArray()); Assert.AreEqual(5, imageService.Images.Count); } finally { ActionQueue.ExitMonitor(callTracer); } }
public async Task TestImageServiceAsync() { var imageService = ServiceRef.Create <IImageService>(new ImageServiceAsync()); //await imageService.GetOrDownloadAsync("https://myimage"); //Assert.AreEqual(1, imageService.Images.Count); //Assert.AreEqual("https://myimage", imageService.Images[0].Url); //Assert.IsTrue(imageService.Images[0].Data.Length > 0); var callTracer = new SimpleCallMonitorTracer(); ActionQueue.BeginMonitor(callTracer); try { await imageService.GetOrDownloadAsync("https://myimage"); Assert.AreEqual(1, imageService.Images.Count); } finally { ActionQueue.ExitMonitor(callTracer); } }