Exemplo n.º 1
0
        public void GetByEmptyModelTest()
        {
            var service = new SubstancesService();
            var model   = new Models.Search.QueryModel();
            var result  = service.GetByQuery(model);

            Assert.True(result.Count == 100, "return first 100 elements from db if model is empty");
        }
Exemplo n.º 2
0
        public void GetByUnreachableVapourPressurTest()
        {
            const double VapourPressur = 0.158;
            var          service       = new SubstancesService();
            var          model         = new Models.Search.QueryModel();

            model.vp1 = VapourPressur;
            model.vp2 = 0;

            var result = service.GetByQuery(model);

            Assert.True(result.Count == 0);
        }
Exemplo n.º 3
0
        public void GetByUnreachableRefractiveIndexTest()
        {
            const double RefractiveIndex = 1.329;
            var          service         = new SubstancesService();
            var          model           = new Models.Search.QueryModel();

            model.ri1 = RefractiveIndex;
            model.ri2 = 0;

            var result = service.GetByQuery(model);

            Assert.True(result.Count == 0);
        }
Exemplo n.º 4
0
        public void GetByUnreachableDensityTest()
        {
            const int density = 1;
            var       service = new SubstancesService();
            var       model   = new Models.Search.QueryModel();

            model.d1 = density;
            model.d2 = 0;

            var result = service.GetByQuery(model);

            Assert.True(result.Count == 0);
        }
Exemplo n.º 5
0
        public void GetByUnreachableFlashPointTest()
        {
            const int flashpoint = 100;
            var       service    = new SubstancesService();
            var       model      = new Models.Search.QueryModel();

            model.fp1 = flashpoint;
            model.fp2 = 0;

            var result = service.GetByQuery(model);

            Assert.True(result.Count == 0);
        }
Exemplo n.º 6
0
        public void GetByUnreachableMeltingPointTest()
        {
            const int MeltingPoint = 0;
            var       service      = new SubstancesService();
            var       model        = new Models.Search.QueryModel();

            model.mp1 = MeltingPoint;
            model.mp2 = -10;

            var result = service.GetByQuery(model);

            Assert.True(result.Count == 0);
        }
Exemplo n.º 7
0
        public void GetByVapourPressurLessThanTest()
        {
            const double VapourPressur = 0.158;
            var          service       = new SubstancesService();
            var          model         = new Models.Search.QueryModel();

            model.vp2 = VapourPressur;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.VapourPressur <= VapourPressur);
            }
        }
Exemplo n.º 8
0
        public void GetByRefractiveIndexLessThanTest()
        {
            const double RefractiveIndex = 1.329;
            var          service         = new SubstancesService();
            var          model           = new Models.Search.QueryModel();

            model.ri2 = RefractiveIndex;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.RefractiveIndex <= RefractiveIndex);
            }
        }
Exemplo n.º 9
0
        public void GetByMeltingPointLessThanTest()
        {
            const int MeltingPoint = 0;
            var       service      = new SubstancesService();
            var       model        = new Models.Search.QueryModel();

            model.mp2 = MeltingPoint;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.MeltingPoint <= MeltingPoint);
            }
        }
Exemplo n.º 10
0
        public void GetByFlashPointThanTest()
        {
            const int flashpoint = 100;
            var       service    = new SubstancesService();
            var       model      = new Models.Search.QueryModel();

            model.fp1 = flashpoint;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.FlashPoint >= flashpoint);
            }
        }
Exemplo n.º 11
0
        public void GetByDensityLessThanTest()
        {
            const int density = 1;
            var       service = new SubstancesService();
            var       model   = new Models.Search.QueryModel();

            model.d2 = density;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.Density <= density);
            }
        }
Exemplo n.º 12
0
        public void GetByBoilingPointGreatThanTest()
        {
            const int boilingPoint = 10;
            var       service      = new SubstancesService();
            var       model        = new Models.Search.QueryModel();

            model.bp1 = boilingPoint;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.BoilingPoint >= boilingPoint);
            }
        }
Exemplo n.º 13
0
        public void GetByWaterUnSolubilityTest()
        {
            const bool WaterSolubility = false;
            var        service         = new SubstancesService();
            var        model           = new Models.Search.QueryModel();

            model.ws = WaterSolubility;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.WaterSolubility == "нет");
            }
        }
Exemplo n.º 14
0
        public void GetByValidNameTest()
        {
            const string name    = "вода";
            var          service = new SubstancesService();
            var          model   = new Models.Search.QueryModel();

            model.q = name;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.Names.Any(x => x.ToLower().Contains(name)));
            }
        }
