public void Web_Service_For_Scan_Completion() { // pick a device to test var device = new LinqMetaData().Device.FirstOrDefault(x => x.ScansAvailable > 0); Assert.IsNotNull(device); // setup service call var output = new StringWriter(); var service = new ScanService(); var url = new Uri("http://localhost/" + service.GetProperties().Url + "/scancomplete", UriKind.Absolute); HttpContext.Current = new HttpContext( new HttpRequest(url.AbsolutePath, url.AbsoluteUri, url.Query), new HttpResponse(output)); HttpContext.Current.User = new RolePrincipal(new GenericIdentity(device.UniqueIdentifier)); Thread.CurrentPrincipal = HttpContext.Current.User; // report the completed scan var count = service.ScanComplete(new ScanRecord { ScanStartTime = DateTime.UtcNow, ScanType = ScanType.ClearViewScan }); // compare the completed count before and after Assert.AreEqual(device.ScansUsed + 1, count.ScansCompleted); }