PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/TestSpss/SpssCasesCollectionTest.cs

#
C# | 122 lines | 101 code | 13 blank | 8 comment | 1 complexity | 2ba678aa922b4f461df852d6373ce13a MD5 | raw file
  1using System;
  2using System.Data;
  3using Microsoft.VisualStudio.TestTools.UnitTesting;
  4
  5namespace Spss.Testing
  6{
  7	/// <summary>
  8	///This is a test class for Spss.SpssCasesCollection and is intended
  9	///to contain all Spss.SpssCasesCollection Unit Tests
 10	///</summary>
 11	[TestClass()]
 12    [DeploymentItem("x86", "x86")]
 13    [DeploymentItem("x64", "x64")]
 14	public class SpssCasesCollectionTest : TestBase
 15	{
 16
 17
 18		private TestContext testContextInstance;
 19
 20		/// <summary>
 21		///Gets or sets the test context which provides
 22		///information about and functionality for the current test run.
 23		///</summary>
 24		public TestContext TestContext
 25		{
 26			get
 27			{
 28				return testContextInstance;
 29			}
 30			set
 31			{
 32				testContextInstance = value;
 33			}
 34		}
 35
 36		const int expectedRowCount = 138;
 37		[TestMethod]
 38		public void Count()
 39		{
 40			Assert.AreEqual(expectedRowCount, docRead.Cases.Count);
 41		}
 42
 43		[TestMethod]
 44		[ExpectedException(typeof(InvalidOperationException))]
 45		public void ReadOnlyAddNew()
 46		{
 47			docRead.Cases.New();
 48		}
 49
 50		[TestMethod]
 51		public void New()
 52		{
 53			int oldCount = docAppend.Cases.Count;
 54			SpssCase Case = docAppend.Cases.New();
 55			Case["num"] = 5;
 56			Case.Commit();
 57			Assert.AreEqual(oldCount + 1, docAppend.Cases.Count);
 58		}
 59		[TestMethod]
 60		public void SeveralNewRows()
 61		{
 62			int oldCount = docAppend.Cases.Count;
 63			for (int i = 1; i <= 5; i++)
 64			{
 65				SpssCase Case = docAppend.Cases.New();
 66				Case["num"] = i;
 67				Case.Commit();
 68				Assert.AreEqual(oldCount + i, docAppend.Cases.Count);
 69			}
 70		}
 71
 72		[TestMethod]
 73		public void GetFirstRowValue()
 74		{
 75			SpssCase Case = docRead.Cases[0];
 76			Assert.AreEqual(82d, Case["num"]);
 77		}
 78
 79		[TestMethod]
 80		public void GetMiddleRowValue()
 81		{
 82			SpssCase Case = docRead.Cases[5];
 83			Assert.AreEqual(6d, Case["num"]);
 84		}
 85
 86		[TestMethod]
 87		public void GetSeveralRowsValues()
 88		{
 89			SpssCase case1 = docRead.Cases[0];
 90			SpssCase case2 = docRead.Cases[5];
 91			Assert.AreEqual(82d, case1["num"]);
 92			Assert.AreEqual(6d, case2["num"]);
 93			Assert.AreEqual(82d, case1["num"]);
 94		}
 95		[TestMethod]
 96		public void Enumerator()
 97		{
 98			int c = 0;
 99			foreach (SpssCase Case in docRead.Cases)
100			{
101				Assert.IsNotNull(Case);
102				Assert.AreEqual(c, Case.Position);
103				c++;
104			}
105			Assert.AreEqual(expectedRowCount, docRead.Cases.Count);
106		}
107		[TestMethod]
108		public void ToDataTable()
109		{
110			DataTable dt = docRead.Cases.ToDataTable();
111			Assert.AreEqual(docRead.Cases.Count, dt.Rows.Count);
112			Assert.AreEqual(dt.Columns.Count, docRead.Variables.Count);
113
114			Assert.AreEqual(1d, dt.Rows[0][0]);
115			Assert.AreEqual(82d, dt.Rows[0][1]);
116			Assert.AreEqual(23d, dt.Rows[137][0]);
117			Assert.AreEqual(15d, dt.Rows[137][1]);
118		}
119	}
120
121
122}