public void Administrator_Can_Create_Rates()
        {
            // create a new rate
            var controller = Mock();

            controller.Invoke(x => x.EditRate(null, new ScanRate
            {
                ScanType        = ScanType.ClearViewScan,
                RatePerScan     = (decimal)12345.67,
                MinCountForRate = 10,
                MaxCountForRate = 20,
                EffectiveDate   = DateTime.UtcNow,
                IsActive        = true
            }));
            // confirm the rate was added
            var rate = new LinqMetaData().ScanRate.FirstOrDefault(x => x.RatePerScan == (decimal)12345.67);

            Assert.IsNotNull(rate);

            // check purchases output for use of the new rate
            var purchaseController = Mock <PurchaseController>();

            purchaseController.Invoke(x => x.Add(null, null));
            Assert.IsTrue(purchaseController.Response.Output.ToString().Contains("<option value=\"" + rate.ScanRateId + "\""));

            rate.Delete();
        }
        public void User_Creation_Sends_Email()
        {
            // create a user to use during the test
            Create_Edit_User(TestData.ServiceAdminUsername, true);

            var user     = TestData.ServiceAdminUser;
            var testUser = new LinqMetaData().User.FirstOrDefault(x => x.FirstName == TestValues["FirstName"]);

            Assert.IsNotNull(testUser);
            Thread.Sleep(5000); // wait for exchange to deliver the e-mail

            // check the inbox for the e-mail
            var imap     = SupportController.EnsureConnection(user);
            var msgCount = imap.SelectMailbox("INBOX").NumMsg;

            Assert.IsTrue(msgCount > 0);

            var msgs =
                imap.Search(SearchCondition.Deleted().Not()).Select(
                    x =>
                    imap.GetMessage(x, true, true,
                                    new[] { "date", "subject", "from", "content-type", "to", "cc", "message-id" }));
            var message =
                msgs.Where(x => x.Subject.Contains(ControllerRes.Account.Email_SubjectUserRegistration)).
                OrderByDescending(x => x.Date).FirstOrDefault();

            Assert.IsNotNull(message);

            message = imap.GetMessage(message.Uid, false, false);
            // make sure the link matches the current test user in the database
            var match = Regex.Match(message.Body, "RegistrationKey=(([a-zA-Z0-9]{2})+)");

            Assert.IsTrue(match.Success);

            var restriction =
                testUser.UserAccountRestrictions.Select(x => x.AccountRestriction).SingleOrDefault(
                    x => x.RestrictionKey == match.Groups[1].Value);

            Assert.IsNotNull(restriction);

            // make sure key is unique
            restriction = new LinqMetaData().AccountRestriction.Single(x => x.RestrictionKey == match.Groups[1].Value);
            Assert.IsNotNull(restriction);

            var ars = testUser.UserAccountRestrictions.Select(y => y.AccountRestriction).ToList();

            testUser.UserAccountRestrictions.DeleteMulti();
            ars.ForEach(y => y.Delete());
            // finally delete the test user
            testUser.Delete();
        }
Exemplo n.º 3
0
        protected void Create_Edit_Device(string username, bool dontDelete = false)
        {
            var location = TestData.EndUserLoc;

            // create a new device
            var controller = Mock();

            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(username));
            var request = controller.Mock(x => x.ControllerContext.HttpContext.Request);

            request.Setup(x => x.HttpMethod).Returns("POST");

            // fill in missing test values
            _testValues["OrganizationId"] = location.OrganizationId.ToString(CultureInfo.InvariantCulture);
            _testValues["LocationId"]     = location.LocationId.ToString(CultureInfo.InvariantCulture);

            // submit test values
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");
            var device = new LinqMetaData().Device.FirstOrDefault(x => x.SerialNumber == _testValues["SerialNumber"]);

            Assert.IsNotNull(device);

            // edit the device
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(username));
            request = controller.Mock(x => x.ControllerContext.HttpContext.Request);
            request.Setup(x => x.HttpMethod).Returns("POST");

            // set the locationId
            controller.RouteData.Values.Add("deviceId", device.DeviceId);

            // change the serial number of the device
            _testValues["SerialNumber"] = "DeviceTest1";
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");
            device = new LinqMetaData().Device.FirstOrDefault(x => x.SerialNumber == _testValues["SerialNumber"]);
            Assert.IsNotNull(device);

            if (dontDelete)
            {
                return;
            }
            // finally delete the testing data
            device.PurchaseHistories.DeleteMulti();
            device.Delete();
        }
