public void Name_ComputerWithEmptyName_ShouldThrowArgumentNullException() { var componentsList = new List<Component>(); componentsList.Add(new Component("HDD", 90)); var pc = new Computer(string.Empty, componentsList); }
static void Main() { List<Computer> catalog = new List<Computer>(); List<Component> components = new List<Component>(); components.Add(new Component("HDD", 240m)); components.Add(new Component("CPU", 530.87m)); components.Add(new Component("RAM", 95.50m)); Computer acer = new Computer("Acer", components); List<Component> components1 = new List<Component>(); components1.Add(new Component("CPU", 229)); components1.Add(new Component("Motheboard", 340)); components1.Add(new Component("Graphics card", 339)); Computer mac = new Computer("Mac", components1); List<Component> components2 = new List<Component>(); components2.Add(new Component("CPU", 129)); components2.Add(new Component("RAM", 125m, "4GB")); Computer hp = new Computer("HP", components2); catalog.Add(acer); catalog.Add(mac); catalog.Add(hp); var sortCatalog = catalog.OrderBy(computer => computer.Price); foreach (var computer in sortCatalog) { Console.WriteLine(computer); } }
public void Computer_ComputerWithValidInfo_ShouldPassTest() { var componentsList = new List<Component>(); componentsList.Add(new Component("HDD", 90)); var pc = new Computer("HP", componentsList); }
internal static void Main() { // 1st test option: // You can run the Unit Tests from the Visual Studio menu: // BUILD -> Build Solution // TEST -> Windows -> Test Explorer (you will see in the Test Explorer window: Not Run Tests or Passed Tests // and above it: Run All // Please, click on Run All, and read the ClassComponentTests.cs and the ClassComputerTests.cs files for more details // 2nd test option: Ctrl + F5 // start catalog var catalog = new List<Computer>(); // 1st computer var componentsList1 = new List<Component>(); componentsList1.Add(new Component("Motherboard", 90)); componentsList1.Add(new Component("CPU", 120.45m)); componentsList1.Add(new Component("RAM", 45.50m, "8 GB")); // adding additional component to already created Computer object var pc = new Computer("HP", componentsList1); Console.WriteLine(pc); pc.AddComponent(new Component("added later", 126)); // Using method that allows addition of components Console.WriteLine(pc); catalog.Add(pc); // 2nd computer var componentsList2 = new List<Component>(); componentsList2.Add(new Component("DVD", 15.99m)); componentsList2.Add(new Component("GPU", 255.1m)); catalog.Add(new Computer("Cheap", componentsList2)); // 3rd computer var componentsList3 = new List<Component>(); componentsList3.Add(new Component("RAM", 52.19m)); componentsList3.Add(new Component("SSD", 550)); catalog.Add(new Computer("Average", componentsList3)); // 4th computer var componentsList4 = new List<Component>(); componentsList4.Add(new Component("GPU", 1125.5m)); componentsList4.Add(new Component("CPU", 900)); catalog.Add(new Computer("Expensive", componentsList4)); catalog.Sort(); // IComparable interface implemented on Computer class Console.WriteLine("\r\n" + new string('-', 50) + "\r\n" + "COMPUTER CATALOG"); foreach (var computer in catalog) { Console.WriteLine(computer); } }
static void Main(string[] args) { List<Component> parts = new List<Component>(); Component part1 = new Component("Hdd", "250 gb", 100m); Component part2 = new Component("MB", "Foxcon", 100m); Component part3 = new Component("PSU", 100m); parts.Add(part1); parts.Add(part2); parts.Add(part3); Computer comp1 = new Computer("Super Comp", parts); Console.WriteLine(comp1.ToString()); }
static void Main(string[] args) { Computer pc1 = new Computer("Toshiba b12", new Component("I5", 123), new Component("ADATA DDR3 gb", 50), new Component("EVGA gtx000", 300)); Computer pc2 = new Computer("Lenovo asd", new Component("I7", 200), new Component("ADATA DDR3 4gb", 50), new Component("EVGA gtx950", 500)); Computer pc3 = new Computer("LG asd", new Component("I3", 70), new Component("ADATA DDR3 8gb", 100), new Component("EVGA gtx500", 180)); Computer pc4 = new Computer("ASUS dsa", new Component("Pentium", 40), new Component("ADATA DDR3 16gb", 200), new Component("EVGA gtx000", 300)); List<Computer> pcList = new List<Computer> { pc1, pc2, pc3, pc4 }; System.Console.WriteLine(string.Join(", ", pcList)); pcList.Sort(); System.Console.WriteLine("After sorting by price:\n"); System.Console.WriteLine(string.Join(", ", pcList)); }
public void CompareToMethod_CorrectlyComparesComputers() { // arrange var componentsList1 = new List<Component>(); componentsList1.Add(new Component("HDD", 90)); componentsList1.Add(new Component("RAM", 120)); var pc1 = new Computer("HP", componentsList1); var componentsList2 = new List<Component>(); componentsList2.Add(new Component("HDD", 190)); componentsList2.Add(new Component("RAM", 160)); var pc2 = new Computer("Dell", componentsList1); var expected = pc1.Price.CompareTo(pc2.Price); // assert - if equal, the computers have indeed been compared by price var actual = pc1.CompareTo(pc2); Assert.AreEqual(expected, actual, "Computers were not correctly compared."); }
private static void Main() { Console.OutputEncoding = Encoding.UTF8; Thread.CurrentThread.CurrentCulture = new CultureInfo("bg-BG"); var asus = new Computer("Asus Prebuilt", new List<Component>() { new Component("CPU", "Phenom II x4", 206), new Component("RAM", "8GB 1600MHz", 60), new Component("Motherboard", "Asus something", 50), new Component("HDD", 80) }); var sony = new Computer("Sony Prebuilt", new List<Component>() { new Component("CPU", "Phenom II x4", 206), new Component("RAM", "8GB 1600MHz", 60), new Component("Motherboard", "Asus something", 50), new Component("HDD", 80) }); Console.WriteLine(asus); }
static List<Computer> AddComputers() { List<Computer> computers = new List<Computer>(); string ch = null; do { Console.Write("Enter computer's name: "); string name = Console.ReadLine(); List<Component> components = AddComponents(); Computer computer = new Computer(name, components); computers.Add(computer); Console.Write("\nAdd a new computer (y/n)?"); ch = Console.ReadLine(); Console.WriteLine(); } while (ch != "n" && ch != "N"); return computers; }
public void ComponentsList_ComputerWithEmptyComponentsList_ShouldThrowArgumentNullException() { var componentsList = new List<Component>(); var pc = new Computer("HP", componentsList); }
// methods public static decimal CalculateComputerPrice(Computer computer) { var components = computer.Components; return components.Sum(component => component.Price); }
private decimal Calculate(Computer computer) { var components = computer.Components; decimal price = components.Sum(component => component.Price); return price; }