@@ -819,6 +819,90 @@ public async Task Roundtrip_WithUserFeedback_Success()
819819 envelopeRoundtrip . Should ( ) . BeEquivalentTo ( envelope ) ;
820820 }
821821
822+ [ Fact ]
823+ public async Task Roundtrip_WithFeedback_Success ( )
824+ {
825+ // Arrange
826+ var feedback = new SentryFeedback (
827+ "Everything is great!" ,
828+ 829+ "Someone Nice" ,
830+ "fake-replay-id" ,
831+ "https://www.example.com" ,
832+ SentryId . Create ( )
833+ ) ;
834+ var evt = new SentryEvent { Level = SentryLevel . Info ,
835+ Contexts =
836+ {
837+ Feedback = feedback
838+ }
839+ } ;
840+
841+ using var envelope = Envelope . FromFeedback ( evt ) ;
842+
843+ using var stream = new MemoryStream ( ) ;
844+
845+ // Act
846+ await envelope . SerializeAsync ( stream , _testOutputLogger ) ;
847+ stream . Seek ( 0 , SeekOrigin . Begin ) ;
848+
849+ using var envelopeRoundtrip = await Envelope . DeserializeAsync ( stream ) ;
850+
851+ // Assert
852+ envelopeRoundtrip . Should ( ) . BeEquivalentTo ( envelope ) ;
853+ }
854+
855+ [ Fact ]
856+ public void FromFeedback_NoFeedbackContext_Throws ( )
857+ {
858+ // Arrange
859+ var evt = new SentryEvent { Level = SentryLevel . Info } ;
860+
861+ // Act
862+ Action act = ( ) => Envelope . FromFeedback ( evt ) ;
863+
864+ // Assert
865+ act . Should ( ) . Throw < ArgumentException > ( )
866+ . WithMessage ( "Unable to create envelope - the event does not contain any feedback." ) ;
867+ }
868+
869+ [ Fact ]
870+ public void FromFeedback_MultipleAttachments_LogsWarning ( )
871+ {
872+ // Arrange
873+ var feedback = new SentryFeedback (
874+ "Everything is great!" ,
875+ 876+ "Someone Nice" ,
877+ "fake-replay-id" ,
878+ "https://www.example.com" ,
879+ SentryId . Create ( )
880+ ) ;
881+ var evt = new SentryEvent { Level = SentryLevel . Info ,
882+ Contexts =
883+ {
884+ Feedback = feedback
885+ }
886+ } ;
887+ var logger = Substitute . For < IDiagnosticLogger > ( ) ;
888+ logger . IsEnabled ( Arg . Any < SentryLevel > ( ) ) . Returns ( true ) ;
889+
890+ List < SentryAttachment > attachments = [
891+ AttachmentHelper . FakeAttachment ( "file1.txt" ) , AttachmentHelper . FakeAttachment ( "file2.txt" )
892+ ] ;
893+
894+ // Act
895+ using var envelope = Envelope . FromFeedback ( evt , logger , attachments ) ;
896+
897+ // Assert
898+ logger . Received ( 1 ) . Log (
899+ SentryLevel . Warning ,
900+ Arg . Is < string > ( m => m . Contains ( "Feedback can only contain one attachment" ) ) ,
901+ null ,
902+ Arg . Any < object [ ] > ( ) ) ;
903+ envelope . Items . Should ( ) . ContainSingle ( item => item . Header [ EnvelopeItem . TypeKey ] . ToString ( ) == EnvelopeItem . TypeValueAttachment ) ;
904+ }
905+
822906 [ Fact ]
823907 public async Task Roundtrip_WithSession_Success ( )
824908 {
0 commit comments