Skip to content

Commit fc4143e

Browse files
committed
WARESCAN-71 #comment Ensure unix epoch is UTC. Added unit test project.
1 parent 596b556 commit fc4143e

11 files changed

+435
-11
lines changed

Data/WebServiceDataAdapter.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class WebServiceDataAdapter : DataAdapter
2929
public LastModifiedDictionary lastModifiedDict = new LastModifiedDictionary();
3030
public event BeforeImportHandler BeforeImport;
3131
private WebServiceClient webServiceClient = null;
32+
private WebServiceDateTimeConverter dateTimeConverter = new WebServiceDateTimeConverter();
3233

3334
public WebServiceDataAdapter(WebServiceClient client)
3435
{
@@ -49,7 +50,7 @@ public override int Fill(DataSet dataSet)
4950
{
5051
lastModified = DateTime.Now - TimeSpan.FromDays(90); // TODO: 90 days is arbitrary
5152
}
52-
int modifiedTime = ToUnixTime(lastModified);
53+
int modifiedTime = dateTimeConverter.ToUnixTime(lastModified);
5354
JToken token = webServiceClient.DoSync(modifiedTime.ToString(), table.TableName);
5455
if (token != null)
5556
{
@@ -126,19 +127,18 @@ private JToken ToToken(DataTable table)
126127
{
127128
using (JTokenWriter writer = new JTokenWriter())
128129
{
129-
JsonSerializer serializer = new JsonSerializer();
130-
serializer.Converters.Add(new DataTableConverter());
130+
JsonSerializer serializer = GetJsonSerializer();
131131
serializer.Serialize(writer, table);
132132
return writer.Token;
133133
}
134134
}
135135

136-
private int ToUnixTime(DateTime dateTime)
136+
private JsonSerializer GetJsonSerializer()
137137
{
138-
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();
139-
TimeSpan span = dateTime - epoch;
140-
int unixtime = (int)Math.Round(span.TotalSeconds);
141-
return unixtime;
138+
JsonSerializer serializer = new JsonSerializer();
139+
serializer.Converters.Add(new DataTableConverter());
140+
//serializer.Converters.Add(dateTimeConverter);
141+
return serializer;
142142
}
143143
}
144144
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using Newtonsoft.Json;
6+
using Newtonsoft.Json.Converters;
7+
8+
namespace Vtiger.Data
9+
{
10+
class WebServiceDateTimeConverter : DateTimeConverterBase
11+
{
12+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
13+
{
14+
// TODO
15+
}
16+
17+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
18+
{
19+
// TODO
20+
return null;
21+
}
22+
23+
public int ToUnixTime(DateTime dateTime)
24+
{
25+
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
26+
TimeSpan span = dateTime - epoch;
27+
int unixtime = (int)Math.Round(span.TotalSeconds);
28+
return unixtime;
29+
}
30+
}
31+
}

SmartDeviceTestRun.testrunConfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TestRunConfiguration xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006" id="d029e424-54cc-4f9f-8edf-81888e653d88" name="Local SmartDevices Test Run">
3+
<Description>This is a default test run configuration for a local SmartDevice test run.</Description>
4+
<Timeouts testTimeout="1800000"/>
5+
<Hosts type="Smart Device">
6+
<DeviceHostRunConfigData name="Smart Device" deviceId="6A809CD4-1A5E-49d8-8704-F23565E97F53" deviceName="Windows Mobile 6.5.3 Professional Emulator" platformId="2AC76CE7-3E8C-402d-85E7-AE9C98D7B6BA" platformName="Windows Mobile 6.5.3 Professional DTK" uiPlatformId="2AC76CE7-3E8C-402d-85E7-AE9C98D7B6BA"/>
7+
</Hosts>
8+
</TestRunConfiguration>

vtwsclib.NET.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<AssemblyName>vtwsclib.NET</AssemblyName>
1212
<ProjectTypeGuids>{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1313
<PlatformFamilyName>PocketPC</PlatformFamilyName>
14-
<PlatformID>4118C335-430C-497f-BE48-11C3316B135E</PlatformID>
15-
<OSVersion>5.1</OSVersion>
14+
<PlatformID>2AC76CE7-3E8C-402d-85E7-AE9C98D7B6BA</PlatformID>
15+
<OSVersion>5.02</OSVersion>
1616
<DeployDirSuffix>vtwsclib.NET</DeployDirSuffix>
1717
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
18-
<NativePlatformName>Windows Mobile 5.0 Pocket PC SDK</NativePlatformName>
18+
<NativePlatformName>Windows Mobile 6.5.3 Professional DTK</NativePlatformName>
1919
<FormFactorID>
2020
</FormFactorID>
2121
</PropertyGroup>
@@ -54,6 +54,7 @@
5454
<Reference Include="System.Xml" />
5555
</ItemGroup>
5656
<ItemGroup>
57+
<Compile Include="Data\WebServiceDateTimeConverter.cs" />
5758
<Compile Include="Data\WebServiceDataAdapter.cs">
5859
<SubType>Component</SubType>
5960
</Compile>

vtwsclib.NET.sln

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 10.00
3+
# Visual Studio 2008
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vtwsclib.NET", "vtwsclib.NET.csproj", "{E39EC7A7-827A-48BE-AC82-0E2578F9413C}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Compact", "..\JSON.NET\Newtonsoft.Json\Newtonsoft.Json.Compact.csproj", "{256AA604-F61B-4B6D-8D51-C8E6AB11E435}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vtwsclib.NET.tests", "vtwsclib.NET.tests\vtwsclib.NET.tests.csproj", "{C8C7DD8A-4BC6-4EA1-A776-ACA2D759BA58}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2DF0B43B-8D56-4BDC-A0AD-187DB98779CE}"
11+
ProjectSection(SolutionItems) = preProject
12+
SmartDeviceTestRun.testrunConfig = SmartDeviceTestRun.testrunConfig
13+
vtwsclib.NET.vsmdi = vtwsclib.NET.vsmdi
14+
EndProjectSection
15+
EndProject
16+
Global
17+
GlobalSection(TestCaseManagementSettings) = postSolution
18+
CategoryFile = vtwsclib.NET.vsmdi
19+
EndGlobalSection
20+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
21+
Debug|Any CPU = Debug|Any CPU
22+
Release|Any CPU = Release|Any CPU
23+
EndGlobalSection
24+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
25+
{E39EC7A7-827A-48BE-AC82-0E2578F9413C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{E39EC7A7-827A-48BE-AC82-0E2578F9413C}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{E39EC7A7-827A-48BE-AC82-0E2578F9413C}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{E39EC7A7-827A-48BE-AC82-0E2578F9413C}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{C8C7DD8A-4BC6-4EA1-A776-ACA2D759BA58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{C8C7DD8A-4BC6-4EA1-A776-ACA2D759BA58}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{C8C7DD8A-4BC6-4EA1-A776-ACA2D759BA58}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{C8C7DD8A-4BC6-4EA1-A776-ACA2D759BA58}.Release|Any CPU.Build.0 = Release|Any CPU
37+
EndGlobalSection
38+
GlobalSection(SolutionProperties) = preSolution
39+
HideSolutionNode = FALSE
40+
EndGlobalSection
41+
EndGlobal
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
==========================================================================
2+
Visual Studio Team System: Overview of Authoring and Running Tests
3+
==========================================================================
4+
5+
This overview describes the features for authoring and running tests in
6+
Visual Studio Team System and Visual Studio Team Edition for Software Testers.
7+
8+
Opening Tests
9+
-------------
10+
To open a test, open a test project or a test metadata file (a file with
11+
extension .vsmdi) that contains the definition of the test. You can find
12+
test projects and metadata files in Solution Explorer.
13+
14+
Viewing Tests
15+
-------------
16+
To see which tests are available to you, open the Test View window. Or,
17+
if you have installed Team Edition for Software Testers, you can also open
18+
the Test List Editor window to view tests.
19+
20+
To open the Test View window, click the Test menu, point to Windows, and
21+
then click Test View. To open the Test List Editor window (if you have
22+
installed Team Edition for Software Testers), click Test, point to Windows,
23+
and then click Test List Editor.
24+
25+
Running Tests
26+
-------------
27+
You can run tests from the Test View window and the Test List Editor window.
28+
See Viewing Tests to learn how to open these windows. To run one or more
29+
tests displayed in the Test View window, first select the tests in that
30+
window; to select multiple tests, hold either the Shift or CTRL key while
31+
clicking tests. Then click the Run Tests button in the Test View window
32+
toolbar.
33+
34+
If you have installed Visual Studio Team Edition for Software Testers, you can
35+
also use the Test List Editor window to run tests. To run tests in Test List Editor,
36+
select the check box next to each test that you want to run. Then click the
37+
Run Tests button in the Test List Editor window toolbar.
38+
39+
Viewing Test Results
40+
--------------------
41+
When you run a test or a series of tests, the results of the test run will be
42+
shown in the Test Results window. Each individual test in the run is shown on
43+
a separate line so that you can see its status. The window contains an
44+
embedded status bar in the top half of the window that provides you with
45+
summary details of the complete test run.
46+
47+
To see more detailed results for a particular test result, double-click it in
48+
the Test Results window. This opens a window that provides more information
49+
about the particular test result, such as any specific error messages returned
50+
by the test.
51+
52+
Changing the way that tests are run
53+
-----------------------------------
54+
Each time you run one or more tests, a collection of settings is used to
55+
determine how those tests are run. These settings are contained in a “test
56+
run configuration” file.
57+
58+
Here is a partial list of the changes you can make with a test run
59+
configuration file:
60+
61+
- Change the naming scheme for each test run.
62+
- Change the test controller that the tests are run on so that you can run
63+
tests remotely.
64+
- Gather code coverage data for the code being tested so that you can see
65+
which lines of code are covered by your tests.
66+
- Enable and disable test deployment.
67+
- Specify additional files to deploy before tests are run.
68+
- Select a different host, ASP.NET, for running ASP.NET unit tests.
69+
- Select a different host, the smart device test host, for running smart device unit tests.
70+
- Set various properties for the test agents that run your tests.
71+
- Run custom scripts at the start and end of each test run so that you can
72+
set up the test environment exactly as required each time tests are run.
73+
- Set time limits for tests and test runs.
74+
- Set the browser mix and the number of times to repeat Web tests in the
75+
test run.
76+
77+
By default, a test run configuration file is created whenever you create a
78+
new test project. You make changes to this file by double-clicking it in
79+
Solution Explorer and then changing its settings. (Test run configuration
80+
files have the extension .testrunconfig.)
81+
82+
A solution can contain multiple test run configuration files. Only one of
83+
those files, known as the “Active” test run configuration file, is used to
84+
determine the settings that are currently used for test runs. You select
85+
the active test run configuration by clicking Select Active Test Run
86+
Configuration on the Test menu.
87+
88+
-------------------------------------------------------------------------------
89+
90+
Test Types
91+
----------
92+
Using Visual Studio Team Edition for Software Testers, you can create a number
93+
of different test types:
94+
95+
Unit test: Use a unit test to create a programmatic test in C++, Visual C# or
96+
Visual Basic that exercises source code. A unit test calls the methods of a
97+
class, passing suitable parameters, and verifies that the returned value is
98+
what you expect.
99+
There are three specialized variants of unit tests:
100+
- Data-driven unit tests are created when you configure a unit test to be
101+
called repeatedly for each row of a data source. The data from each row
102+
is used by the unit test as input data.
103+
- ASP.NET unit tests are unit tests that exercise code in an ASP.NET Web
104+
application.
105+
- Smart device unit tests are unit tests that are deployed to a smart device
106+
or emulator and then executed by the smart device test host.
107+
108+
Web Test: Web tests consist of an ordered series of HTTP requests that you
109+
record in a browser session using Microsoft Internet Explorer. You can have
110+
the test report specific details about the pages or sites it requests, such
111+
as whether a particular page contains a specified string.
112+
113+
Load Test: You use a load test to encapsulate non-manual tests, such as
114+
unit, Web, and generic tests, and then run them simultaneously by using
115+
virtual users. Running these tests under load generates test results,
116+
including performance and other counters, in tables and in graphs.
117+
118+
Generic test: A generic test is an existing program wrapped to function as a
119+
test in Visual Studio. The following are examples of tests or programs that
120+
you can turn into generic tests:
121+
- An existing test that uses process exit codes to communicate whether the
122+
test passed or failed. 0 indicates passing and any other value indicates
123+
a failure.
124+
- A general program to obtain specific functionality during a test scenario.
125+
- A test or program that uses a special XML file (called a “summary results
126+
file”), to communicate detailed results.
127+
128+
Manual test: The manual test type is used when the test tasks are to be
129+
completed by a test engineer as opposed to an automated script.
130+
131+
Ordered test: Use an ordered test to execute a set of tests in an order you
132+
specify.
133+
134+
-------------------------------------------------------------------------------
135+
136+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using Vtiger.Data;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using System;
4+
5+
namespace Vtiger.Data.Tests
6+
{
7+
8+
9+
/// <summary>
10+
///This is a test class for WebServiceDateTimeConverterTest and is intended
11+
///to contain all WebServiceDateTimeConverterTest Unit Tests
12+
///</summary>
13+
[TestClass()]
14+
public class WebServiceDateTimeConverterTest
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+
#region Additional test attributes
37+
//
38+
//You can use the following additional attributes as you write your tests:
39+
//
40+
//Use ClassInitialize to run code before running the first test in the class
41+
//[ClassInitialize()]
42+
//public static void MyClassInitialize(TestContext testContext)
43+
//{
44+
//}
45+
//
46+
//Use ClassCleanup to run code after all tests in a class have run
47+
//[ClassCleanup()]
48+
//public static void MyClassCleanup()
49+
//{
50+
//}
51+
//
52+
//Use TestInitialize to run code before running each test
53+
//[TestInitialize()]
54+
//public void MyTestInitialize()
55+
//{
56+
//}
57+
//
58+
//Use TestCleanup to run code after each test has run
59+
//[TestCleanup()]
60+
//public void MyTestCleanup()
61+
//{
62+
//}
63+
//
64+
#endregion
65+
66+
67+
[TestMethod()]
68+
[DeploymentItem("vtwsclib.NET.dll")]
69+
public void ToUnixTimeTest()
70+
{
71+
WebServiceDateTimeConverter_Accessor target = new WebServiceDateTimeConverter_Accessor();
72+
DateTime dateTime = new DateTime(1976, 7, 4, 0, 0, 0, DateTimeKind.Utc);
73+
int expected = 205286400;
74+
int actual = target.ToUnixTime(dateTime);
75+
Assert.AreEqual(expected, actual);
76+
}
77+
}
78+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("vtwsclib.NET.tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Microsoft")]
12+
[assembly: AssemblyProduct("vtwsclib.NET.tests")]
13+
[assembly: AssemblyCopyright("Copyright © Microsoft 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM componenets. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("f4faac29-7cfa-4268-ab0f-71d8cdb34f54")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Revision and Build Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]

0 commit comments

Comments
 (0)