<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:29 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-1029] Introduce interfaces for IBsonReader/IBsonWriter</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1029</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;To enable easier testing of serializers (along with other benefits), interfaces should be introduced where BsonReader and BsonWriter are currently being used.&lt;/p&gt;

&lt;p&gt;Old&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
In order to unit test a custom bson serializers, a mock of BsonReader and BsonWriter need to be provided.&lt;/p&gt;

&lt;p&gt;If the custom serializer depends on the CurrentBsonType or State properties, it can not be tested easily, as these properties are not virtual, and have protected setters.&lt;/p&gt;

&lt;p&gt;There is an ugly workaround to create your own abstract inheritors of the above classes, where one can provide a public method to set these properties, and then for the test to mock that inheritors.&lt;/p&gt;

&lt;p&gt;A better approach would be to make  these properties virtual, providing for a better user code testability.&lt;/p&gt;</description>
                <environment></environment>
        <key id="152154">CSHARP-1029</key>
            <summary>Introduce interfaces for IBsonReader/IBsonWriter</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="sunnybg">Svetoslav Milenov</reporter>
                        <labels>
                            <label>bson</label>
                    </labels>
                <created>Tue, 12 Aug 2014 13:22:00 +0000</created>
                <updated>Thu, 2 Apr 2015 18:06:05 +0000</updated>
                            <resolved>Wed, 3 Dec 2014 21:10:24 +0000</resolved>
                                    <version>1.9.2</version>
                                    <fixVersion>2.0</fixVersion>
                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="777787" author="xgen-internal-githook" created="Wed, 3 Dec 2014 20:52:49 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rstam&apos;, u&apos;name&apos;: u&apos;rstam&apos;, u&apos;email&apos;: u&apos;robert@robertstam.org&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1029&quot; title=&quot;Introduce interfaces for IBsonReader/IBsonWriter&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1029&quot;&gt;&lt;del&gt;CSHARP-1029&lt;/del&gt;&lt;/a&gt;: Introduce IBsonReader and IBsonWriter interfaces.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/f5b902c65f52d92e380888521e2bedd69a0982f4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/f5b902c65f52d92e380888521e2bedd69a0982f4&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="688647" author="craiggwilson" created="Tue, 12 Aug 2014 21:15:14 +0000"  >&lt;p&gt;We have discussed changing these to interfaces as well, just haven&apos;t pulled the trigger. Too many other, more important things to do.&lt;/p&gt;

&lt;p&gt;While we can certainly debate the philosophy of what a pure unit test is, our current ones don&apos;t require any extrenal dependencies other than a working BsonWriter/BsonReader. And since those can be instantiated based on byte arrays or from parsing json fairly easily, we believe it much more clear to be testing with actual implementations of these classes. I do, however, understand your dilemna that all you want to do is test something small.&lt;/p&gt;

&lt;p&gt;So... I don&apos;t think making these virtual is the right thing. The right thing is to use interfaces for BsonWriter/BsonReader. We are not at a point where we are able to discuss this change, so please don&apos;t go and do this. I am going to change this ticket&apos;s description to Introduce interfaces for BsonReader and BsonWriter to remind us this is important.&lt;/p&gt;</comment>
                            <comment id="688481" author="sunnybg" created="Tue, 12 Aug 2014 19:03:04 +0000"  >&lt;p&gt;Hi Craig,&lt;br/&gt;
Actually, if you need only to check if the value to be deserialized is null (i.e. BsonType.Null) in order to perform something, there is no need to have the inner working, and mocking makes sense. At least for pure unit testing POV. Same for all other abstract/virtual methods, if the custom serializer use them.&lt;/p&gt;

&lt;p&gt;I checked the tests you mention, but they are not &quot;pure&quot; &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; unit tests.&lt;/p&gt;

&lt;p&gt;Anyway, the change I proposed is the least impact on the code base. A proper solution would be to change the signature of IBsonSerializer methods to IBsonReader, and IBsonWriter, and make BsonWriter and BsonReader abstract classes to implement these interfaces. That way there will be a better decoupling. But this was a much bigger change, affecting too many files.&lt;/p&gt;

&lt;p&gt;If you think such a change is acceptable. I can change my pull request and implement it.&lt;/p&gt;</comment>
                            <comment id="688311" author="craiggwilson" created="Tue, 12 Aug 2014 17:04:08 +0000"  >&lt;p&gt;Hi Svetoslav,&lt;/p&gt;

&lt;p&gt;Thanks for the PR and suggestion. Unfortunately, there is a lot of behavior in these base classes and mocking them to test your implementation wouldn&apos;t prove much.  I&apos;d suggest looking at how our internall implemented serializers are tested, and do that. Since they don&apos;t integrate with anything (mongodb, files, etc...), this isn&apos;t a problem provides a much more robust and provable implementation.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="688200" author="sunnybg" created="Tue, 12 Aug 2014 15:51:08 +0000"  >&lt;p&gt;Pull request added: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/pull/186&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/pull/186&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hs1apz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>132083</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="353">C# Sprint 12</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>