示例#1
0
        public void UnitPriceInvalidCountCompanyValidTest()
        {
            double        minUnitPrice  = 0;
            double        maxUnitPrice  = 100;
            int           minCount      = 50;
            double        wholeValue    = 7500;
            string        goodName      = "gun";
            string        company       = "googoolParvar";
            double        weight        = 100;
            double        unitPrice     = 150;
            int           count         = 50;
            DateTime      issuanceDate  = new DateTime(2015, 1, 20);
            List <string> merchandises  = new List <string>();
            List <string> companies     = new List <string>();
            List <string> licenseNeeded = new List <string>();

            companies.Add("googoolParvar");
            bool expected = false;
            //drivers
            Law lawTest = new Law(DateTime.MinValue, DateTime.MaxValue, minUnitPrice, maxUnitPrice, minCount,
                                  "", "", double.MinValue, merchandises, companies, licenseNeeded);
            Statement statement = new Statement();

            statement.SetParameters(issuanceDate, wholeValue, "", "");
            MerchandiseInStatement MIS = new MerchandiseInStatement(goodName, company, weight, count, unitPrice);

            statement.AddNewMerchandise(MIS);
            Assert.AreEqual(lawTest.IsValidWithoutMerchandise(statement), expected, "Wrong Check in ");
        }
        public void check_low_with_two_unvalid_merchandise_in_statement()
        {
            List <string> merchandises = new List <string>();

            merchandises.Add("berenj");
            merchandises.Add("gandom");
            List <string> companies = new List <string>();

            companies.Add("tabarok");
            companies.Add("golestan");
            List <string> licenseNeeded = new List <string>();
            DateTime      issuanceDate  = new DateTime(2015, 1, 18);
            //stub
            bool expected = false;
            //drivers
            Law lawTest = new Law(DateTime.MinValue, DateTime.MaxValue, 200, 5000, 200
                                  , "", "", double.MinValue, merchandises, companies, licenseNeeded);
            Statement statement = new Statement();

            statement.SetParameters(issuanceDate, 200000, "", "");
            MerchandiseInStatement mis  = new MerchandiseInStatement("berenj", "tabarok", 0, 1000, 100);
            MerchandiseInStatement mis2 = new MerchandiseInStatement("gandom", "golestan", 0, 100, 1000);

            statement.AddNewMerchandise(mis);
            statement.AddNewMerchandise(mis2);
            Assert.AreEqual(lawTest.IsValidPerMerchandise(statement), expected, "low with tow unvalid merchandise in statement isn't correctly coded!");
        }
        public void AddNewMerchandiseToStatement(string name, string company, string weight, string number, string price)
        {
            // these should not be empty
            double _weight = String.IsNullOrEmpty(weight) ? -1 : Convert.ToDouble(weight);
            int    _number = String.IsNullOrEmpty(number) ? -1 : Convert.ToInt32(number);
            double _price  = String.IsNullOrEmpty(price) ? -1 : Convert.ToDouble(price);

            MerchandiseInStatement merchandise = new MerchandiseInStatement(name, company, _weight, _number, _price);

            statement.AddNewMerchandise(merchandise);
        }
示例#4
0
        public void CompanyCountUnitPriceValidUnionFlagsTest()
        {
            double        minUnitPrice  = 0;
            double        maxUnitPrice  = 100;
            int           minCount      = 10;
            double        wholeValue    = 7500;
            string        goodName1     = "gun";
            string        company1      = "googoolParvar";
            double        weight1       = 100;
            double        unitPrice1    = 50;
            int           count1        = 9;
            string        goodName2     = "WarMachine";
            string        company2      = "googoolParvar";
            double        weight2       = 1000;
            double        unitPrice2    = 500;
            int           count2        = 10;
            DateTime      issuanceDate  = new DateTime(2015, 1, 20);
            List <string> merchandises  = new List <string>();
            List <string> companies     = new List <string>();
            List <string> licenseNeeded = new List <string>();

            companies.Add("USI");
            companies.Add("googoolParvar");
            bool expected = false;
            //drivers
            Law lawTest = new Law(DateTime.MinValue, DateTime.MaxValue, minUnitPrice, maxUnitPrice, minCount,
                                  "", "", double.MinValue, merchandises, companies, licenseNeeded);
            Statement statement = new Statement();

            statement.SetParameters(issuanceDate, wholeValue, "", "");
            MerchandiseInStatement MIS1 = new MerchandiseInStatement(goodName1, company1, weight1, count1, unitPrice1);
            MerchandiseInStatement MIS2 = new MerchandiseInStatement(goodName2, company2, weight2, count2, unitPrice2);

            statement.AddNewMerchandise(MIS1);
            statement.AddNewMerchandise(MIS2);
            Assert.AreEqual(lawTest.IsValidWithoutMerchandise(statement), expected, "Wrong Check in ");
        }
