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); } }
static void WriteLut(Entry[] lut, string path) { BdsVersion fileVersion = new BdsVersion(); BdsVersion assemblyVersion = new BdsVersion(Assembly.GetExecutingAssembly()); fileVersion.Major = assemblyVersion.Major; fileVersion.Minor = assemblyVersion.Minor; fileVersion.Revision = assemblyVersion.Revision; fileVersion.Build = assemblyVersion.Build; fileVersion.ScmInfo = assemblyVersion.ScmInfo; string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (BinaryWriter wr = new BinaryWriter(File.Open(path, FileMode.Create))) { DataSerializationHelper.WriteHeader(wr, fileVersion, SER_FMT_VER); wr.Write(lut.Length); for (int i = 0; i < lut.Length; ++i) { wr.Write(lut[i].CardSet); wr.Write(lut[i].Ahvo); } } }
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); }
static Entry[] ReadLut(string path) { Entry[] lut = null; using (BinaryReader r = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { BdsVersion fileVersion; int serFmtVersion; DataSerializationHelper.ReadHeader(r, out fileVersion, out serFmtVersion, SER_FMT_VER); int count = r.ReadInt32(); lut = new Entry[count]; for (int i = 0; i < count; ++i) { lut[i].CardSet = r.ReadUInt64(); lut[i].Ahvo = r.ReadSingle(); } } return(lut); }
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); }
internal UnitTestResult[] RunTestMethod() { Debug.Assert(this.test != null, "Test should not be null."); Debug.Assert(this.testMethodInfo.TestMethod != null, "Test method should not be null."); List <UTF.TestResult> results = new List <UTF.TestResult>(); var isDataDriven = false; if (this.testMethodInfo.TestMethodOptions.Executor != null) { if (this.test.DataType == DynamicDataType.ITestDataSource) { var data = DataSerializationHelper.Deserialize(this.test.SerializedData); var testResults = this.ExecuteTestWithDataSource(null, data); results.AddRange(testResults); } else if (this.ExecuteDataSourceBasedTests(results)) { isDataDriven = true; } else { var testResults = this.ExecuteTest(this.testMethodInfo); foreach (var testResult in testResults) { if (string.IsNullOrWhiteSpace(testResult.DisplayName)) { testResult.DisplayName = this.test.DisplayName; } } results.AddRange(testResults); } } else { PlatformServiceProvider.Instance.AdapterTraceLogger.LogError( "Not able to get executor for method {0}.{1}", this.testMethodInfo.TestClassName, this.testMethodInfo.TestMethodName); } // Get aggregate outcome. var aggregateOutcome = this.GetAggregateOutcome(results); this.testContext.SetOutcome(aggregateOutcome); // Set a result in case no result is present. if (!results.Any()) { results.Add(new UTF.TestResult() { Outcome = aggregateOutcome, TestFailureException = new TestFailedException(UnitTestOutcome.Error, Resource.UTA_NoTestResult) }); } // In case of data driven, set parent info in results. if (isDataDriven) { results = this.UpdateResultsWithParentInfo(results, Guid.NewGuid()); } return(results.ToArray().ToUnitTestResults()); }