public void TrySetValue_Should_ReturnOk_When_ConvertibleIsNull()
        {
            var property = new ThingProperty(_thing, false, false,
                                             _getter, _setter, _jsonSchemaValidation, _jsonConvertible, null, _originPropertyName);

            var value     = _fixture.Create <string>();
            var jsonValue = _fixture.Create <string>();

            _jsonConvertible.TryConvert(value, out Arg.Any <object>())
            .Returns(x =>
            {
                x[1] = jsonValue;
                return(true);
            });

            _jsonSchemaValidation.IsValid(jsonValue)
            .Returns(true);

            property.TrySetValue(value).Should().Be(SetPropertyResult.Ok);
            _thing.Value.Should().Be(jsonValue);

            _jsonSchemaValidation
            .Received(1)
            .IsValid(jsonValue);

            _jsonConvertible
            .Received(1)
            .TryConvert(value, out Arg.Any <object>());
        }
        public void TrySetValue_Should_ReturnInvalid_When_TryConvertIsFalse()
        {
            var property = new ThingProperty(_thing, false, false,
                                             _getter, _setter, _jsonSchemaValidation, _jsonConvertible, _convertible, _originPropertyName);

            var value = _fixture.Create <string>();

            _jsonConvertible.TryConvert(value, out Arg.Any <object>())
            .Returns(x =>
            {
                x[1] = null;
                return(false);
            });

            property.TrySetValue(value).Should().Be(SetPropertyResult.InvalidValue);
            _thing.Value.Should().NotBe(value);

            _jsonConvertible
            .Received(1)
            .TryConvert(value, out Arg.Any <object>());

            _jsonSchemaValidation
            .DidNotReceive()
            .IsValid(Arg.Any <object>());
        }