Exemplo n.º 4
0
        public void Service_Administrator_Can_Set_Geocode()
        {
            // submit a new location without a name and get back an error
            var controller = Mock();

            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(TestData.ServiceAdminUsername));
            var request =
                controller.Mock <LocationController, HttpRequestBase>(
                    x => x.ControllerContext.HttpContext.Request);

            request.Setup(x => x.HttpMethod).Returns("POST");

            // fill in everything but the name
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");
            var location = new LinqMetaData().Location.FirstOrDefault(x => x.Name == _testValues["Name"]);

            Assert.IsNotNull(location);

            // test that geocode was automatically filled by our valid address above
            Assert.IsTrue(location.Latitude.HasValue);
            Assert.IsTrue(location.Longitude.HasValue);

            // test administrator can change values
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(TestData.ServiceAdminUsername));
            request = controller.Mock <LocationController, HttpRequestBase>(x => x.ControllerContext.HttpContext.Request);
            request.Setup(x => x.HttpMethod).Returns("POST");
            controller.RouteData.Values.Add("locationId", location.LocationId);

            // modify the geocode
            const decimal newGeocode = (decimal)55.2039;

            _testValues["Latitude"] = newGeocode.ToString(CultureInfo.InvariantCulture);
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");

            location = new LinqMetaData().Location.FirstOrDefault(x => x.Name == _testValues["Name"]);
            Assert.IsNotNull(location);
            Assert.AreEqual(newGeocode, location.Latitude);
            location.Delete();
        }
Exemplo n.º 5
0
        private void Create_Edit_Location(string username)
        {
            // create a new location
            var controller = Mock();

            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(username));
            var request =
                controller.Mock(x => x.ControllerContext.HttpContext.Request);

            request.Setup(x => x.HttpMethod).Returns("POST");

            // submit test values
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");
            var location = new LinqMetaData().Location.FirstOrDefault(x => x.Name == _testValues["Name"]);

            Assert.IsNotNull(location);

            // edit the location
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(username));
            request = controller.Mock(x => x.ControllerContext.HttpContext.Request);
            request.Setup(x => x.HttpMethod).Returns("POST");

            // set the locationId
            controller.RouteData.Values.Add("locationId", location.LocationId);

            // change the name of the location
            _testValues["Name"] = "EPICLocationTest1";
            request.SetupGet(x => x.Form).Returns(() => _testValues);

            controller.Invoke("Edit");
            location = new LinqMetaData().Location.FirstOrDefault(x => x.Name == _testValues["Name"]);
            Assert.IsNotNull(location);

            // finally delete
            location.Delete();
        }