示例#5
0
        public bool ConditionsMatched(Statement statement)
        {
            //licensesNeeded.Clear(); // This List Sould Not Be HERE AT ALLLLLLLL!!!!
            //List<string> licenses = new List<string>();
            //List<string> merchandises = new List<string>();
            //List<string> companies = new List<string>();

            //merchandises.Add("گازوییل");
            //merchandises.Add("بنزین");
            //merchandises.Add("قیر");
            //licenses.Add("مجوز واردات فرآورده های نفتی");
            //CreateNewLaw(DateTime.MinValue, DateTime.MaxValue, double.MinValue, double.MaxValue, int.MinValue,
            //             String.Empty, double.MinValue, String.Empty, merchandises, companies, licenses);
            //licenses = new List<string>();
            //merchandises = new List<string>();
            //companies = new List<string>();

            //merchandises.Add("بشکه");
            //merchandises.Add("ورق آهن");
            //merchandises.Add("میلگرد");
            //merchandises.Add("تیرآهن");
            //licenses.Add("مجوز واردات کالای خارجی تولید داخل");
            //licenses.Add("مجوز واردات کالاهای فلزی");
            //CreateNewLaw(DateTime.MinValue, DateTime.MaxValue, 100, 10000, 100,
            //             String.Empty, double.MinValue, String.Empty, merchandises, companies, licenses);
            //licenses = new List<string>();
            //merchandises = new List<string>();
            //companies = new List<string>();


            //merchandises.Add("شامپو");
            //merchandises.Add("کرم");
            //licenses.Add("مجوز سلامت بهداشتی کالا های متفرقه");
            //CreateNewLaw(new DateTime(2010, 1, 1), DateTime.MaxValue, double.MinValue, double.MaxValue, int.MinValue,
            //             "چین", double.MinValue, String.Empty, merchandises, companies, licenses);
            //licenses = new List<string>();
            //merchandises = new List<string>();
            //companies = new List<string>();


            //companies.Add("هیوندای");
            //companies.Add("کیا");
            //licenses.Add("مجوز  واردات خودرو های خارجی");
            //CreateNewLaw(DateTime.MinValue, DateTime.MaxValue, double.MinValue, double.MaxValue, int.MinValue,
            //            String.Empty, 1000000, String.Empty, merchandises, companies, licenses);
            //licenses = new List<string>();
            //merchandises = new List<string>();
            //companies = new List<string>();


            //licenses.Add("مجوز واردات کالاهای لوکس");
            //licenses.Add("مجوز سلامت فیزیکی کالاها");
            //licenses.Add("عدم مغایرت با اهداف اقتصاد مقاومتی");
            //CreateNewLaw(new DateTime(2014, 1, 1), new DateTime(2017, 1, 1), 100000, 1000000, int.MinValue,
            //             "سوئیس", double.MinValue, "هوایی", merchandises, companies, licenses);
            //licenses = new List<string>();
            //merchandises = new List<string>();
            //companies = new List<string>();

            ////MessageBox.Show("law size: " + laws.Count);
            if (statement.GetIssuanceDate() > startDate && statement.GetIssuanceDate() < finishDate &&
                (String.IsNullOrEmpty(country) ? true : (statement.GetCountry() == country)) &&
                (String.IsNullOrEmpty(kindOfImport) ? true : statement.GetKindOfImport() == kindOfImport) &&
                (this.minTotalPrice <= statement.GetWholeValue()))
            {
                bool minCountIsLimited;
                bool minUnitPriceIsLimted;
                bool companyIsLimited;

                if (this.merchandiseList.Count == 0) // no limitation for name of goods
                {
                    foreach (MerchandiseInStatement statementMerchandise in statement.GetMerchandiseList())
                    {
                        minCountIsLimited    = false /*true*/;
                        minUnitPriceIsLimted = false /*true*/;
                        companyIsLimited     = false /*true*/;

                        if (statementMerchandise.GetUnitPrice() > minUnitPrice &&
                            statementMerchandise.GetUnitPrice() < maxUnitPrice)
                        {
                            minUnitPriceIsLimted = true /*false*/;
                        }
                        //MessageBox.Show("false because unit price of: " + statementMerchandise.GetName());
                        //statementMerchandise.GetUnitPrice().ToString() + " " + law.GetMinUnitPrice().ToString());

                        if (statementMerchandise.GetCount() > minCount
                            /*&& statementMerchandise.GetCount() <= law.GetMaxCount()*/)
                        {
                            minCountIsLimited = true;
                        }

                        if (companies.Count == 0) // law states no company
                        {
                            companyIsLimited = true;
                        }
                        else if (companies.Contains(statementMerchandise.GetCompany())) // law states companies
                        {
                            companyIsLimited = true;
                        }

                        MessageBox.Show("flags: " + minUnitPriceIsLimted.ToString() + " " + minCountIsLimited.ToString() + " " + companyIsLimited.ToString());
                        if (minUnitPriceIsLimted && minCountIsLimited && companyIsLimited)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    foreach (string lawMerchandiseName in merchandiseList)
                    {
                        if (statement.hasMerchandiseWithName(lawMerchandiseName))
                        {
                            minCountIsLimited    = false /*true*/;
                            minUnitPriceIsLimted = false /*true*/;
                            companyIsLimited     = false /*true*/;

                            MerchandiseInStatement currentmerchandise = statement.getMerchandiseWithName(lawMerchandiseName);
                            MessageBox.Show("Got one equal name");
                            if (currentmerchandise.GetUnitPrice() > minUnitPrice &&
                                currentmerchandise.GetUnitPrice() < maxUnitPrice)
                            {
                                minUnitPriceIsLimted = true;
                            }
                            if (currentmerchandise.GetCount() > minCount
                                /*&& statementMerchandise.GetCount() <= law.GetMaxCount()*/)
                            {
                                minCountIsLimited = true;
                            }

                            //MessageBox.Show(companies.Count.ToString());
                            //MessageBox.Show(companies[0].ToString());
                            //MessageBox.Show("join: " + String.IsNullOrEmpty(String.Join("", companies)).ToString());
                            //MessageBox.Show(companies.ToString());
                            //if (companies.Count == 0)
                            if (String.IsNullOrEmpty(String.Join("", companies)))
                            {
                                companyIsLimited = true;
                            }
                            else if (companies.Contains(currentmerchandise.GetCompany()))
                            {
                                companyIsLimited = true;
                            }
                            MessageBox.Show("flags: " + minUnitPriceIsLimted.ToString() + " " + minCountIsLimited.ToString() + " " + companyIsLimited.ToString());
                            if (minUnitPriceIsLimted && minCountIsLimited && companyIsLimited)
                            {
                                return(true);
                            }
                        }
                    }
                }
                //MessageBox.Show("condition checking: priceLimited: " + minUnitPriceIsLimted.ToString() + "      minCountLimited: " + minCountIsLimited.ToString() + "       companyLimited: " + companyIsLimited.ToString());
                //if (minUnitPriceIsLimted && minCountIsLimited && companyIsLimited)
                //return true;
            }
            //MessageBox.Show("not matched at first");
            return(false);
        }