public void UT_Mtch() { boot.Init(); var model = mod.sr.SetModel(boot, initSupl: false); Assert.IsTrue(model.elmGroups.Count > 0); Assert.IsTrue(model.Rules.Count > 0); var Rules = model.Rules.ToList(); var grps = model.elmGroups.ToList(); // test 1 Уголок L50x5 -> цена 7 209 руб Rule.Rule rule = Rules.Find(x => x.sCS.Contains("Уголок")); Group.Group gr = grps.Find(x => x.Prf.Contains("L")); if (rule != null && gr != null) { rule.Init(); var m = new Mtch(gr, rule); Assert.IsTrue(gr.totalPrice > 7000); double rubPerKg = gr.totalPrice / gr.totalWeight; Assert.IsTrue(rubPerKg > 20); } // test 2 Полоса -30 из Листа ЛСС rule = Rules.Find(x => x.sCS.Contains("Лист")); gr = grps.Find(x => x.Prf.Contains("—")); if (rule != null && gr != null) { rule.Init(); var m = new Mtch(gr, rule); Assert.IsTrue(gr.totalPrice > 7000); double rubPerKg = gr.totalPrice / gr.totalWeight; Assert.IsTrue(rubPerKg > 20); } // test 3 Бетон rule = Rules.Find(x => x.sCS.Contains("бетон")); gr = grps.Find(x => x.mat.Contains("b")); if (rule != null && gr != null) { rule.Init(); var m = new Mtch(gr, rule); Assert.IsTrue(gr.totalPrice > 7000); double rubPerM3 = gr.totalPrice / gr.totalVolume; //.totalWeight; Assert.IsTrue(rubPerM3 > 2000); } //foreach (var gr in model.elmGroups) //{ // Assert.IsTrue(model.Rules.Count > 0); // foreach (var rule in model.Rules) // { // Assert.IsNotNull(rule.CompSet.Supplier); // Assert.IsTrue(rule.CompSet.Components.Count > 0); // Mtch _match = new Mtch(gr, rule); // } //} FileOp.AppQuit(); }
public void UT_comp_PL_Native() { boot.Init(); // test 1 Native: берем группу, правила и компонент - пластину PL8 из модели model = model.sr.SetModel(boot); if (model.name != "Chasovnya+lepestok") goto exit; gr = model.elmGroups[23]; Assert.AreEqual("—8", gr.prf); rule = new Rule.Rule(6); Assert.AreEqual(58, rule.text.Length); rule.Init(); Assert.AreEqual(93, rule.CompSet.Components.Count); comp = rule.CompSet.Components[60]; Assert.AreEqual("С245", comp.Str(SType.Material)); Assert.AreEqual("PL8x100", comp.Str(SType.Profile)); bool b = comp.isMatch(gr, rule); Assert.IsTrue(b); //test 2 Native: обрабатываем все группы, но проверяем только нужную - PL8 Mtch _mtch = null; foreach (var g in model.elmGroups) { _mtch = new Mtch(g, rule); if (g.prf != "—8") continue; Assert.AreEqual(Mtch.OK.Match, _mtch.ok); } //test 3 Native: загружаем несколько Правил model.Rules.Clear(); rule = new Rule.Rule(5); rule.Init(); model.Rules.Add(rule); rule = new Rule.Rule(6); rule.Init(); model.Rules.Add(rule); _mtch = null; Mtch found_mtch = null; foreach (var g in model.elmGroups) { foreach (var r in model.Rules) { _mtch = new Mtch(g, r); if (g.prf != "—8" || !r.text.Contains("—")) continue; Assert.AreEqual(Mtch.OK.Match, _mtch.ok); found_mtch = _mtch; break; } } Assert.AreEqual("Полоса", found_mtch.rule.sCS); //test 4 Native with Handle, init all rules model.Rules.Clear(); model.matches.Clear(); Docs rRule = Docs.getDoc("Rules", fatal: false, create_if_notexist: false); for (int i = 4; i < rRule.il; i++) { rule = new Rule.Rule(i); rule.Init(); model.Rules.Add(rule); } model.mh.Hndl(ref model); foreach (var m in model.matches) { if (m.group.prf != "—8") continue; Assert.AreEqual(Mtch.OK.Match, m.ok); Assert.AreEqual("Полоса", m.rule.sCS); Assert.AreEqual("СтальХолдинг", m.rule.sSupl); } //test 5 Native with Pricing model.Rules.Clear(); model.matches.Clear(); model.mh.Pricing(ref model); if (model.name != "Chasovnya+lepestok") goto exit; bool c235found = false; //проверим, что это в самом деле правила из TSmatchINFO/Rules - есть С235 foreach (var r in model.Rules) { if (!r.text.Contains("235")) continue; c235found = true; break; } Assert.IsTrue(c235found); //полоса PL8 находится в matches[23] Mtch found_match = model.matches[23]; Assert.AreEqual(Mtch.OK.Match, found_match.ok); Assert.AreEqual("Полоса", found_match.rule.sCS); Assert.AreEqual("СтальХолдинг", found_match.rule.sSupl); exit: FileOp.AppQuit(); }