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 6893487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:39:53+00:00 2026-05-27T06:39:53+00:00

I get following AssertFailedException and can’t see, why this happens. CollectionAssert.AreEquivalent failed. The expected

  • 0

I get following AssertFailedException and can’t see, why this happens.

CollectionAssert.AreEquivalent failed. The expected collection
contains 1 occurrence(s) of <FileExporter.Document>. The actual
collection contains 0 occurrence(s).

Code:

[TestMethod]
public void GetDocumentsTest()
{
    List<Document> testDocuments = new List<Document>() {
      new Document(){ Path = "TestDoc1", Language = "DEU" }
    , new Document(){ Path = "TestDoc2", Language = "ENG" }
    };

    string sqlCommand = "SELECT Path, LanguageCode FROM Document WITH(NOLOCK) ORDER BY Id";
    string connectionString = "Data Source=|DataDirectory|\\Documents.sdf;Persist Security Info=False;";
    List<Document> documents = new DataAccessManagerTestMockup().GetDocuments(sqlCommand, connectionString);
// Sql gets same documents with same path and same language

    CollectionAssert.AreEquivalent(testDocuments, documents);
}

Update:

namespace FileExporter
{
    public class Document
    {
        public string Path { get; set; }

        public string Language { get; set; }

        public bool Equals(Document y)
        {
            if (object.ReferenceEquals(this, y))
                return true;
            if (object.ReferenceEquals(this, null) || object.ReferenceEquals(y, null))
                return false;
            return this.Path == y.Path && this.Language == y.Language;
        }
    }
}

Update 2:

I think i shouldn’t spend a night in cologne (3 hours driving time) and try to code.
Colleague just said me i should override equals and use an object instead of Document.

namespace FileExporter
{
    public class Document
    {
        public string Path { get; set; }

        public string Language { get; set; }

        public override bool Equals(object y)
        {
            if (object.ReferenceEquals(this, y))
                return true;
            if (object.ReferenceEquals(this, null) || object.ReferenceEquals(y, null))
                return false;
            return this.Path == ((Document) y).Path && this.Language == ((Document) y).Language;
        }
        public override int GetHashCode()
        {
        if (this == null)
            return 0;
        int hashCodePath = this.Path == null ? 0 : this.Path.GetHashCode();
        int hashCodeLanguage = this.Language == null ? 0 : this.Language.GetHashCode();

        return hashCodePath ^ hashCodeLanguage;

        }
}
  • 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-05-27T06:39:54+00:00Added an answer on May 27, 2026 at 6:39 am

    For this to succeed your Document class needs to implement (override) Equals()

    You can verify this easily:

    var d1 = new Document(){ Path = "TestDoc1", Language = "DEU" };
    var d2 = new Document(){ Path = "TestDoc1", Language = "DEU" };
    
    Assert.AreEqual(d1, d2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I convert Base64 encode data into hex format. I get following data
When installing Rails 3.0.1 i always get following error message, although i can use
I'm probably doing something very stupid but I can't get following regexp to work
This is my code for AES. Under Gingerbread I get following error after encrypting
Our application can get following numbers: 0.1 0.02 0.003 etc. These values treated by
I get following error when deploying on test server with II6 and Framework 3.5
Why do I get following error when trying to start a ruby on rails
When using GWT I get following warning: Referencing deprecated class 'com.google.gwt.user.client.rpc.SerializableException' While it's only
When I process a cube in Visual Studio 2005 I get following message: Process
When I compile my application , I get following compile error. Unable to find

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.