private bool ProcessDataSourceTests(UnitTestElement test, TestMethodInfo testMethodInfo, ITestContext testContext, List <UnitTestElement> tests) { var dataRows = PlatformServiceProvider.Instance.TestDataSource.GetData(testMethodInfo, testContext); if (dataRows == null || !dataRows.Any()) { return(false); } try { int rowIndex = 0; foreach (var dataRow in dataRows) { // TODO: Test serialization rowIndex++; var displayName = string.Format(CultureInfo.CurrentCulture, Resource.DataDrivenResultDisplayName, test.DisplayName, rowIndex); var discoveredTest = test.Clone(); discoveredTest.DisplayName = displayName; discoveredTest.TestMethod.DataType = DynamicDataType.DataSourceAttribute; discoveredTest.TestMethod.SerializedData = DataSerializationHelper.Serialize(new[] { (object)rowIndex }); tests.Add(discoveredTest); } return(true); } finally { testContext.SetDataConnection(null); testContext.SetDataRow(null); } }
public void DataSerializerShouldRoundTripDateTimeOffset() { var source = new DateTimeOffset(628381323438126060, TimeSpan.FromHours(-8)); var actual = DataSerializationHelper.Deserialize( DataSerializationHelper.Serialize(new object[] { source })); actual.Should().HaveCount(1); actual[0].Should().BeOfType <DateTimeOffset>(); actual[0].As <DateTimeOffset>().Should().Be(source); }
public void DataSerializerShouldRoundTripDateTimeOfKindUtc() { var source = new DateTime(628381323438126060, DateTimeKind.Utc); var actual = DataSerializationHelper.Deserialize( DataSerializationHelper.Serialize(new object[] { source })); actual.Should().HaveCount(1); actual[0].Should().BeOfType <DateTime>(); actual[0].As <DateTime>().Should().Be(source); actual[0].As <DateTime>().Kind.Should().Be(source.Kind); }
private bool ProcessTestDataSourceTests(UnitTestElement test, MethodInfo methodInfo, UTF.ITestDataSource[] testDataSources, List <UnitTestElement> tests) { foreach (var dataSource in testDataSources) { var data = dataSource.GetData(methodInfo); var discoveredTests = new List <UnitTestElement>(); var serializationFailed = false; foreach (var d in data) { var discoveredTest = test.Clone(); discoveredTest.DisplayName = dataSource.GetDisplayName(methodInfo, d); try { discoveredTest.TestMethod.SerializedData = DataSerializationHelper.Serialize(d); discoveredTest.TestMethod.DataType = DynamicDataType.ITestDataSource; } catch (SerializationException) { serializationFailed = true; break; } discoveredTests.Add(discoveredTest); } // Serialization failed for the type, bail out. if (serializationFailed) { tests.Add(test); break; } tests.AddRange(discoveredTests); } return(true); }