Hillgrove
Hillgrove
CC#
Created by Hillgrove on 9/24/2024 in #help
MSTest: How to assert 2 collections
I am trying to make a unit test to see if the objects in 1 collection (and the order for that matter) are the same (as in different objects, same values) as the ones in another collection. This fails, as apparently CollectionAssert.AreEqual is a reference test.
[TestClass()]
public class TrophiesRepositoryTests
{
private TrophiesRepository trophyRepo = new();

[TestInitialize]
public void Setup()
{
trophyRepo.Add(new Trophy { Id = 1, Competition = "World Cup", Year = 1998 });
trophyRepo.Add(new Trophy { Id = 2, Competition = "Champions League", Year = 2020 });
trophyRepo.Add(new Trophy { Id = 3, Competition = "Copa America", Year = 2016 });
trophyRepo.Add(new Trophy { Id = 4, Competition = "Euro Cup", Year = 2004 });
trophyRepo.Add(new Trophy { Id = 5, Competition = "Olympics", Year = 2008 });
}

// MethodName_StateUnderTest_ExpectedBehavior

#region Get Tests
[TestMethod()]
public void Get_WithNoParameters_ReturnsEntireList()
{
// Arrange
List<Trophy> expected = new List<Trophy>
{
new Trophy { Id = 1, Competition = "World Cup", Year = 1998 },
new Trophy { Id = 2, Competition = "Champions League", Year = 2020 },
new Trophy { Id = 3, Competition = "Copa America", Year = 2016 },
new Trophy { Id = 4, Competition = "Euro Cup", Year = 2004 },
new Trophy { Id = 5, Competition = "Olympics", Year = 2008 }
};

// Act
List<Trophy> actual = trophyRepo.Get();

// Assert
CollectionAssert.AreEqual(expected, actual);
Assert.AreEqual(5, actual.Count);
}
#endregion
}
[TestClass()]
public class TrophiesRepositoryTests
{
private TrophiesRepository trophyRepo = new();

[TestInitialize]
public void Setup()
{
trophyRepo.Add(new Trophy { Id = 1, Competition = "World Cup", Year = 1998 });
trophyRepo.Add(new Trophy { Id = 2, Competition = "Champions League", Year = 2020 });
trophyRepo.Add(new Trophy { Id = 3, Competition = "Copa America", Year = 2016 });
trophyRepo.Add(new Trophy { Id = 4, Competition = "Euro Cup", Year = 2004 });
trophyRepo.Add(new Trophy { Id = 5, Competition = "Olympics", Year = 2008 });
}

// MethodName_StateUnderTest_ExpectedBehavior

#region Get Tests
[TestMethod()]
public void Get_WithNoParameters_ReturnsEntireList()
{
// Arrange
List<Trophy> expected = new List<Trophy>
{
new Trophy { Id = 1, Competition = "World Cup", Year = 1998 },
new Trophy { Id = 2, Competition = "Champions League", Year = 2020 },
new Trophy { Id = 3, Competition = "Copa America", Year = 2016 },
new Trophy { Id = 4, Competition = "Euro Cup", Year = 2004 },
new Trophy { Id = 5, Competition = "Olympics", Year = 2008 }
};

// Act
List<Trophy> actual = trophyRepo.Get();

// Assert
CollectionAssert.AreEqual(expected, actual);
Assert.AreEqual(5, actual.Count);
}
#endregion
}
3 replies
CC#
Created by Hillgrove on 11/19/2023 in #help
Git and Google Drive
new git user.. it seems to have your local repositories in a google drive controlled file structure can fuck stuff up. I'm quite OCD/anal about my folder structure, so before I have to find a new place for my local repositories to live, I'd like to hear if there are any other solutions?
20 replies
CC#
Created by Hillgrove on 11/3/2023 in #help
❔ Learning platform
I'm currently learning C# at CS education. It's going great, but as we're dipping our toes into abstracts, virtual classes, and interfaces I would like more experience in my fingers and my teacher can't provide more cases. I've previously done Harvard's CS50, JetBrains Python course on Hyperskill, and started Java on MOOC.fi and I'm looking for something similar for C#. Does such a learning tool exist?
5 replies