Exemplo n.º 15
0
        public void GetByValidFormulaWithDigitsTest()
        {
            const string Formula = "C28H38O19";
            var          service = new SubstancesService();
            var          model   = new Models.Search.QueryModel();

            model.q = Formula;

            var result = service.GetByQuery(model);

            Assert.True(result.Count > 0);
            foreach (var previewElem in result)
            {
                var elem = service.GetById(previewElem.Id);
                Assert.True(elem.Formula == Formula);
            }
        }
Exemplo n.º 16
0
        public void GetByEqualFormulasTest()
        {
            const string Formula         = "C2H5OH";
            const string extendedFormula = "C2H5OH";
            const string foldedFormula   = "C2H6O";
            var          service         = new SubstancesService();
            var          model           = new Models.Search.QueryModel();

            model.q = Formula;

            var resultByFormula = service.GetByQuery(model);

            model.q = extendedFormula;
            var resultByExtendedFormula = service.GetByQuery(model);

            model.q = foldedFormula;
            var resultByFoldedFormula = service.GetByQuery(model);

            Assert.True(resultByFormula.Count > 0);
            Assert.True(resultByFormula.Select(x => x.Id).SequenceEqual(resultByExtendedFormula.Select(x => x.Id)));
            Assert.True(resultByFormula.Select(x => x.Id).SequenceEqual(resultByFoldedFormula.Select(x => x.Id)));
        }
