Exemplo n.º 1
0
        public JsonResult put(PersonPhoneModel personPhone)
        {
            string query = @"
                    update dbo.PersonPhone set
                    ('" + personPhone.phoneNumber + @",
                     '" + personPhone.phoneNumberTypeID + @"
                     where businessEntityID = " + personPhone.businessEntityID;

            DataTable     table         = new DataTable();
            string        sqlDataSource = _configuration.GetConnectionString("PhonePersonAppCon");
            SqlDataReader myReader;

            using (SqlConnection myCon = new SqlConnection(sqlDataSource))
            {
                myCon.Open();
                using (SqlCommand myCommand = new SqlCommand(query, myCon))
                {
                    myReader = myCommand.ExecuteReader();
                    table.Load(myReader);

                    myReader.Close();
                    if (myCon != null)
                    {
                        myCon.Close();
                    }
                }

                return(new JsonResult("Updated Successfully"));
            }
        }
        public void IntegrationTest()
        {
            var connection = TestSession.GetConnection();

            connection.Open();
            #region good insertion and select by id test
            PersonPhoneModel inserted = new PersonPhoneModel();
            inserted.BusinessEntityID  = TestSession.Random.Next();
            inserted.PhoneNumber       = TestSession.Random.RandomString(25);
            inserted.PhoneNumberTypeID = TestSession.Random.Next();
            inserted.ModifiedDate      = TestSession.Random.RandomDateTime();

            _tested.Insert(connection, new[] { inserted });

            var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new PersonPhoneModelPrimaryKey()
            {
                BusinessEntityID  = inserted.BusinessEntityID,
                PhoneNumber       = inserted.PhoneNumber,
                PhoneNumberTypeID = inserted.PhoneNumberTypeID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterInsertion);
            var selectedAfterInsert = selectedAfterInsertion.Single();
            Assert.AreEqual(inserted.BusinessEntityID, selectedAfterInsert.BusinessEntityID);
            Assert.AreEqual(inserted.PhoneNumber, selectedAfterInsert.PhoneNumber);
            Assert.AreEqual(inserted.PhoneNumberTypeID, selectedAfterInsert.PhoneNumberTypeID);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate);

            #endregion

            #region update and select by id test
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Update(connection, new[] { inserted });

            var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new PersonPhoneModelPrimaryKey()
            {
                BusinessEntityID  = inserted.BusinessEntityID,
                PhoneNumber       = inserted.PhoneNumber,
                PhoneNumberTypeID = inserted.PhoneNumberTypeID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss);
            var selectedAfterUpdate = selectedAfterUpdateAddresss.Single();
            Assert.AreEqual(inserted.BusinessEntityID, selectedAfterUpdate.BusinessEntityID);
            Assert.AreEqual(inserted.PhoneNumber, selectedAfterUpdate.PhoneNumber);
            Assert.AreEqual(inserted.PhoneNumberTypeID, selectedAfterUpdate.PhoneNumberTypeID);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate);

            #endregion

            #region delete test
            _tested.Delete(connection, new[] { inserted });
            var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new PersonPhoneModelPrimaryKey()
            {
                BusinessEntityID  = inserted.BusinessEntityID,
                PhoneNumber       = inserted.PhoneNumber,
                PhoneNumberTypeID = inserted.PhoneNumberTypeID,
            });
            CollectionAssert.IsEmpty(selectedAfterDeleteAddresss);
            #endregion
            connection.Close();
        }