protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        if (Session["SmId"] != null && Session["SmId"].ToString() != "")
        {
            SpecificationValue svupd = new SpecificationValue();
            long   SpecCategId       = long.Parse(ddlSpecCategoryData.SelectedValue);
            string SpecName          = TextSpecMname.Text;
            long   SpecId            = long.Parse(Session["SmId"].ToString());
            smobj.UpdateSpecMaster(SpecCategId, SpecId, SpecName);
            //svupd.UpdateSpecRecord(SpecId, SpecName);

            // binddata();
            if (ddlPCname.SelectedValue != "0" && ddlPCname.SelectedValue != "-1")
            {
                long pcaid = long.Parse(ddlPCname.SelectedValue);
                List <SpecificationMaster> lstspecnew = smobj.GetSpecBasedOnPC(pcaid);
                Session["lstspecmasterdata"] = lstspecnew;
                GridView1.DataSource         = (List <SpecificationMaster>)Session["lstspecmasterdata"];
                GridView1.DataBind();
                mpeUpdate.Hide();
                DivMsg.Style.Add("display", "inline-table");
                lblMsg.Text = "Updated Successfully !";
            }
            else
            {
                binddata();
                mpeUpdate.Hide();
            }
            // BindSpecData();
        }
    }
示例#2
0
        public void DoSomthing()
        {
            Specification specification =
                new AndSpecification(new EqualSpecification("key1", SpecificationValue.Single("value1")), new
                                     OrSpecification(
                                         new HasValueSpecification("key2"),
                                         new EqualSpecification("key5", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 3, DateTimeKind.Local))),

                                         // value of key3 should be equal to any of values 1,2,3
                                         new EqualSpecification("key3", SpecificationValue.AnyOf(1, 2, 3))),

                                     // key4 should be greater or equal to value with name "currentDateTime" which will be resolved at specification evaluation
                                     new GreaterOrEqualSpecification("key4", SpecificationValue.Ref("currentDateTime")));

            Dictionary <string, object> values = new Dictionary <string, object>
            {
                { "key1", "value1" },
                { "key3", 1 },
                { "key4", DateTime.Now.AddMinutes(1) },

                // value referenced from specification
                { "currentDateTime", DateTime.UtcNow }
            };

            SpecificationResult result = specification.Evaluate(values);

            Assert.True(result.IsSatisfied);

            string xml = specification.ToXml();

            Console.WriteLine(xml);

            Specification sp2 = Specification.Parse.FromXml(XElement.Parse(xml));
        }
        public void CastIntString(int value, bool allowCast, bool throwCastException, bool result, bool expectException)
        {
            EqualSpecification specification = new EqualSpecification("key", SpecificationValue.AnyOf("1", "2"));

            SpecificationEvaluationSettings settings =
                new SpecificationEvaluationSettings
            {
                IncludeDetails   = true,
                ThrowValueErrors = throwCastException
            };

            settings.ValueSettings.AllowCast = allowCast;
            Dictionary <string, object> values = new Dictionary <string, object> {
                { "key", value }
            };

            if (expectException)
            {
                Assert.Throws <InvalidOperationException>(() => specification.Evaluate(values, settings));
            }
            else
            {
                var res = specification.Evaluate(values, settings);

                Assert.Equal(result, res.IsSatisfied);
            }
        }
        public void ReplaceReference()
        {
            EqualSpecification equal = new EqualSpecification(
                "k1",
                SpecificationValue.Ref("{p1}"));

            ValueReferenceVisitor visitor = new ValueReferenceVisitor(
                new Dictionary <string, object>
            {
                { "{p1}", SpecificationValue.Ref("{p2}") },
                { "{p2}", SpecificationValue.Single("qwe") },
            });

            Specification result = visitor.Visit(equal);

            var r = Assert.IsType <EqualSpecification>(result);

            Assert.NotSame(equal, r);
            Assert.Contains("qwe", r.Value.Values);
            Assert.DoesNotContain("{p1}", r.Value.Values);
            Assert.DoesNotContain("{p2}", r.Value.Values);
            Assert.Equal(equal.Key, r.Key);
            Assert.Equal(SpecificationValueSettings.DefaultAllOf.DefaultMultiplicity, r.Value.ValueMultiplicity);
            Assert.Equal(SpecificationValue.DataType.String, r.Value.ValueType);
        }
    public List <SpecificationValue> SelectedProductDetails(long pno)
    {
        List <SpecificationValue> lstsspecv = new List <SpecificationValue>();
        SpecificationValue        specvalue;

        try
        {
            db.OpenConn();
            SqlCommand cmd = new SqlCommand(@"select S.SpecificationMasterName,SV.SpecificationValueName,SV.ProductID from SpecificationMaster S,SpecificationValues SV where S.SpecificationMasterID=SV.SpecificationMasterID and ProductID=@ProductID", db.conn);
            cmd.Parameters.AddWithValue("@ProductID", pno);

            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                specvalue = new SpecificationValue();
                specvalue.SpecificationMasterName = dr["SpecificationMasterName"].ToString();
                specvalue.SpecificationValueName  = dr["SpecificationValueName"].ToString();
                specvalue.ProductID = long.Parse(dr["ProductID"].ToString());
                lstsspecv.Add(specvalue);
            }
            dr.Close();
            db.CloseConn();
        }
        catch (Exception ex)
        {
            db.CloseConn();
            throw ex;
        }
        return(lstsspecv);
    }
    public List <SpecificationValue> GetProductSpecificationDetails(long pcid, long pid)
    {
        List <SpecificationValue> lstpspec = new List <SpecificationValue>();
        SpecificationValue        specvalue;

        try
        {
            db.OpenConn();
            SqlCommand cmd = new SqlCommand(@"select S.specificationmastername,SV.specificationvaluename from 
SpecificationMaster S,SpecificationValues SV where S.SpecificationMasterID=SV.SpecificationMasterID and ProductCategoryID=@ProductCategoryID and productid=@pructid", db.conn);
            cmd.Parameters.AddWithValue("@ProductCategoryID", pcid);
            cmd.Parameters.AddWithValue("@pructid", pid);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                specvalue = new SpecificationValue();
                specvalue.SpecificationMasterName = dr["SpecificationMasterName"].ToString();
                specvalue.SpecificationValueName  = dr["SpecificationValueName"].ToString();
                lstpspec.Add(specvalue);
            }
            dr.Close();
            db.CloseConn();
        }
        catch (Exception ex)
        {
            db.CloseConn();
            throw ex;
        }
        return(lstpspec);
    }
    //public void UpdateSpecMaster(long spmid,string spname)
    //{

    //    try
    //    {
    //        db.OpenConn();
    //        string query = "update SpecificationValues set SpecificationValueName=@SpecificationValueName where SpecificationMasterID=@SpecificationMasterID and ProductID=@ProductID ";
    //        SqlCommand cmd = new SqlCommand(query, db.conn);
    //        cmd.Parameters.AddWithValue("@SpecificationValueName", SpecificationValueName);
    //        cmd.Parameters.AddWithValue("@SpecificationMasterID", SpecificationMasterID);
    //        cmd.Parameters.AddWithValue("@ProductID", ProductID);
    //        cmd.ExecuteNonQuery();
    //        db.CloseConn();

    //    }
    //    catch (Exception ex)
    //    {
    //        db.CloseConn();
    //        throw ex;
    //    }

    //}

    public List <SpecificationValue> GetProductSpecs(long pcid)
    {
        List <SpecificationValue> lstpspec = new List <SpecificationValue>();
        SpecificationValue        specvalue;

        try
        {
            db.OpenConn();
            SqlCommand cmd = new SqlCommand(@" select SM.SpecificationMasterID, SM.SpecificationMasterName,SV.SpecificationValueName from SpecificationMaster SM left outer join SpecificationValues SV on SM.SpecificationMasterID=SV.SpecificationMasterID   where 
 SM.Specificationcategoryid=@Specificationcategoryid ", db.conn);

            cmd.Parameters.AddWithValue("@Specificationcategoryid", pcid);
            //cmd.Parameters.AddWithValue("@pructid", pid);
            //cmd.Parameters.AddWithValue("@Specificationcategoryid", speccategoryid);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                specvalue = new SpecificationValue();
                specvalue.SpecificationMasterID   = long.Parse(dr["SpecificationMasterID"].ToString());
                specvalue.SpecificationMasterName = "* " + dr["SpecificationMasterName"].ToString();
                specvalue.SpecificationValueName  = ": " + dr["SpecificationValueName"].ToString();
                lstpspec.Add(specvalue);
            }
            dr.Close();
            db.CloseConn();
        }
        catch (Exception ex)
        {
            db.CloseConn();
            throw ex;
        }
        return(lstpspec);
    }
    public List <SpecificationValue> GetPictureThumbnails(long thumbpathid)
    {
        List <SpecificationValue> lstpicthumnls = new List <SpecificationValue>();
        SpecificationValue        objpicthumnls = null;

        try
        {
            db.OpenConn();
            SqlCommand cmd = new SqlCommand("select * from PicturesThumbnails where ProductPictureID=@pictureid", db.conn);
            cmd.Parameters.AddWithValue("@pictureid", thumbpathid);

            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                objpicthumnls = new SpecificationValue();
                objpicthumnls.PictureThumbnailsID = long.Parse(dr["PictureThumbnailsID"].ToString());
                objpicthumnls.PictureThumbPath    = dr["PictureThumbPath"].ToString();
                objpicthumnls.ProductPictureID    = long.Parse(dr["ProductPictureID"].ToString());
                lstpicthumnls.Add(objpicthumnls);
            }
            dr.Close();
            db.CloseConn();
        }
        catch (Exception e)
        {
            db.CloseConn();
            throw e;
        }
        return(lstpicthumnls);
    }
    public List <SpecificationValue> GetProductSpec()
    {
        List <SpecificationValue> lstsvalues = new List <SpecificationValue>();
        SpecificationValue        obj;

        try
        {
            db.OpenConn();
            SqlCommand cmd = new SqlCommand("select SM.SpecificationMasterID,SM.Specificationmastername,P.ProductID  FROM specificationmaster SM inner join Products P on SM.ProductID=P.ProductID WHERE SM.PRoductID=@ProductID", db.conn);
            cmd.Parameters.AddWithValue("@ProductID", ProductID);
            cmd.Parameters.AddWithValue("@ProductCategoryID", ProductCategoryID);
            //cmd.Parameters.AddWithValue("@SpecificationMasterID", SpecificationMasterID);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                obj = new SpecificationValue();
                obj.SpecificationMasterName = dr["SpecificationMasterName"].ToString();

                obj.SpecificationMasterID = long.Parse(dr["SpecificationMasterID"].ToString());
                lstsvalues.Add(obj);
            }
            dr.Close();
            db.CloseConn();
        }
        catch (Exception ex)
        {
            db.CloseConn();
            throw ex;
        }
        return(lstsvalues);
    }
