コード例 #1
0
ファイル: Store.cs プロジェクト: talhahkazi93/projects
        private void AUbtn_Click(object sender, EventArgs e)
        {
            if (AUbtn.Text == "Edit")
            {
                if (Nametxt.Text.Equals("") || Typetxt.Text.Equals(""))
                {
                    MessageBox.Show("Required Fields are empty");
                }
                else
                {
                    StoreDao store = new StoreDao();

                    String name = Nametxt.Text;
                    String Type = Typetxt.Text;
                    String id   = idtext.Text;

                    store.Update(id, name, Type);

                    MessageBox.Show("Edited!");

                    Store_Load(sender, e);
                }
            }
            if (AUbtn.Text == "Add")
            {
                if (Nametxt.Text.Equals("") || Typetxt.Text.Equals(""))
                {
                    MessageBox.Show("Required Fields are empty");
                }
                else
                {
                    StoreDao store = new StoreDao();

                    String name = Nametxt.Text;
                    String Type = Typetxt.Text;

                    store.insert(name, Type);

                    AddBtn.Enabled  = true;
                    EditBtn.Enabled = true;

                    MessageBox.Show("Added!");

                    Store_Load(sender, e);
                }
            }
        }
コード例 #2
0
        public void IntegrationTest()
        {
            var connection = TestSession.GetConnection();

            connection.Open();
            #region good insertion and select by id test
            StoreModel inserted = new StoreModel();
            inserted.BusinessEntityID = TestSession.Random.Next();
            inserted.Name             = TestSession.Random.RandomString(50);
            inserted.SalesPersonID    = TestSession.Random.Next();
            inserted.Demographics     = null; //TODO define how to generate random xml;
            inserted.rowguid          = Guid.NewGuid();
            inserted.ModifiedDate     = TestSession.Random.RandomDateTime();

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

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

            CollectionAssert.IsNotEmpty(selectedAfterInsertion);
            var selectedAfterInsert = selectedAfterInsertion.Single();
            Assert.AreEqual(inserted.BusinessEntityID, selectedAfterInsert.BusinessEntityID);
            Assert.AreEqual(inserted.Name, selectedAfterInsert.Name);
            Assert.AreEqual(inserted.SalesPersonID, selectedAfterInsert.SalesPersonID);
            Assert.AreEqual(inserted.Demographics, selectedAfterInsert.Demographics);
            Assert.AreEqual(inserted.rowguid, selectedAfterInsert.rowguid);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate);

            #endregion

            #region update and select by id test
            inserted.Name          = TestSession.Random.RandomString(50);
            inserted.SalesPersonID = TestSession.Random.Next();
            inserted.Demographics  = null; //TODO define how to generate random xml;
            inserted.rowguid       = Guid.NewGuid();
            inserted.ModifiedDate  = TestSession.Random.RandomDateTime();

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

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

            CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss);
            var selectedAfterUpdate = selectedAfterUpdateAddresss.Single();
            Assert.AreEqual(inserted.BusinessEntityID, selectedAfterUpdate.BusinessEntityID);
            Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name);
            Assert.AreEqual(inserted.SalesPersonID, selectedAfterUpdate.SalesPersonID);
            Assert.AreEqual(inserted.Demographics, selectedAfterUpdate.Demographics);
            Assert.AreEqual(inserted.rowguid, selectedAfterUpdate.rowguid);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate);

            #endregion

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