1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Data.Common; 6 using Xunit; 7 8 namespace System.Data.Tests.Common 9 { 10 public class DataColumnMappingTest 11 { 12 [Fact] DataSetColumn_Get_WhenNotSet()13 public void DataSetColumn_Get_WhenNotSet() 14 { 15 DataColumnMapping dataColumnMapping = new DataColumnMapping(); 16 17 string dataSetColumn = dataColumnMapping.DataSetColumn; 18 19 Assert.Equal(string.Empty, dataSetColumn); 20 } 21 22 [Fact] SourceColumn_Get_WhenNotSet()23 public void SourceColumn_Get_WhenNotSet() 24 { 25 DataColumnMapping dataColumnMapping = new DataColumnMapping(); 26 27 string sourceColumn = dataColumnMapping.SourceColumn; 28 29 Assert.Equal(string.Empty, sourceColumn); 30 } 31 32 [Fact] GetDataColumnBySchemaAction_String_String_DataTable_Type_MissingSchemaAction_MissingDataTableThrowsException()33 public void GetDataColumnBySchemaAction_String_String_DataTable_Type_MissingSchemaAction_MissingDataTableThrowsException() 34 { 35 AssertExtensions.Throws<ArgumentNullException>("dataTable", () => DataColumnMapping.GetDataColumnBySchemaAction("", "", null, typeof(string), new MissingSchemaAction())); 36 } 37 38 [Fact] GetDataColumnBySchemaAction_String_String_DataTable_Type_MissingSchemaAction_MissingDataSetColumnReturnsNull()39 public void GetDataColumnBySchemaAction_String_String_DataTable_Type_MissingSchemaAction_MissingDataSetColumnReturnsNull() 40 { 41 DataColumn dataColumn = DataColumnMapping.GetDataColumnBySchemaAction("", null, new DataTable(), typeof(string), new MissingSchemaAction()); 42 43 Assert.Null(dataColumn); 44 } 45 46 [Fact] GetDataColumnBySchemaAction_String_String_DataTable_Type_MissingSchemaAction_DataColumnExpressionExistsThrowsException()47 public void GetDataColumnBySchemaAction_String_String_DataTable_Type_MissingSchemaAction_DataColumnExpressionExistsThrowsException() 48 { 49 DataColumn priceColumn = new DataColumn(); 50 priceColumn.DataType = typeof(decimal); 51 priceColumn.ColumnName = "price"; 52 priceColumn.DefaultValue = 50; 53 54 DataColumn taxColumn = new DataColumn(); 55 taxColumn.DataType = typeof(decimal); 56 taxColumn.ColumnName = "tax"; 57 taxColumn.Expression = "price * 0.0862"; 58 59 DataTable dataTable = new DataTable(); 60 dataTable.Columns.Add(priceColumn); 61 dataTable.Columns.Add(taxColumn); 62 63 Assert.Throws<InvalidOperationException>(() => DataColumnMapping.GetDataColumnBySchemaAction("", "tax", dataTable, typeof(string), new MissingSchemaAction())); 64 } 65 66 [Fact] ToString_OK()67 public void ToString_OK() 68 { 69 DataColumnMapping dataColumnMapping = new DataColumnMapping("the source", ""); 70 71 Assert.Equal("the source", dataColumnMapping.ToString()); 72 } 73 } 74 } 75