示例#10
0
        public void FromSingle(object value, object eval, SpecificationValue.Multiplicity sm, bool sac, bool sid, bool er, SpecificationValue.DataType et, SpecificationValue.Multiplicity em, string ee)
        {
            bool result = SpecificationValue.TryFrom(
                value,
                new SpecificationValueSettings {
                IncludeDetails = sid, DefaultMultiplicity = sm, AllowCast = sac
            },
                out SpecificationValue specification,
                out string error);

            Assert.Equal(er, result);

            if (result)
            {
                Assert.Equal(et, specification.ValueType);
                Assert.Equal(em, specification.ValueMultiplicity);
                if (eval != null)
                {
                    Assert.Contains(eval, specification.Values);
                }
            }
            else
            {
                Assert.Null(specification);

                if (ee == null)
                {
                    Assert.Null(error);
                }
                else
                {
                    Assert.Contains(ee, error);
                }
            }
        }
示例#11
0
    public List <SpecificationValue> GetSpec()
    {
        List <SpecificationValue> lstsvalues = new List <SpecificationValue>();
        SpecificationValue        obj;

        try
        {
            db.OpenConn();
            SqlCommand cmd = new SqlCommand("select SC.SpecificationCategoryID,SC.SpecificationCategoryName, SM.SpecificationMasterID,SM.specificationmastername ,SV.SpecificationValueName,SM.ProductID FROM SpecificationCategory SC inner join  specificationmaster SM  on SC.SpecificationCategoryId=SM.SpecificationCategoryId left outer join SpecificationValues SV on  SM.specificationmasterid=SV.specificationmasterid where SM.Productid=@ProductID ", db.conn);
            cmd.Parameters.AddWithValue("@ProductID", ProductID);
            //cmd.Parameters.AddWithValue("@ProductCategoryID", ProductCategoryID);
            //cmd.Parameters.AddWithValue("@SpecificationMasterID", SpecificationMasterID);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                obj = new SpecificationValue();
                obj.SpecificationCategoryID   = long.Parse(dr["SpecificationCategoryID"].ToString());
                obj.SpecificationCategoryName = dr["SpecificationCategoryName"].ToString();
                obj.SpecificationMasterName   = dr["SpecificationMasterName"].ToString();
                obj.SpecificationValueName    = dr["SpecificationValueName"].ToString();
                obj.SpecificationMasterID     = long.Parse(dr["SpecificationMasterID"].ToString());
                lstsvalues.Add(obj);
            }
            //dr.Close();
            db.CloseConn();
        }
        catch (Exception ex)
        {
            db.CloseConn();
            throw ex;
        }
        return(lstsvalues);
    }
    protected void btnYes_Click(object sender, EventArgs e)
    {
        SpecificationValue svobj = new SpecificationValue();

        if (txtsmastername.Text != "")
        {
            smobj.ProductCategoryName = ddlproductcategory.SelectedItem.Text.ToString();

            //objpc = (ProductCategories)ddlproductcategory.SelectedItem;
            smobj.SpecificationCategoryName = ddlspeccategory.SelectedItem.Text.ToString();
            smobj.SpecificationCategoryID   = long.Parse(ddlspeccategory.SelectedValue);
            smobj.ProductCategoryID         = long.Parse(ddlproductcategory.SelectedValue);
            smobj.ProductID = long.Parse(ddlproduct.SelectedValue);
            smobj.SpecificationMasterName = txtsmastername.Text;
            smobj.Description             = txtdescription.Text;
            long smid = smobj.SaveRecord();
            svobj.SpecificationMasterID   = smid;
            svobj.SpecificationMasterName = txtsmastername.Text;
            svobj.SpecificationValueName  = "";
            svobj.ProductID = long.Parse(ddlproduct.SelectedValue);
            svobj.SaveRecord();

            // binddata();
            BindSpecData();
            txtsmastername.Text = "";
            txtdescription.Text = "";
            binddata();
            BindPcategory();
            BindddlSpecCategoryData();
            ModalPopupExtender1.Hide();
            DivMsg.Style.Add("display", "inline-table");
            lblMsg.Text = "Saved Successfully !";
        }
    }
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "ButtonEdit")
     {
         long SmId = long.Parse(e.CommandArgument.ToString());
         Session["SmId"] = SmId;
         List <SpecificationMaster> lstspec = smobj.GetSpecMaster(SmId);
         foreach (SpecificationMaster listitem in lstspec)
         {
             Textpcname.Text = listitem.ProductName;
             ddlSpecCategoryData.SelectedItem.Text = listitem.SpecificationCategoryName;
             ddlSpecCategoryData.SelectedValue     = listitem.SpecificationCategoryID.ToString();
             //Textscname.Text = listitem.SpecificationCategoryName;
             TextSpecMname.Text = listitem.SpecificationMasterName;
         }
         mpeUpdate.Show();
     }
     else if (e.CommandName == "ButtonDelete")
     {
         SpecificationValue svdel = new SpecificationValue();
         long Smid = long.Parse(e.CommandArgument.ToString());
         smobj.DeleteSpecMaster(Smid);
         svdel.DeleteSpecMast(Smid);
         //  binddata();
         BindSpecData();
         binddata();
         DivMsg.Style.Add("display", "inline-table");
         lblMsg.Text = "Deleted Successfully !";
     }
 }
