|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using Intuit.QuickBase.Client; |
| 5 | +using Intuit.QuickBase.Core; |
2 | 6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
| 7 | +using QBFunctionTest.Properties; |
3 | 8 |
|
4 | 9 | namespace QBFunctionTest
|
5 | 10 | {
|
6 | 11 | [TestClass]
|
7 | 12 | public class UnitTest1
|
8 | 13 | {
|
| 14 | + private IQApplication qbApp; |
| 15 | + |
| 16 | + public void InitConnection() |
| 17 | + { |
| 18 | + var client = QuickBase.Login(Settings.Default.qbUser, Settings.Default.qbPass, Settings.Default.qbSiteURL); |
| 19 | + qbApp = client.Connect(Settings.Default.qbAppDBID, Settings.Default.qbAppToken); |
| 20 | + |
| 21 | + } |
| 22 | + |
| 23 | + class TestRecord |
| 24 | + { |
| 25 | + public string textVal; |
| 26 | + public decimal floatVal; |
| 27 | + public bool checkboxVal; |
| 28 | + public DateTime dateVal; |
| 29 | + public DateTime timeStampVal; |
| 30 | + public TimeSpan timeOfDayVal; |
| 31 | + public QAddress addressVal; |
| 32 | + public decimal currencyVal; |
| 33 | + public TimeSpan durationVal; |
| 34 | + public string emailVal; |
| 35 | + public string phoneVal; |
| 36 | + public decimal percentVal; |
| 37 | + |
| 38 | + public TestRecord() |
| 39 | + { |
| 40 | + addressVal = new QAddress(); |
| 41 | + } |
| 42 | + public void SetupTestValues() |
| 43 | + { |
| 44 | + textVal = "Test string #1"; |
| 45 | + floatVal = (decimal)3452.54; |
| 46 | + checkboxVal = true; |
| 47 | + dateVal = new DateTime(2015, 04, 15); |
| 48 | + timeStampVal = new DateTime(1970, 02, 28, 23, 55, 00, DateTimeKind.Local); |
| 49 | + timeOfDayVal = new DateTime(2000, 1, 1, 12, 34, 56).TimeOfDay; |
| 50 | + durationVal = new TimeSpan(3, 4, 5, 6); |
| 51 | + addressVal.Line1 = "1313 Mockingbird Ln"; |
| 52 | + addressVal.City = "Culver City"; |
| 53 | + addressVal.Province = "CA"; |
| 54 | + addressVal.PostalCode = "90120"; |
| 55 | + addressVal.Country = "USA"; |
| 56 | + } |
| 57 | + } |
| 58 | + |
9 | 59 | [TestMethod]
|
10 |
| - public void TestMethod1() |
| 60 | + public void BasicCreationAndRoundTripTest() |
11 | 61 | {
|
| 62 | + InitConnection(); |
| 63 | + List<GrantedAppsInfo> appsLst = qbApp.GrantedDBs(); |
| 64 | + foreach (var app in appsLst) |
| 65 | + { |
| 66 | + foreach (var tab in app.GrantedTables) |
| 67 | + { |
| 68 | + if (tab.Name == "APITestApp: APITestTable") |
| 69 | + { |
| 70 | + IQTable tbl = qbApp.GetTable(tab.Dbid); |
| 71 | + qbApp.DeleteTable(tbl); |
| 72 | + break; |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + IQTable testTable = qbApp.NewTable("APITestTable", "dummyRec"); |
| 78 | + testTable.Columns.Add(new QColumn("TextTest", FieldType.text)); |
| 79 | + testTable.Columns.Add(new QColumn("FloatTest", FieldType.@float)); |
| 80 | + testTable.Columns.Add(new QColumn("CheckboxTest", FieldType.checkbox)); |
| 81 | + testTable.Columns.Add(new QColumn("DateTest", FieldType.date)); |
| 82 | + testTable.Columns.Add(new QColumn("TimeStampTest", FieldType.timestamp)); |
| 83 | + testTable.Columns.Add(new QColumn("TimeOfDayTest", FieldType.timeofday)); |
| 84 | + testTable.Columns.Add(new QColumn("DurationTest", FieldType.duration)); |
| 85 | + //testTable.Columns.Add(new QColumn("AddressTest", FieldType.address)); |
| 86 | + //testTable.Columns.Add(new QColumn("CurrencyTest", FieldType.currency)); |
| 87 | + //testTable.Columns.Add(new QColumn("EmailTest", FieldType.email)); |
| 88 | + //testTable.Columns.Add(new QColumn("PhoneTest", FieldType.phone)); |
| 89 | + //testTable.Columns.Add(new QColumn("PercentTest", FieldType.percent)); |
| 90 | + |
| 91 | + TestRecord exemplar = new TestRecord(); |
| 92 | + exemplar.SetupTestValues(); |
| 93 | + |
| 94 | + IQRecord inRec = testTable.NewRecord(); |
| 95 | + inRec["TextTest"] = exemplar.textVal; |
| 96 | + inRec["FloatTest"] = exemplar.floatVal; |
| 97 | + inRec["CheckboxTest"] = exemplar.checkboxVal; |
| 98 | + inRec["DateTest"] = exemplar.dateVal; |
| 99 | + inRec["TimeStampTest"] = exemplar.timeStampVal; |
| 100 | + inRec["TimeOfDayTest"] = exemplar.timeOfDayVal; |
| 101 | + //inRec["DurationTest"] = exemplar.durationVal; |
| 102 | + //inRec["AddressTest"] = exemplar.addressVal; |
| 103 | + |
| 104 | + Assert.AreEqual(exemplar.textVal, inRec["TextTest"], "Strings setter fails"); |
| 105 | + Assert.AreEqual(exemplar.floatVal, inRec["FloatTest"], "Floats setter fails"); |
| 106 | + Assert.AreEqual(exemplar.checkboxVal, inRec["CheckboxTest"], "Checkboxes setter fails"); |
| 107 | + Assert.AreEqual(exemplar.dateVal, inRec["DateTest"], "Dates setter fails"); |
| 108 | + Assert.AreEqual(exemplar.timeStampVal, inRec["TimeStampTest"], "TimeStamps setter fails"); |
| 109 | + Assert.AreEqual(exemplar.timeOfDayVal, inRec["TimeOfDayTest"], "TimeOfDays setter fails"); |
| 110 | + //Assert.AreEqual(exemplar.durationVal, inRec["DurationTest"], "Durations setter fails"); |
| 111 | + |
| 112 | + testTable.Records.Add(inRec); |
| 113 | + testTable.AcceptChanges(); |
| 114 | + |
| 115 | + Assert.AreEqual(exemplar.textVal, inRec["TextTest"], "Strings wrong post upload"); |
| 116 | + Assert.AreEqual(exemplar.floatVal, inRec["FloatTest"], "Floats wrong post upload"); |
| 117 | + Assert.AreEqual(exemplar.checkboxVal, inRec["CheckboxTest"], "Checkboxes wrong post upload"); |
| 118 | + Assert.AreEqual(exemplar.dateVal, inRec["DateTest"], "Dates wrong post upload"); |
| 119 | + Assert.AreEqual(exemplar.timeStampVal, inRec["TimeStampTest"], "TimeStamps wrong post upload"); |
| 120 | + Assert.AreEqual(exemplar.timeOfDayVal, inRec["TimeOfDayTest"], "TimeOfDays wrong post upload"); |
| 121 | + //Assert.AreEqual(exemplar.durationVal, inRec["DurationTest"], "Durations wrong post upload"); |
| 122 | + |
| 123 | + testTable.Records.Clear(); |
| 124 | + testTable.Query(); |
| 125 | + |
| 126 | + IQRecord outRec = testTable.Records[0]; |
| 127 | + Assert.AreEqual(exemplar.textVal, outRec["TextTest"], "Strings don't roundtrip"); |
| 128 | + Assert.AreEqual(exemplar.floatVal, outRec["FloatTest"], "Floats don't roundtrip"); |
| 129 | + Assert.AreEqual(exemplar.checkboxVal, outRec["CheckboxTest"], "Checkboxes don't roundtrip"); |
| 130 | + Assert.AreEqual(exemplar.dateVal, outRec["DateTest"], "Dates don't roundtrip"); |
| 131 | + Assert.AreEqual(exemplar.timeStampVal, outRec["TimeStampTest"], "TimeStamps don't roundtrip"); |
| 132 | + Assert.AreEqual(exemplar.timeOfDayVal, outRec["TimeOfDayTest"], "TimeOfDays don't roundtrip"); |
| 133 | + //Assert.AreEqual(exemplar.durationVal, outRec["DurationTest"], "Durations don't roundtrip"); |
| 134 | + |
12 | 135 | }
|
13 | 136 | }
|
14 | 137 | }
|
0 commit comments