Exemple #3
0
 private ThingProperty GetThingProperty()
 {
     _thingPropertyId = Int32.Parse(Page.Request.QueryString["id"]);
     TDA                      = new ThingDataAccess();
     _thingProperty           = TDA.GetThingProperty(_thingPropertyId);
     Session["thingProperty"] = _thingProperty;
     return(_thingProperty);
 }
        public void TryGetValue_Should_ReturnTrue_When_IsNotWriteOnly()
        {
            var property = new ThingProperty(_thing, false, false,
                                             _getter, _setter, _jsonSchemaValidation, _jsonConvertible, _convertible, _originPropertyName);

            _thing.Value = _fixture.Create <string>();

            property.TryGetValue(out var value).Should().BeTrue();
            value.Should().Be(_thing.Value);
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _thingProperty = GetThingProperty();

            if (!IsPostBack)
            {
                lblOwnerName.Text   = "Owner Thing: " + _thingProperty.OwnerThing.Name;
                lblId.Text          = _thingProperty.OwnerThing.Id.ToString();
                txtName.Text        = _thingProperty.OwnedThing.Name;
                txtDescription.Text = _thingProperty.OwnedThing.Description;
                cbList.Checked      = _thingProperty.IsList;
                BindPropertyDDL();
            }
        }
        public void UpdateThingProperty(ThingProperty thingProperty)
        {
            connection = new SqlConnection(constr);

            using (SqlCommand command = new SqlCommand("UpdateThingProperty", connection))
            {
                command.CommandType = CommandType.StoredProcedure;

                //Add SqlParameters to the SqlCommand
                command.Parameters.AddWithValue("@thingPropertyId", thingProperty.ThingPropertyId);
                command.Parameters.AddWithValue("@propertyId", thingProperty.OwnedThing.Id);
                command.Parameters.AddWithValue("@name", thingProperty.PropertyName);
                command.Parameters.AddWithValue("@description", thingProperty.PropertyDescription);
                command.Parameters.AddWithValue("@isList", thingProperty.IsList);

                //try to open the connection
                try
                {
                    connection.Open();
                }
                catch (Exception ex)
                {
                    //There is a problem connecting to the instance of the SQL Server.
                    //For example, the connection string might be wrong,
                    //or the SQL Server might not be available to you.
                    string error = ex.GetBaseException().ToString();
                }

                //Execute the query.
                try
                {
                    int rowsAffected = Int32.Parse(command.ExecuteNonQuery().ToString());
                }
                catch (Exception ex)
                {
                    //There was a problem executing the query. For examaple, your SQL statement
                    //might be wrong, or you might not have permission to create records in the
                    //specified table.
                    string error = ex.ToString();
                }

                //is this necessary?
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            _thingProperty = Session["thingProperty"] != null ? (ThingProperty)Session["thingProperty"] : GetThingProperty();
            _thingProperty.ThingPropertyId     = _thingPropertyId;
            _thingProperty.OwnerThing          = new Thing();
            _thingProperty.OwnerThing.Id       = Int32.Parse(lblId.Text);
            _thingProperty.OwnedThing          = new Thing();
            _thingProperty.OwnedThing.Id       = Int32.Parse(ddlTypes.SelectedValue);
            _thingProperty.PropertyName        = txtName.Text;
            _thingProperty.PropertyDescription = txtDescription.Text;
            _thingProperty.IsList = cbList.Checked;

            TDA = new ThingDataAccess();
            TDA.UpdateThingProperty(_thingProperty);
            Response.Redirect("EditThing.aspx?id=" + _thingProperty.OwnerThing.Id);
        }
        public void TrySetValue_Should_ReturnReadOnly_When_IsReadOnly()
        {
            var property = new ThingProperty(_thing, true, false,
                                             _getter, _setter, _jsonSchemaValidation, _jsonConvertible, _convertible, _originPropertyName);

            var value = _fixture.Create <string>();

            property.TrySetValue(value).Should().Be(SetPropertyResult.ReadOnly);
            _thing.Value.Should().NotBe(value);

            _jsonConvertible
            .DidNotReceive()
            .TryConvert(Arg.Any <object>(), out Arg.Any <object>());

            _jsonSchemaValidation
            .DidNotReceive()
            .IsValid(Arg.Any <object>());
        }
        public List <ThingProperty> GetThingProperties(int ownerThingId)
        {
            List <ThingProperty> returnList = new List <ThingProperty>();

            connection = new SqlConnection(constr);

            using (SqlCommand command = new SqlCommand("GetOwnerPropertyList", connection))
            {
                command.CommandType = CommandType.StoredProcedure;

                //Add SqlParameters to the SqlCommand
                command.Parameters.AddWithValue("@ownerId", ownerThingId);

                //try to open the connection
                try
                {
                    connection.Open();
                }
                catch (Exception ex)
                {
                    //There is a problem connecting to the instance of the SQL Server.
                    //For example, the connection string might be wrong,
                    //or the SQL Server might not be available to you.
                    string error = ex.GetBaseException().ToString();
                }

                //Execute the query.
                try
                {
                    // Use the Command object to create a data reader
                    SqlDataReader dataReader = command.ExecuteReader();

                    // Read the data reader's rows into the PropertyList
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            ThingProperty thingProperty = new ThingProperty();
                            thingProperty.ThingPropertyId     = dataReader.GetInt32(0);
                            thingProperty.PropertyName        = dataReader.GetString(1);
                            thingProperty.PropertyDescription = dataReader.GetString(2);
                            thingProperty.IsList = dataReader.GetBoolean(3);

                            //Thing ownerThing = new Thing();
                            //ownerThing.Id = dataReader.GetInt32(3);
                            //ownerThing.Name = dataReader.GetString(4);
                            //ownerThing.Description = dataReader.GetString(5);

                            Thing ownedThing = new Thing();
                            ////ownedThing.Id = dataReader.GetInt32(6);
                            ownedThing.Name = dataReader.GetString(4);
                            //ownedThing.Description = dataReader.GetString(8);
                            thingProperty.OwnedThing = ownedThing;
                            // Add it to the thingList
                            returnList.Add(thingProperty);

                            //clsProperty Property = new clsProperty();
                            //Property.PropertyID = dataReader.GetInt32(0);
                            //Property.PropertyName = dataReader.GetString(1);
                            //Property.PropertyValue = dataReader.GetString(2);
                            //Property.PropertyParentID = dataReader.GetInt32(3);
                            //Property.PropertyParentName = dataReader.GetString(4);
                            //Property.FieldID = dataReader.GetInt32(5);
                            //Property.IsActive = dataReader.GetBoolean(6);
                            //// Add it to the Property list
                            //Properties.Add(Property);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //There was a problem executing the query. For examaple, your SQL statement
                    //might be wrong, or you might not have permission to create records in the
                    //specified table.
                    string error = ex.ToString();
                }

                //is this necessary?
                finally
                {
                    connection.Close();
                }
            }
            return(returnList);
        }
        public ThingProperty GetThingProperty(int id)
        {
            ThingProperty thingProperty = new ThingProperty();

            connection = new SqlConnection(constr);

            //Tell the SqlCommand what query to execute and what SqlConnection to use.
            using (SqlCommand command = new SqlCommand("GetThingProperty", connection))              //GetThingsAll
            {
                command.CommandType = CommandType.StoredProcedure;
                //Add SqlParameters to the SqlCommand
                command.Parameters.AddWithValue("@id", id);

                //try to open the connection
                try
                {
                    connection.Open();
                }
                catch (Exception ex)
                {
                    //There is a problem connecting to the instance of the SQL Server.
                    //For example, the connection string might be wrong,
                    //or the SQL Server might not be available to you.
                    string error = ex.GetBaseException().ToString();
                }

                //Execute the query.
                try
                {
                    // Use the Command object to create a data reader
                    SqlDataReader dataReader = command.ExecuteReader();


                    // Read the data reader's rows into the PropertyList
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            thingProperty.ThingPropertyId     = dataReader.GetInt32(0);
                            thingProperty.PropertyName        = dataReader.GetString(1);
                            thingProperty.PropertyDescription = dataReader.GetString(2);
                            thingProperty.IsList = dataReader.GetBoolean(3);

                            Thing ownerThing = new Thing();
                            ownerThing.Id            = dataReader.GetInt32(4);
                            ownerThing.Name          = dataReader.GetString(5);
                            ownerThing.Description   = dataReader.GetString(6);
                            thingProperty.OwnerThing = ownerThing;

                            Thing ownedThing = new Thing();
                            ownedThing.Id            = dataReader.GetInt32(7);
                            ownedThing.Name          = dataReader.GetString(8);
                            ownedThing.Description   = dataReader.GetString(9);
                            thingProperty.OwnedThing = ownedThing;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //There was a problem executing the query. For examaple, your SQL statement
                    //might be wrong, or you might not have permission to create records in the
                    //specified table.
                    string error = ex.ToString();
                }
            }
            return(thingProperty);
        }
Exemple #11
0
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     _thingProperty = Session["thingProperty"] != null ? (ThingProperty)Session["thingProperty"] : GetThingProperty();
     Response.Redirect("EditThing.aspx?id=" + _thingProperty.OwnerThing.Id);
 }