Exemplo n.º 6
0
        public void Service_Administrator_Can_Modify_Available_Scans()
        {
            var location = TestData.EndUserLoc;

            var controller = Mock();

            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(TestData.ServiceAdminUsername));
            var request = controller.Mock(x => x.ControllerContext.HttpContext.Request);

            request.Setup(x => x.HttpMethod).Returns("POST");

            // fill in missing test values
            _testValues["OrganizationId"] = location.OrganizationId.ToString(CultureInfo.InvariantCulture);
            _testValues["LocationId"]     = location.LocationId.ToString(CultureInfo.InvariantCulture);

            // submit test values
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");
            var device = new LinqMetaData().Device.FirstOrDefault(x => x.SerialNumber == _testValues["SerialNumber"]);

            Assert.IsNotNull(device);
            Assert.AreEqual(1, device.PurchaseHistories.Count);

            // edit the device
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(TestData.ServiceAdminUsername));
            request = controller.Mock(x => x.ControllerContext.HttpContext.Request);
            request.Setup(x => x.HttpMethod).Returns("POST");

            // change the number of scans
            controller.RouteData.Values.Add("deviceId", device.DeviceId);

            // change the number of scans without the scan notes
            _testValues["ScansAvailable"] = "20";
            _testValues["PurchaseNotes"]  = null;

            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");
            device = new LinqMetaData().Device.FirstOrDefault(x => x.SerialNumber == _testValues["SerialNumber"]);
            Assert.IsNotNull(device);
            Assert.AreEqual(417, controller.Response.StatusCode);

            // change the number of scans with the purchase notes
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(TestData.ServiceAdminUsername));
            request = controller.Mock(x => x.ControllerContext.HttpContext.Request);
            request.Setup(x => x.HttpMethod).Returns("POST");
            controller.RouteData.Values.Add("deviceId", device.DeviceId);
            _testValues["ScansAvailable"] = "20";
            _testValues["PurchaseNotes"]  = "This is an available scans changed test.";
            request.SetupGet(x => x.Form).Returns(() => _testValues);
            controller.Invoke("Edit");

            device = new LinqMetaData().Device.FirstOrDefault(x => x.SerialNumber == _testValues["SerialNumber"]);
            Assert.IsNotNull(device);
            Assert.AreEqual(20, device.ScansAvailable);
            Assert.AreEqual(2, device.PurchaseHistories.Count);

            // finally delete the testing data
            device.PurchaseHistories.DeleteMulti();
            device.Delete();
        }
        protected void Create_Edit_User(string username, bool dontDelete = false)
        {
            var user = new LinqMetaData().User.Single(x => x.Username == username);

            // get the location for the input username
            var organization = new LinqMetaData().Organization.First(x => x.Users.Any(y => y.Username == username));

            // make sure the user inbox is accessible
            var profile = new UserSettingEntity(user.UserId, "SupportUser")
            {
                UserId = user.UserId, Name = "SupportUser"
            };

            Assert.IsFalse(profile.IsNew);

            // set up a new user account with the email address set to the same as the passed in user
            var controller = Mock();

            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(username));
            var request = controller.Mock(x => x.ControllerContext.HttpContext.Request);

            request.Setup(x => x.HttpMethod).Returns("POST");

            // fill in the missing user values
            TestValues["OrganizationId"] = organization.OrganizationId.ToString(CultureInfo.InvariantCulture);
            TestValues["Role"]           = OrganizationUtils.GetAllowedRoles(organization.OrganizationId)
                                           .First().RoleId.ToString(CultureInfo.InvariantCulture);
            // set the e-mail address equal to the passed in user support center e-mail
            TestValues["EmailAddress"] = profile.Value + '@' + SupportController.DOMAIN;

            // submit test values
            request.SetupGet(x => x.Form).Returns(() => TestValues);
            controller.Invoke("Add");
            var testUser = new LinqMetaData().User.FirstOrDefault(x => x.FirstName == TestValues["FirstName"]);

            Assert.IsNotNull(testUser);

            // try to edit the user
            controller = Mock();
            controller.HttpContext.User = new RolePrincipal(new GenericIdentity(username));
            request = controller.Mock(x => x.ControllerContext.HttpContext.Request);
            request.Setup(x => x.HttpMethod).Returns("POST");

            // set the userId
            controller.RouteData.Values.Add("userId", testUser.UserId);

            // username cannot be changed because registration is still pending at this point
            // just edit the first name
            TestValues["FirstName"] = "UserTest1";
            TestValues["IsActive"]  = "true";
            TestValues["UserName"]  = "******";
            request.SetupGet(x => x.Form).Returns(() => TestValues);
            controller.Invoke("Edit");
            testUser = new LinqMetaData().User.FirstOrDefault(x => x.FirstName == TestValues["FirstName"]);
            Assert.IsNotNull(testUser);

            // don't delete for further testing by the caller, which is responsible for cleanup
            if (!dontDelete)
            {
                var ars = testUser.UserAccountRestrictions.Select(y => y.AccountRestriction).ToList();
                testUser.UserAccountRestrictions.DeleteMulti();
                ars.ForEach(y => y.Delete());
                // finally delete the test user
                testUser.Delete();
            }
        }