示例#14
0
        public void Less(object r, string key, bool expected)
        {
            Specification specification = new LessSpecification(key, SpecificationValue.Single(r));

            SpecificationResult result = specification.Evaluate(this.values);

            Assert.Equal(expected, result.IsSatisfied);
        }
示例#15
0
        protected SpecificationResult Compare(
            SpecificationValue left,
            SpecificationValue rigth,
            SpecificationEvaluationSettings settings)
        {
            if (left.ValueType != rigth.ValueType)
            {
                List <object> cast = new List <object>();
                foreach (object leftValue in left.Values)
                {
                    if (TypeHelper.HasMappingOrCast(leftValue, rigth.ValueType, settings.ValueSettings, out object leftCast))
                    {
                        cast.Add(leftCast);
                    }
                    else
                    {
                        if (settings.ThrowValueErrors)
                        {
                            throw new InvalidOperationException(
                                      string.Format(
                                          SpecAbsRes.KeyValueSpecificationTypeNotMatch,
                                          left.ValueType,
                                          this.Key,
                                          this.Value.ValueType));
                        }

                        return(SpecificationResult.Create(
                                   false,
                                   settings.IncludeDetails
                                ? string.Format(
                                       SpecAbsRes.KeyValueSpecificationTypeNotMatch,
                                       left.ValueType,
                                       this.Key,
                                       rigth.ValueType)
                                : null));
                    }
                }

                if (left.Values.Count == 1)
                {
                    left = SpecificationValue.Single(cast.Single());
                }
                if (left.ValueMultiplicity == SpecificationValue.Multiplicity.AnyOf)
                {
                    left = SpecificationValue.AnyOf(cast);
                }
                else if (left.ValueMultiplicity == SpecificationValue.Multiplicity.AllOf)
                {
                    left = SpecificationValue.AllOf(cast);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            return(this.CompareSafeTypes(left, rigth, settings));
        }
示例#16
0
        public void SingleString()
        {
            SpecificationValue value = SpecificationValue.Single("23");

            Assert.NotNull(value);
            Assert.Single(value.Values, "23");
            Assert.Equal(SpecificationValue.Multiplicity.AllOf, value.ValueMultiplicity);
            Assert.Equal(SpecificationValue.DataType.String, value.ValueType);
        }
示例#17
0
        public SpecificationValue CreateModel()
        {
            var specificationValue = new SpecificationValue();

            specificationValue.ProductSpecificationID = this.SpecificationID;
            specificationValue.Value = this.Value;

            return(specificationValue);
        }
        public void HasSpecRefs()
        {
            AndSpecification and = new AndSpecification(
                new EqualSpecification("qwe", SpecificationValue.Single(1)),
                new ReferenceSpecification("qwe"));

            Assert.False(and.HasValueRefs());
            Assert.True(and.HasSpecificationRefs());
        }
示例#19
0
        public void SingleInt()
        {
            SpecificationValue value = SpecificationValue.Single(23);

            Assert.NotNull(value);
            Assert.Single(value.Values, 23);
            Assert.Equal(SpecificationValue.Multiplicity.AllOf, value.ValueMultiplicity);
            Assert.Equal(SpecificationValue.DataType.Int, value.ValueType);
            Assert.Equal("23", value.ToString());
        }
        public void SingleSingleDetails()
        {
            EqualSpecification  specification = new EqualSpecification("key", SpecificationValue.Single(1));
            SpecificationResult spr           = specification.Evaluate(new Dictionary <string, object> {
                { "key", 2 }
            });

            Assert.False(spr.IsSatisfied);
            Assert.Equal("Right value(s) 1 not satisfied left value(s) 2 in key equal 1", spr.Details);
        }
示例#21
0
        public void AllOfInt()
        {
            SpecificationValue value = SpecificationValue.AllOf(1, 2, 4);

            Assert.NotNull(value);
            Assert.Collection(value.Values.OfType <int>(), i => Assert.Equal(1, i), i => Assert.Equal(2, i), i => Assert.Equal(4, i));
            Assert.Equal(SpecificationValue.Multiplicity.AllOf, value.ValueMultiplicity);
            Assert.Equal(SpecificationValue.DataType.Int, value.ValueType);
            Assert.Equal("All of (1, 2, 4)", value.ToString());
        }
示例#22
0
        public void LessOrEqualDateTime()
        {
            Assert.True(new LessOrEqualSpecification("k4", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 3, DateTimeKind.Utc))).Evaluate(this.values).IsSatisfied);
            Assert.True(new LessOrEqualSpecification("k4", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 4, DateTimeKind.Utc))).Evaluate(this.values).IsSatisfied);
            Assert.False(new LessOrEqualSpecification("k4", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 2, DateTimeKind.Utc))).Evaluate(this.values).IsSatisfied);

            Assert.True(new LessOrEqualSpecification("k4", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 3, DateTimeKind.Utc).ToLocalTime())).Evaluate(this.values).IsSatisfied);
            Assert.True(new LessOrEqualSpecification("k4", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 4, DateTimeKind.Utc).ToLocalTime())).Evaluate(this.values).IsSatisfied);
            Assert.False(new LessOrEqualSpecification("k4", SpecificationValue.Single(new DateTime(2018, 10, 10, 1, 2, 2, DateTimeKind.Utc).ToLocalTime())).Evaluate(this.values).IsSatisfied);
        }
        public async Task <ActionResult <SpecificationValue> > Post([FromBody] SpecificationValue entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _specificationValueRepository.Create(entity);

            await _unitOfWork.Save();

            return(Ok(entity));
        }
