示例#1
0
        public void CanCallVoidMethodOnReferenceTypeTarget()
        {
            //-- Arrange

            DeriveClassFrom <object>()
            .DefaultConstructor()
            .ImplementInterface <AncestorRepository.ITargetObjectCaller>()
            .Method <object, object>(intf => intf.CallTheTarget).Implement((m, target) => {
                target.CastTo <TargetOne>().Void(x => x.CallMe);
                m.Return(null);
            });

            //-- Act

            var obj       = CreateClassInstanceAs <AncestorRepository.ITargetObjectCaller>().UsingDefaultConstructor();
            var targetObj = new TargetOne();

            obj.CallTheTarget(targetObj);
            obj.CallTheTarget(targetObj);

            //-- Assert

            Assert.That(targetObj.TimesCalled, Is.EqualTo(2));
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check the session the ensure user is valid
            if (Session["username"] == null)
            {
                Response.Redirect("index.aspx");
            }

            //Displays the username in the top navigation bar
            lblUserName.Text = "" + Session["username"];


            string CS = ConfigurationManager.ConnectionStrings["oacConnectionString"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                if (!IsPostBack)
                {
                    SqlCommand cmd = new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%City%'",
                                                    con);
                    con.Open();
                    City.DataSource     = cmd.ExecuteReader();
                    City.DataTextField  = "ItemName"; //Column name
                    City.DataValueField = "ItemName"; //column name
                    City.DataBind();
                    con.Close();

                    SqlCommand cmd2 = new SqlCommand("SELECT [OrgName], [OrgID] FROM [Organizations]", con);
                    con.Open();
                    OrgName.DataSource     = cmd2.ExecuteReader();
                    OrgName.DataTextField  = "OrgName"; //Column name
                    OrgName.DataValueField = "OrgID";   //column name
                    OrgName.DataBind();
                    con.Close();

                    SqlCommand cmdStreamOne =
                        new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%Stream%'", con);
                    con.Open();
                    StreamOne.DataSource     = cmdStreamOne.ExecuteReader();
                    StreamOne.DataTextField  = "ItemName"; //Column name
                    StreamOne.DataValueField = "ItemName"; //column name
                    StreamOne.DataBind();
                    con.Close();

                    SqlCommand cmdStreamTwo =
                        new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%Stream%'", con);
                    con.Open();
                    StreamTwo.DataSource     = cmdStreamTwo.ExecuteReader();
                    StreamTwo.DataTextField  = "ItemName"; //Column name
                    StreamTwo.DataValueField = "ItemName"; //column name
                    StreamTwo.DataBind();
                    con.Close();

                    SqlCommand cmdCategoryOne =
                        new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%Category%'", con);
                    con.Open();
                    CategoryOne.DataSource     = cmdCategoryOne.ExecuteReader();
                    CategoryOne.DataTextField  = "ItemName"; //Column name
                    CategoryOne.DataValueField = "ItemName"; //column name
                    CategoryOne.DataBind();
                    con.Close();

                    SqlCommand cmdCategoryTwo =
                        new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%Category%'", con);
                    con.Open();
                    CategoryTwo.DataSource     = cmdCategoryTwo.ExecuteReader();
                    CategoryTwo.DataTextField  = "ItemName"; //Column name
                    CategoryTwo.DataValueField = "ItemName"; //column name
                    CategoryTwo.DataBind();
                    con.Close();

                    SqlCommand cmdTargetOne =
                        new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%Target%'", con);
                    con.Open();
                    TargetOne.DataSource     = cmdTargetOne.ExecuteReader();
                    TargetOne.DataTextField  = "ItemName"; //Column name
                    TargetOne.DataValueField = "ItemName"; //column name
                    TargetOne.DataBind();
                    con.Close();

                    SqlCommand cmdTargetTwo =
                        new SqlCommand("SELECT [ItemName] FROM [Handlers] WHERE Category LIKE '%Target%'", con);
                    con.Open();
                    TargetTwo.DataSource     = cmdTargetTwo.ExecuteReader();
                    TargetTwo.DataTextField  = "ItemName"; //Column name
                    TargetTwo.DataValueField = "ItemName"; //column name
                    TargetTwo.DataBind();
                    con.Close();
                }
            }
        }