Hello,

This may not matter to other people, but I wanted to place this here just
in case someone else has the same problem:

        [Fact]
        public void YesNoType_Returns_N_From_NullSafeSet() {
            var sessionImplementor = new Mock<ISessionImplementor>();
            var dbCommand = new Mock<DbCommand>();
            var dbParameterCollection = new Mock<DbParameterCollection>();

            var dbParameter = Mock.Of<DbParameter>();
            dbParameter.Value = string.Empty;

            dbParameterCollection.Protected()
                .Setup<DbParameter>("GetParameter", new object[] {
It.IsAny<int>() }).Returns(dbParameter);

            dbCommand.Protected()
                .Setup<DbParameterCollection>("DbParameterCollection")
                .Returns(dbParameterCollection.Object);

            var type = new YesNoType();

            type.NullSafeSet(dbCommand.Object, false, 0,
sessionImplementor.Object);
            dbCommand.Object.Parameters[0].Value.ShouldBe("N");
        }


I took a look at the DbParameterCollection and it has an abstract,
protected GetParameter method which I was able to setup.

Thanks again for your help on this issue.

2018-04-06 9:49 GMT-04:00 Robert Eberhart <robert.eberh...@gmail.com>:

> Thank you for your response.
>
> You are correct.
>
> Upon reviewing your answer, the issue I'm having is less with DbCommand
> than with the DbParameterCollection.  I'm using Moq and when I try to
> mock/fake the DbCommand and set up the DbParameterCollection using a
> variety of standard techniques, Moq pitches a fit.
>
> However, your answer combined with a review of the DbParameterCollection
> class gave me an idea.  I'm going to give it a shot and see if it works.
>
> Sincerely,
> Robert
>
> 2018-04-05 20:38 GMT-04:00 Alexander Zaytsev <haz...@gmail.com>:
>
>> DbCommand is an abstract class. It should be testable the same way as
>> the IDbCommand interface.
>>
>> The reason to change is that interfaces are immutable (at least in
>> Microsoft's point of view on BCL) - once set it cannot have methods added
>> or removed. The abstract classes are more fluid and can have additional
>> methods (if the method itself is not abstract). The particular functions we
>> were interested from abstract classes are the *Async methods which were
>> added to the class hierarchy, but not to the interfaces.
>>
>> Best Regards,
>> Alexander
>>
>> On Fri, Apr 6, 2018 at 10:51 AM, TheNephalim <robert.eberh...@gmail.com>
>> wrote:
>>
>>> I was writing some unit tests for a custom type and everything was fine
>>> until I got to NullSafeSet:
>>>
>>>         public void NullSafeSet(DbCommand cmd, object value, int index,
>>> ISessionImplementor session) {
>>>             if (value == null) {
>>>                 ((IDataParameter)cmd.Parameters[index]).Value =
>>> DBNull.Value;
>>>             } else {
>>>                 var yes = (bool)value;
>>>                 ((IDataParameter)cmd.Parameters[index]).Value = yes ?
>>> "Y" : "N";
>>>             }
>>>         }
>>>
>>> It appears that on change NH-3431 there was a mass replace of the usage
>>> of System.Data classes to System.Data.Common classes.  The code moved from
>>> interfaces in the function signatures to concrete classes.  This makes it
>>> not possible to test this method, as far as I can tell, without actually
>>> trying to instantiate an instance of a command to pass into the method.
>>>
>>> Does anyone have an idea of why this choice was made?  It is what it is
>>> at this point.  I'm just curious as to the reasoning.
>>>
>>> - Robert
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "nhusers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to nhusers+unsubscr...@googlegroups.com.
>>> To post to this group, send email to nhusers@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/nhusers.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "nhusers" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/nhusers/39RnNkXgz78/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> nhusers+unsubscr...@googlegroups.com.
>> To post to this group, send email to nhusers@googlegroups.com.
>> Visit this group at https://groups.google.com/group/nhusers.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To post to this group, send email to nhusers@googlegroups.com.
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to