using System;
using System.Collections.Generic;
using System.Text;
using System.Transactions;
using NUnit.Framework;
using DBaccess;
using DBaccess.DBaccessDataSetTableAdapters;

namespace DBaccesstest
{
    [TestFixture]
    public class testcode
    {
        private zaikoTableTableAdapter zaikoAdapter;
        private TransactionScope transactionScope;

        [TestFixtureSetUp]
        public void テスト初期化()
        {
            zaikoAdapter = new zaikoTableTableAdapter();
//          zaikoAdapter.ConnectionString = "Data Source=(local);Initial Catalog=sampleDB;User ID=sa;Password=sapassword;";
            transactionScope = new TransactionScope();
        }

        [TestFixtureTearDown]
        public void テスト後処理()
        {
            transactionScope.Dispose();
        }

        [Test]
        public void データ追加テスト()
        {
            int datacount;
            DBaccessDataSet.zaikoTableDataTable zaikoTable1 = new DBaccessDataSet.zaikoTableDataTable();
            zaikoAdapter.Fill(zaikoTable1);
            datacount = zaikoTable1.Rows.Count;

            DBaccessDataSet.zaikoTableRow newData = (DBaccessDataSet.zaikoTableRow)zaikoTable1.NewRow();
            newData.syohinID = 1001;
            newData.syohinName = "りんご";
            newData.zaiko = 100;
            zaikoTable1.Rows.Add(newData);
            zaikoAdapter.Update(zaikoTable1);

            DBaccessDataSet.zaikoTableDataTable zaikoTable2 = zaikoAdapter.GetData();
            Assert.AreEqual(datacount + 1, zaikoTable2.Rows.Count);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void 例外データ追加テスト()
        {
            int datacount;
            DBaccessDataSet.zaikoTableDataTable zaikoTable1 = new DBaccessDataSet.zaikoTableDataTable();
            zaikoAdapter.Fill(zaikoTable1);
            datacount = zaikoTable1.Rows.Count;

            DBaccessDataSet.zaikoTableRow newData = (DBaccessDataSet.zaikoTableRow)zaikoTable1.NewRow();
            newData.syohinID = 1002;
            newData.syohinName = "みかん";
            newData.zaiko = -50;
            zaikoTable1.Rows.Add(newData);
            zaikoAdapter.Update(zaikoTable1);

            DBaccessDataSet.zaikoTableDataTable zaikoTable2 = zaikoAdapter.GetData();
            Assert.AreEqual(datacount + 1, zaikoTable2.Rows.Count);
        }
    }
}
