chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

I've created the unit test below and I want to set the value of the drop down control to "R" but using SelectedValue doesn't seem to work.  How do I set the selected value of a drop down list in a test?

        [Test]
        public void Button1_Click_DropDown()
        {
            // arrange
            var webForm1 = new WebForm1();
            var dropDownList = new DropDownList();
            var sender = new object();
            var eventArgs = new EventArgs();
 
            dropDownList.SelectedValue = "R";
            Isolate.NonPublic.InstanceField(webForm1, "ddlRating").Value = dropDownList;
 
            // act
            Isolate.Invoke.Method(webForm1, "Button1_Click", sender, eventArgs);
 
            // assert
            Assert.AreEqual("Ticket Price: $18", (string)Isolate.Invoke.Method(webForm1, "GetPrice", "rating"));
        }
closed with the note: Exactly the answer I was looking for.
asked by chking999 (1.6k points)
closed by chking999
...