Exemplo n.º 17
0
        public virtual ActionResult Query(string term, string limit = null, bool searchDetails = false)
        {
            term = term.Trim();
            int termInt;
            if (!int.TryParse(term, out termInt))
                termInt = -1;

            var m = new Models.Search.QueryModel() { Term = term };

            if (string.IsNullOrEmpty(term))
            {
                m.Success = false;
                m.ErrorMessage = "A search term is required";
                return View(m);
            }

            m.Success = true;

            // Deal with !/@/# Search Shortcuts
            if (limit == null && term.Length > 0)
            {
                switch (term[0])
                {
                    case '!':
                        term = term.Substring(1);
                        limit = "DeviceSerialNumber";
                        break;
                    case '#':
                        term = term.Substring(1);
                        limit = "JobId";
                        if (!int.TryParse(term, out termInt))
                            termInt = -1;
                        break;
                    case '@':
                        term = term.Substring(1);
                        limit = "UserId";
                        break;
                }
            }

            if (limit == null)
            {
                if (term.Length < 2 && termInt < 0) // < 2 Characters && Not a Number
                {
                    m.Success = false;
                    m.ErrorMessage = "A search term of at least two characters is required";
                    return View(m);
                }
                if (Authorization.Has(Claims.Job.Search))
                    m.Jobs = Services.Searching.Search.SearchJobsTable(Database, term, LimitCount: null, IncludeJobStatus: true, SearchDetails: searchDetails);

                if (Authorization.Has(Claims.Device.Search))
                    m.Devices = Services.Searching.Search.SearchDevices(Database, term, LimitCount: null, SearchDetails: searchDetails);

                if (Authorization.Has(Claims.User.Search))
                    m.Users = Services.Searching.Search.SearchUsers(Database, term, true, LimitCount: null);
            }
            else
            {
                switch (limit.ToLower())
                {
                    case "devicemodel":
                        Authorization.Require(Claims.Device.Search);
                        int deviceModelId;
                        if (int.TryParse(term, out deviceModelId))
                        {
                            var vm = Database.DeviceModels.Find(deviceModelId);
                            if (vm != null)
                            {
                                m.FriendlyTerm = string.Format("Device Model: {0}", vm.ToString());
                                m.Devices = Services.Searching.Search.SearchDeviceModel(Database, vm.Id);
                                break;
                            }
                        }
                        m.FriendlyTerm = string.Format("Device Model: {0}", term);
                        m.Success = false;
                        m.ErrorMessage = "Invalid Device Model Id";
                        break;
                    case "deviceprofile":
                        Authorization.Require(Claims.Device.Search);
                        int deviceProfileId;
                        if (int.TryParse(term, out deviceProfileId))
                        {
                            var dp = Database.DeviceProfiles.Find(deviceProfileId);
                            if (dp != null)
                            {
                                m.FriendlyTerm = string.Format("Device Profile: {0}", dp.ToString());
                                m.Devices = Services.Searching.Search.SearchDeviceProfile(Database, dp.Id);
                                break;
                            }
                        }
                        m.FriendlyTerm = string.Format("Device Profile: {0}", term);
                        m.Success = false;
                        m.ErrorMessage = "Invalid Device Profile Id";
                        break;
                    case "devicebatch":
                        Authorization.Require(Claims.Device.Search);
                        int deviceBatchId;
                        if (int.TryParse(term, out deviceBatchId))
                        {
                            var db = Database.DeviceBatches.Find(deviceBatchId);
                            if (db != null)
                            {
                                m.FriendlyTerm = string.Format("Device Batch: {0}", db.ToString());
                                m.Devices = Services.Searching.Search.SearchDeviceBatch(Database, db.Id);
                                break;
                            }
                        }
                        m.FriendlyTerm = string.Format("Device Batch: {0}", term);
                        m.Success = false;
                        m.ErrorMessage = "Invalid Device Batch Id";
                        break;
                    case "devices":
                        Authorization.Require(Claims.Device.Search);
                        if (term.Length < 2)
                        {
                            m.Success = false;
                            m.ErrorMessage = "A search term of at least two characters is required";
                            return View(m);
                        }
                        m.Devices = Services.Searching.Search.SearchDevices(Database, term, null, searchDetails);
                        if (m.Devices.Count == 1)
                        {
                            return RedirectToAction(MVC.Device.Show(m.Devices[0].Id));
                        }
                        break;
                    case "jobs":
                        Authorization.Require(Claims.Job.Search);
                        if (term.Length < 2 && termInt < 0)
                        {
                            m.Success = false;
                            m.ErrorMessage = "A search term of at least two characters is required";
                            return View(m);
                        }
                        if (termInt >= 0)
                        { // Term is a Number - Check for JobId
                            if (Database.Jobs.Count(j => j.Id == termInt) == 1)
                            {
                                return RedirectToAction(MVC.Job.Show(termInt));
                            }
                        }
                        m.Jobs = Services.Searching.Search.SearchJobsTable(Database, term, LimitCount: null, IncludeJobStatus: true, SearchDetails: searchDetails);
                        break;
                    case "users":
                        Authorization.Require(Claims.User.Search);
                        if (term.Length < 2)
                        {
                            m.Success = false;
                            m.ErrorMessage = "A search term of at least two characters is required";
                            return View(m);
                        }
                        m.Users = Services.Searching.Search.SearchUsers(Database, term, true, LimitCount: null);
                        if (m.Users.Count == 1)
                        {
                            return RedirectToAction(MVC.User.Show(m.Users[0].Id));
                        }
                        break;
                    case "deviceserialnumber":
                        Authorization.Require(Claims.Device.Search);
                        var device = Database.Devices.FirstOrDefault(d => d.SerialNumber == term);
                        if (device != null)
                            return RedirectToAction(MVC.Device.Show(term));
                        else
                        {
                            m.Success = false;
                            m.ErrorMessage = "Unknown Device Serial Number";
                            return View(m);
                        }
                    case "jobid":
                        Authorization.Require(Claims.Job.Search);
                        if (termInt >= 0)
                        {
                            var job = Database.Jobs.FirstOrDefault(d => d.Id == termInt);
                            if (job != null)
                                return RedirectToAction(MVC.Job.Show(termInt));
                            else
                            {
                                m.Success = false;
                                m.ErrorMessage = "Unknown Job Number";
                                return View(m);
                            }
                        }
                        else
                        {
                            m.Success = false;
                            m.ErrorMessage = "Invalid Job Number";
                            return View(m);
                        }
                    case "userid":
                        Authorization.Require(Claims.User.Search);

                        term = ActiveDirectory.ParseDomainAccountId(term);

                        var user = Database.Users.FirstOrDefault(u => u.UserId == term);
                        if (user != null)
                            return RedirectToAction(MVC.User.Show(term));
                        else
                        {
                            try
                            {
                                user = UserService.GetUser(term, Database);
                                if (user != null)
                                    return RedirectToAction(MVC.User.Show(term));
                                else
                                {
                                    m.Success = false;
                                    m.ErrorMessage = "Unknown User Id";
                                    return View(m);
                                }
                            }
                            catch (ArgumentException)
                            {
                                m.Success = false;
                                m.ErrorMessage = "Unknown User Id";
                                return View(m);
                            }
                        }
                    case "userflag":
                        Authorization.RequireAll(Claims.User.Search, Claims.User.ShowFlagAssignments);
                        int flagId;
                        if (int.TryParse(term, out flagId))
                        {
                            var flag = Database.UserFlags.Find(flagId);
                            if (flag != null)
                            {
                                m.FriendlyTerm = string.Format("User Flag: {0}", flag.ToString());
                                m.Users = Services.Searching.Search.SearchUserFlag(Database, flag.Id);
                                break;
                            }
                        }
                        m.FriendlyTerm = string.Format("User Flag: {0}", term);
                        m.Success = false;
                        m.ErrorMessage = "Invalid User Flag Id";
                        break;
                }
            }

            // UI Extensions
            UIExtensions.ExecuteExtensions<SearchQueryModel>(this.ControllerContext, m);

            return View(m);
        }