public void ExtractParameter_ShouldAddEqualParametersThanDataRowColumns() { //ARRANGE var dictionary = new Dictionary <string, object>(); dictionary["testColumn1"] = "testValue1"; dictionary["testColumn2"] = 2; var dataObjectFactory = A.Fake <IDataObjectFactory>(); ConfigurationFake.CallsTo(x => x.DataObjectFactory) .Returns(dataObjectFactory); var dataParameterCollectionFake = A.Fake <IDataParameterCollection>(); CommandFake.CallsTo(x => x.Parameters) .Returns(dataParameterCollectionFake); var context = CreateContext(dictionary); SqlPrimitiveDataTypesFake.CallsTo(x => x.IsSqlPrimitiveType(A <Type> ._)) .Returns(true); //ACT _parameterExtractor.ExtractParameter(context); //ASSERT dataParameterCollectionFake.CallsTo( x => x.Add(A <IDbDataParameter> .That.Matches( parameter => parameter.ParameterName == "testColumn1" && (string)parameter.Value == "testValue1"))) .MustHaveHappened(Repeated.Exactly.Once); dataParameterCollectionFake.CallsTo( x => x.Add(A <IDbDataParameter> .That.Matches( parameter => parameter.ParameterName == "testColumn2" && (int)parameter.Value == 2))) .MustHaveHappened(Repeated.Exactly.Once); dataObjectFactory.CallsTo(x => x.CreateDataParameter()) .MustHaveHappened(Repeated.Exactly.Twice); }
public void ExtractParameter_ShouldAddEqualParametersThanObjectProperties() { //ARRANGE const string firstItem = "test1"; const int secondItem = 2; var obj = new Tuple <string, int>(firstItem, secondItem); var context = CreateContext(obj); var dataObjectFactory = A.Fake <IDataObjectFactory>(); ConfigurationFake.CallsTo(x => x.DataObjectFactory) .Returns(dataObjectFactory); var dataParameterCollectionFake = A.Fake <IDataParameterCollection>(); CommandFake.CallsTo(x => x.Parameters) .Returns(dataParameterCollectionFake); SqlPrimitiveDataTypesFake.CallsTo(x => x.IsSqlPrimitiveType(A <Type> ._)) .Returns(true); //ACT _parameterExtractor.ExtractParameter(context); //ASSERT dataParameterCollectionFake.CallsTo( x => x.Add(A <IDbDataParameter> .That.Matches( parameter => parameter.ParameterName == "Item1" && (string)parameter.Value == firstItem))) .MustHaveHappened(Repeated.Exactly.Once); dataParameterCollectionFake.CallsTo( x => x.Add(A <IDbDataParameter> .That.Matches( parameter => parameter.ParameterName == "Item2" && (int)parameter.Value == secondItem))) .MustHaveHappened(Repeated.Exactly.Once); dataObjectFactory.CallsTo(x => x.CreateDataParameter()) .MustHaveHappened(Repeated.Exactly.Twice); }
public void ExtractParameter_ShouldAddEqualParametersThanDataRowColumns() { //ARRANGE var dataTable = new DataTable(); dataTable.Columns.Add("testColumn1", typeof(string)); dataTable.Columns.Add("testColumn2", typeof(int)); dataTable.Rows.Add("testValue1", 2); var dataObjectFactory = A.Fake <IDataObjectFactory>(); ConfigurationFake.CallsTo(x => x.DataObjectFactory) .Returns(dataObjectFactory); var dataParameterCollectionFake = A.Fake <IDataParameterCollection>(); CommandFake.CallsTo(x => x.Parameters) .Returns(dataParameterCollectionFake); var context = CreateContext(dataTable); //ACT _parameterExtractor.ExtractParameter(context); //ASSERT dataParameterCollectionFake.CallsTo( x => x.Add(A <IDbDataParameter> .That.Matches( parameter => parameter.ParameterName == "testColumn1" && (string)parameter.Value == "testValue1"))) .MustHaveHappened(Repeated.Exactly.Once); dataParameterCollectionFake.CallsTo( x => x.Add(A <IDbDataParameter> .That.Matches( parameter => parameter.ParameterName == "testColumn2" && (int)parameter.Value == 2))) .MustHaveHappened(Repeated.Exactly.Once); dataObjectFactory.CallsTo(x => x.CreateDataParameter()) .MustHaveHappened(Repeated.Exactly.Twice); }