Uebungsaufgaben/Semester3/DotNET/Aufgabenblatt4/Aufgabe12/UnitTest1.cs
2024-12-19 23:55:07 +01:00

143 lines
4.8 KiB
C#

using Aufgabe11;
namespace Aufgabe12
{
[TestClass]
public class SalesRepresentativeRepositoryTest
{
public static SalesRepresentativeRepository Repo1 = new SalesRepresentativeRepository();
public static List<SalesRepresentative> EmtyList = new List<SalesRepresentative>();
public static List<SalesRepresentative> GetDummySalesRepresentatives()
{
return new List<SalesRepresentative>
{
new SalesRepresentative
{
FirstName = "Alice",
LastName = "Smith",
Company = "TechCorp",
Area = "Hessen",
SalesVolume = 15000
},
new SalesRepresentative
{
FirstName = "Bob",
LastName = "Johnson",
Company = "InnovateInc",
Area = "Hessen",
SalesVolume = 900
},
new SalesRepresentative
{
FirstName = "Charlie",
LastName = "Brown",
Company = "InnovateInc",
Area = "Baden-Württemberg",
SalesVolume = 18000
}
};
}
[TestMethod]
public void GetSalesRepsFromBadenWuerttembergNullTest()
{
var result = Repo1.GetSalesRepsFromBadenWuerttemberg(null);
// Assert.ThrowsException<ArgumentNullException>(() => Repo1.GetSalesRepsFromBadenWuerttemberg(null));
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void GetSalesRepsFromBadenWuerttembergEmtyTest()
{
var result = Repo1.GetSalesRepsFromBadenWuerttemberg(EmtyList);
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void GetSalesRepsFromBadenWuerttembergDummyTest()
{
var result = Repo1.GetSalesRepsFromBadenWuerttemberg(GetDummySalesRepresentatives());
Assert.IsNotNull(result);
Assert.AreEqual(1, result.Count);
var expected = new List<(string, string, string, decimal)>
{
("Charlie", "Brown", "InnovateInc", 18000)
};
CollectionAssert.AreEqual(expected, result);
}
[TestMethod]
public void GetSalesRepsGroupedByCompanyNullTest()
{
var result = Repo1.GetSalesRepsGroupedByCompany(null);
// Assert.ThrowsException<ArgumentNullException>(() => Repo1.GetSalesRepsGroupedByCompany(null));
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void GetSalesRepsGroupedByCompanyEmtyTest()
{
var result = Repo1.GetSalesRepsGroupedByCompany(EmtyList);
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void GetSalesRepsGroupedByCompanyDummyTest()
{
var result = Repo1.GetSalesRepsGroupedByCompany(GetDummySalesRepresentatives());
Assert.IsNotNull(result);
Assert.AreEqual(2, result.Count);
var expected = new List<(string, string, string, string, decimal)>
{
("Charlie", "Brown", "InnovateInc", "Baden-Württemberg", 18000),
("Alice", "Smith", "TechCorp", "Hessen", 15000)
};
CollectionAssert.AreEqual(expected, result);
}
[TestMethod]
public void GetTopTenLosersNullTest()
{
var result = Repo1.GetTopTenLosers(null);
// Assert.ThrowsException<ArgumentNullException>(() => Repo1.GetTopTenLosers(null));
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void GetTopTenLosersEmtyTest()
{
var result = Repo1.GetTopTenLosers(EmtyList);
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void GetTopTenLosersDummyTest()
{
var result = Repo1.GetTopTenLosers(GetDummySalesRepresentatives());
Assert.IsNotNull(result);
Assert.AreEqual(3, result.Count);
var expected = new List<(string, string, string, string, decimal)>
{
("Bob", "Johnson", "InnovateInc", "Hessen", 900),
("Alice", "Smith", "TechCorp", "Hessen", 15000),
("Charlie", "Brown", "InnovateInc", "Baden-Württemberg", 18000)
};
CollectionAssert.AreEqual(expected, result);
}
}
}