@@ -768,6 +768,136 @@ public async Task CreateDropItemStreamTest(bool binaryEncodingEnabledInClient, b
768768 {
769769 Environment . SetEnvironmentVariable ( ConfigurationManager . BinaryEncodingEnabled , null ) ;
770770 }
771+ }
772+
773+ [ TestMethod ]
774+ [ Owner ( "dkunda" ) ]
775+ [ DataRow ( true , true , DisplayName = "Test scenario when binary encoding is enabled at client level and stream conversation for binary encoding is enabled." ) ]
776+ [ DataRow ( true , false , DisplayName = "Test scenario when binary encoding is enabled at client level and stream conversation for binary encoding is disabled." ) ]
777+ [ DataRow ( false , true , DisplayName = "Test scenario when binary encoding is disabled at client level and stream conversation for binary encoding is enabled." ) ]
778+ [ DataRow ( false , false , DisplayName = "Test scenario when binary encoding is disabled at client level and stream conversation for binary encoding is disabled." ) ]
779+ public async Task CreateItemStream_WithEnableBinaryResponseOptions_ShouldSkipStreamConversation (
780+ bool binaryEncodingEnabledInClient ,
781+ bool enableStreamConversationForBinaryEncoding )
782+ {
783+ Cosmos . Database database = null ;
784+ Container container = null ;
785+ try
786+ {
787+ string databaseName = "binary-encoding-db" ;
788+ string containerName = "binary-encoding-container" ;
789+ if ( binaryEncodingEnabledInClient )
790+ {
791+ Environment . SetEnvironmentVariable ( ConfigurationManager . BinaryEncodingEnabled , "True" ) ;
792+ }
793+
794+ ( string endpoint , string authKey ) = TestCommon . GetAccountInfo ( ) ;
795+ CosmosClientOptions clientOptions = new CosmosClientOptions ( )
796+ {
797+ EnableStreamConversationForBinaryEncoding = enableStreamConversationForBinaryEncoding ,
798+ } ;
799+
800+ CosmosClient cosmosClient = new (
801+ endpoint ,
802+ authKey ,
803+ clientOptions ) ;
804+
805+ DatabaseResponse dbResponse = await cosmosClient . CreateDatabaseIfNotExistsAsync ( databaseName ) ;
806+ database = dbResponse . Database ;
807+
808+ ContainerProperties properties = new ( id : containerName , partitionKeyPath : "/pk" ) ;
809+ container = await database . CreateContainerIfNotExistsAsync ( properties ) ;
810+
811+ ToDoActivity testItem = ToDoActivity . CreateRandomToDoActivity ( ) ;
812+ CosmosSerializerCore cosmosSerializer = new CosmosSerializerCore ( ) ;
813+ using ( Stream stream = cosmosSerializer . ToStream < ToDoActivity > (
814+ testItem ,
815+ canUseBinaryEncodingForPointOperations : binaryEncodingEnabledInClient ) )
816+ {
817+ if ( binaryEncodingEnabledInClient )
818+ {
819+ AssertOnResponseSerializationBinaryType ( stream ) ;
820+ }
821+ else
822+ {
823+ AssertOnResponseSerializationTextType ( stream ) ;
824+ }
825+
826+ using ( ResponseMessage response = await container . CreateItemStreamAsync (
827+ streamPayload : stream ,
828+ partitionKey : new Cosmos . PartitionKey ( testItem . pk ) ) )
829+ {
830+ Assert . IsNotNull ( response ) ;
831+ Assert . AreEqual ( HttpStatusCode . Created , response . StatusCode ) ;
832+ Assert . IsTrue ( response . Headers . RequestCharge > 0 ) ;
833+ Assert . IsNotNull ( response . Headers . ActivityId ) ;
834+ Assert . IsNotNull ( response . Headers . ETag ) ;
835+ Assert . IsNotNull ( response . Diagnostics ) ;
836+ Assert . IsTrue ( ! string . IsNullOrEmpty ( response . Diagnostics . ToString ( ) ) ) ;
837+ Assert . IsTrue ( response . Diagnostics . GetClientElapsedTime ( ) > TimeSpan . Zero ) ;
838+
839+ if ( enableStreamConversationForBinaryEncoding )
840+ {
841+ AssertOnResponseSerializationTextType ( response . Content ) ;
842+ }
843+ else
844+ {
845+ if ( binaryEncodingEnabledInClient )
846+ {
847+ AssertOnResponseSerializationBinaryType ( response . Content ) ;
848+ }
849+ else
850+ {
851+ AssertOnResponseSerializationTextType ( response . Content ) ;
852+ }
853+ }
854+ }
855+ }
856+
857+ using ( ResponseMessage response = await container . ReadItemStreamAsync (
858+ id : testItem . id ,
859+ partitionKey : new Cosmos . PartitionKey ( testItem . pk ) ) )
860+ {
861+ Assert . IsNotNull ( response ) ;
862+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
863+ Assert . IsTrue ( response . Headers . RequestCharge > 0 ) ;
864+ Assert . IsNotNull ( response . Headers . ActivityId ) ;
865+ Assert . IsNotNull ( response . Headers . ETag ) ;
866+ Assert . IsNotNull ( response . Diagnostics ) ;
867+ Assert . IsTrue ( ! string . IsNullOrEmpty ( response . Diagnostics . ToString ( ) ) ) ;
868+ Assert . IsTrue ( response . Diagnostics . GetClientElapsedTime ( ) > TimeSpan . Zero ) ;
869+
870+ if ( enableStreamConversationForBinaryEncoding )
871+ {
872+ AssertOnResponseSerializationTextType ( response . Content ) ;
873+ }
874+ else
875+ {
876+ if ( binaryEncodingEnabledInClient )
877+ {
878+ AssertOnResponseSerializationBinaryType ( response . Content ) ;
879+ }
880+ else
881+ {
882+ AssertOnResponseSerializationTextType ( response . Content ) ;
883+ }
884+ }
885+ }
886+ }
887+ finally
888+ {
889+ Environment . SetEnvironmentVariable ( ConfigurationManager . BinaryEncodingEnabled , null ) ;
890+
891+ if ( container != null )
892+ {
893+ await container . DeleteContainerStreamAsync ( ) ;
894+ }
895+
896+ if ( database != null )
897+ {
898+ await database . DeleteAsync ( ) ;
899+ }
900+ }
771901 }
772902
773903 [ TestMethod ]
0 commit comments