示例#24
0
        public SpecificationValueDto(SpecificationValue specificationValue)
        {
            this.SpecificationID = specificationValue.ProductSpecificationID;
            this.Value           = specificationValue.Value;

            if (specificationValue.Products.Count() == 0)
            {
                this.IsHavingProduct = false;
            }
            else
            {
                this.IsHavingProduct = true;
            }
        }
示例#25
0
    protected void Createtab()
    {
        string pridn = Request.QueryString["prid"];

        SpecificationValue           objspecval = new SpecificationValue();
        List <SpecificationCategory> lstspec    = new List <SpecificationCategory>();
        SpecificationCategory        objspec    = new SpecificationCategory();
        long pcid = long.Parse(pridn);

        lstspec    = objspec.GetSCategories(pcid);
        tbcDynamic = new AjaxControlToolkit.TabContainer();
        StringBuilder html = new StringBuilder();

        for (int i = 0; i < lstspec.Count; i++)
        {
            html.Append("<table class='table table-striped table-hover table-bordered'>");
            html.Append("<tbody>");

            Table    tbl         = new Table();
            TabPanel objtabpanel = new TabPanel();
            objtabpanel.HeaderText = lstspec[i].SpecificationCategoryName;
            objtabpanel.ID         = lstspec[i].SpecificationCategoryID.ToString();
            tbcDynamic.Tabs.Add(objtabpanel);
            List <SpecificationValue> lstspecnam = objspecval.GetProductSpecs(long.Parse(objtabpanel.ID));
            foreach (SpecificationValue items in lstspecnam)
            {
                if (items.SpecificationMasterName == "* Grade")
                {
                    gradetype            = items.SpecificationValueName;
                    Session["gradetype"] = gradetype;
                }
                else
                {
                    html.Append("<tr>");
                    html.Append("<td>");
                    html.Append(items.SpecificationMasterName);
                    html.Append("</td >");
                    html.Append("<td>");
                    html.Append(items.SpecificationValueName);
                    html.Append("</td>");
                    html.Append("</tr>");
                }
            }
            html.Append("</tbody>");
            html.Append("</table>");
        }
        PLH.Controls.Add(new Literal {
            Text = html.ToString()
        });
    }
        public void EqualReference()
        {
            EqualSpecification specification = new EqualSpecification(
                "key",
                SpecificationValue.Ref("k1"));

            Assert.True(
                specification.Evaluate(new Dictionary <string, object>
            {
                { "k1", new[] { 1, 2 } },
                { "key", 1 }
            })
                .IsSatisfied);
        }
        public void ResolveSpecRefGenericThrow()
        {
            AndSpecification and = new AndSpecification(
                new EqualSpecification("qwe", SpecificationValue.Single(1)),
                new ReferenceSpecification("qwe"));

            Dictionary <string, object> values = new Dictionary <string, object> {
                { "qwe", 1 }
            };

            var exc = Assert.Throws <InvalidOperationException>(() => and.ResolveSpecificationRefs(values));

            Assert.Contains("Unable to resolve specification reference for ref(qwe). Unable to resolve specification reference for qwe. Value 1 of type System.Int32 is not a specification", exc.Message);
        }
        public SpecificationsCollectionTests()
        {
            this.col.AllowedRuntimeValueReferenceKeys.Add("runtimeval");
            this.col.AllowedRuntimeSpecificationReferenceKeys.Add("runtimespec");

            this.col.ValuesForReference.Add("v1", SpecificationValue.Single(1));
            this.col.ValuesForReference.Add("v1ref", SpecificationValue.Ref("v1"));

            this.col.SpecificationsForReference.Add("s1", new EqualSpecification("k1", SpecificationValue.Ref("v1ref")));

            this.col.Specifications.Add("m1", new ReferenceSpecification("s1"));
            this.col.Specifications.Add("m2", new ReferenceSpecification("runtimespec"));
            this.col.Specifications.Add("m3", new EqualSpecification("k2", SpecificationValue.Ref("runtimeval")));
            this.col.Specifications.Add("m4", new EqualSpecification("k3", SpecificationValue.Ref("runtimeval")));
        }
        public void ReplaceNoKeysThrowDefault()
        {
            EqualSpecification equal = new EqualSpecification(
                "k1",
                SpecificationValue.Ref("{p1}"));

            ValueReferenceVisitor visitor =
                new ValueReferenceVisitor(new Dictionary <string, object> {
                { "{p2}", "v1" }
            });

            InvalidOperationException exc = Assert.Throws <InvalidOperationException>(() => visitor.Visit(equal));

            Assert.Contains("Unable to resolve value reference for k1 equal ref({p1}). Key {p1} is missing", exc.Message);
        }
        public void ReplaceInconsistentTypes()
        {
            EqualSpecification equal = new EqualSpecification(
                "k1",
                SpecificationValue.Ref("{p1}"));

            ValueReferenceVisitor visitor =
                new ValueReferenceVisitor(new Dictionary <string, object> {
                { "{p1}", TimeSpan.FromDays(1) }
            });

            InvalidOperationException exc = Assert.Throws <InvalidOperationException>(() => visitor.Visit(equal));

            Assert.Contains("Unable to resolve value reference for k1 equal ref({p1}). Value of type System.TimeSpan not supported.", exc.Message);
        }