Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:32:21+00:00 2026-06-17T06:32:21+00:00

I have the following method, it is an extension method and can be called

  • 0

I have the following method, it is an extension method and can be called by any Stream object.
The method should copy the exact content of a Stream into another Stream.

public static void CopyTo(this Stream input, Stream output)
{
   const int size = 10;
   int num;
   var buffer = new byte[size];
   input.Position = 0;
   while ((num = input.Read(buffer, 0, buffer.Length)) != 0)
   {
      output.Write(buffer, 0, num);
   }
}

I have created one simple test to verify that the content of the original Stream is equal to the content of the final Stream:

[TestMethod]
public void StreamWithContentShouldCopyToAnotherStream()
{
    // arrange
    var content = @"abcde12345";
    byte[] data = Encoding.Default.GetBytes(content);
    var stream = new MemoryStream(data);
    var expectedStream = new MemoryStream();
    // act
    stream.CopyTo(expectedStream);
    // assert
    expectedStream.Length
       .Should()
       .Be(stream.Length, "The length of the two streams should be the same");
}

Unfortunately I am covering just part of this method, because I don’t verify if the content is exactly the same. Also dotCover is showing me that the first part of my code is not covered at all, which is this one:

Code coverage result

My target is 100% code coverage on this method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:32:22+00:00Added an answer on June 17, 2026 at 6:32 am

    Perhaps your code is not calling your extension method but is instead calling the Stream.CopyTo(Stream) Method?

    Try renaming your extension method to avoid the name clash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an extension method called AddGZip which looks like the following: public
I have the following method which is called when the value Edit Class... is
I have the following extension method public static class ListExtensions { public static IEnumerable<T>
I have following extension method written: static public IQueryable<OutboundPattern> ByClientID(this IQueryable<OutboundPattern> qry, int clientID)
I have the following extension method which asserts that a property (Id) contains a
I have the following Method. In the fileschooser I can select a file or
I have the following method, which works perfectly. //private static IEnumerable<object> movieSequence; private static
I have the following extension method that takes a List and converts it to
I am experimenting with fluent extension methods. I have the following simple extension method
I currently have an extension Method which converts an IEnumerable of type Tab into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.