Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void Web_Service_For_Scans_Available()
        {
            // 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 + "/getcount", 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;

            // get count reported by service
            var count = service.GetCount();

            // compare service count to device from database
            Assert.AreEqual(device.ScansAvailable, count.ScansAvailable);
        }