public string AddProduct(string type, double price)
        {
            Product product;

            switch (type)
            {
            case "Gpu":
                product = new Gpu(price);
                break;

            case "HardDrive":
                product = new HardDrive(price);
                break;

            case "Ram":
                product = new Ram(price);
                break;

            case "SolidStateDrive":
                product = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException("Invalid product type!");
            }

            if (!products.ContainsKey(type))
            {
                products.Add(type, new Stack <Product>());
            }

            products[type].Push(product);

            return($"Added {type} to pool");
        }
Ejemplo n.º 2
0
        public Product CreateProduct(string type, double price)
        {
            Product product = null;

            switch (type)
            {
            case "Gpu":
                product = new Gpu(price);
                break;

            case "HardDrive":
                product = new HardDrive(price);
                break;

            case "Ram":
                product = new Ram(price);
                break;

            case "SolidStateDrive":
                product = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException("Invalid product type!");
            }

            return(product);
        }
Ejemplo n.º 3
0
        public string AddProduct(string type, double price)
        {
            //var product = productFactory.CreateProduct(type, price);
            //products.Add(product);
            //return $"Added {type} to pool";
            Product product;

            switch (type)
            {
            case "Gpu":
                product = new Gpu(price);
                break;

            case "HardDrive":
                product = new HardDrive(price);
                break;

            case "Ram":
                product = new Ram(price);
                break;

            case "SolidStateDrive":
                product = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException($"Invalid product type!");
            }

            products.Add(product);
            return($"Added {type} to pool");
        }
Ejemplo n.º 4
0
        public string AddProduct(string type, double price)
        {
            Product currentProduct;

            switch (type)
            {
            case "Gpu":
                currentProduct = new Gpu(price);
                break;

            case "HardDrive":
                currentProduct = new HardDrive(price);
                break;

            case "Ram":
                currentProduct = new Ram(price);
                break;

            case "SolidStateDrive":
                currentProduct = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException(ErrorMessage.InvalidProductType);
            }

            productsPool.Add(currentProduct);

            return($"Added {type} to pool");
        }
Ejemplo n.º 5
0
 public void Consts_AllSpecificProducts_ShouldThrowExceptionWithNegativePrice()
 {
     Assert.Throws <InvalidOperationException>(() => { var gpu = new Gpu(-1); });
     Assert.Throws <InvalidOperationException>(() => { var ram = new Ram(-1); });
     Assert.Throws <InvalidOperationException>(() => { var hd = new SolidStateDrive(-1); });
     Assert.Throws <InvalidOperationException>(() => { var ssd = new HardDrive(-1); });
 }
        public static Product CreateProduct(string type, double price)
        {
            Product product = null;

            if (type == "Gpu")
            {
                product = new Gpu(price);
            }
            else if (type == "HardDrive")
            {
                product = new HardDrive(price);
            }
            else if (type == "Ram")
            {
                product = new Ram(price);
            }
            else if (type == "SolidStateDrive")
            {
                product = new SolidStateDrive(price);
            }
            else
            {
                throw new InvalidOperationException("Invalid product type!");
            }

            return(product);
        }
Ejemplo n.º 7
0
        public static Product CreateProduct(string type, double price)
        {
            Product product = null;

            switch (type)
            {
            case "Gpu":
                product = new Gpu(price);
                break;

            case "HardDrive":
                product = new HardDrive(price);
                break;

            case "Ram":
                product = new Ram(price);
                break;

            case "SolidStateDrive":
                product = new SolidStateDrive(price);
                break;
            }


            return(product);
        }
        public Product CreateProduct(string type, double price)
        {
            Product product;

            switch (type)
            {
            case nameof(Gpu):
                product = new Gpu(price);
                break;

            case nameof(HardDrive):
                product = new HardDrive(price);
                break;

            case nameof(Ram):
                product = new Ram(price);
                break;

            case nameof(SolidStateDrive):
                product = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException("Invalid product type!");
            }

            return(product);
        }
Ejemplo n.º 9
0
        private IComponent CreateComponent(string componentType, int id, string manufacturer,
                                           string model, decimal price, double overallPerformance,
                                           int generation)
        {
            IComponent component = null;

            if (componentType == "CentralProcessingUnit")
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "Motherboard")
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "PowerSupply")
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "RandomAccessMemory")
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "SolidStateDrive")
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == "VideoCard")
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }

            return(component);
        }
Ejemplo n.º 10
0
        public Product CreateProduct(string type, double price)
        {
            type = type.ToLower();
            Product product = null;

            switch (type)
            {
            case "gpu":
                product = new Gpu(price);
                break;

            case "harddrive":
                product = new HardDrive(price);
                break;

            case "ram":
                product = new Ram(price);
                break;

            case "solidstatedrive":
                product = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException("Invalid storage type!");
            }

            return(product);
        }
Ejemplo n.º 11
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            CheckIfComputerExist(computerId);

            if (this.components.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }

            IComponent component = null;

            switch (componentType)
            {
            case "CentralProcessingUnit": component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation); break;

            case "Motherboard": component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation); break;

            case "PowerSupply": component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation); break;

            case "RandomAccessMemory": component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation); break;

            case "SolidStateDrive": component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation); break;

            case "VideoCard": component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation); break;

            default: throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }
            IComputer computer = this.computers.FirstOrDefault(x => x.Id == computerId);

            computer.AddComponent(component);
            this.components.Add(component);

            return(string.Format(SuccessMessages.AddedComponent, component.GetType().Name, component.Id, computerId));
        }
Ejemplo n.º 12
0
        public Product CreateProduct(string type, double price)
        {
            Product newProduct = null;

            switch (type)
            {
            case "Gpu":
                newProduct = new Gpu(price);
                break;

            case "HardDrive":
                newProduct = new HardDrive(price);
                break;

            case "Ram":
                newProduct = new Ram(price);
                break;

            case "SolidStateDrive":
                newProduct = new SolidStateDrive(price);
                break;

            default:
                throw new InvalidOperationException(ExceptionMessages.InvalidProductType);
            }

            return(newProduct);
        }
        public void TestSolidStateDriveConstructorSetsTheCorrectValues()
        {
            var solidStateDrive = new SolidStateDrive(60);

            Assert.AreEqual(solidStateDrive.Price, 60, "Does not set the price correctly");
            Assert.AreEqual(solidStateDrive.Weight, 0.2, "Does not set the weight correctly");
        }
Ejemplo n.º 14
0
        private List <Product> productPool; //the product list in the pool of a storage


        public string AddProduct(string type, double price)
        {
            Product newProduct; //creating new Product

            if (type == "Ram")
            {
                newProduct       = new Ram();
                newProduct.Price = price;
                productPool.Add(newProduct);
                return($"Added {type} to pool");
            }
            else if (type == "Gpu")
            {
                newProduct       = new Gpu();
                newProduct.Price = price;
                productPool.Add(newProduct);
                return($"Added {type} to pool");
            }
            else if (type == "HardDrive")
            {
                newProduct       = new HardDrive();
                newProduct.Price = price;
                productPool.Add(newProduct);
                return($"Added {type} to pool");
            }
            else if (type == "SolidstateDrive")
            {
                newProduct       = new SolidStateDrive();
                newProduct.Price = price;
                productPool.Add(newProduct);
                return($"Added {type} to pool");
            }
            throw new NotImplementedException("Invalid product type!");
        }
Ejemplo n.º 15
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            var computer = this.computers.FirstOrDefault(x => x.Id == computerId);

            if (computer == null)
            {
                throw new ArgumentException(ExceptionMessages.NotExistingComputerId);
            }

            IComponent component = null;

            if (this.components.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }

            if (componentType == "CentralProcessingUnit")
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "Motherboard")
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "PowerSupply")
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "RandomAccessMemory")
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "SolidStateDrive")
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else if (componentType == "VideoCard")
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
                computer.AddComponent(component);
                this.components.Add(component);
            }
            else
            {
                throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }

            return(string.Format(SuccessMessages.AddedComponent, componentType, component.Id, computer.Id));
        }
Ejemplo n.º 16
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            if (!IsComputerExist(computerId))
            {
                throw new ArgumentException("Computer with this id does not exist.");
            }

            if (components.Any(x => x.Id == id))
            {
                throw new ArgumentException("Component with this id already exists.");
            }

            IComponent component = null;

            if (componentType == "CentralProcessingUnit")
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }

            else if (componentType == "Motherboard")
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }

            else if (componentType == "PowerSupply")
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }

            else if (componentType == "RandomAccessMemory")
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }

            else if (componentType == "SolidStateDrive")
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }

            else if (componentType == "VideoCard")
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }

            else
            {
                throw new ArgumentException("Component type is invalid.");
            }

            var computer = computers.FirstOrDefault(c => c.Id == computerId);

            computer.AddComponent(component);
            components.Add(component);

            return($"Component {component.GetType().Name} with id {component.Id} added successfully in computer with id {computer.Id}.");
        }
Ejemplo n.º 17
0
        public void UnloadVehicleMethodWorksCorrectly()
        {
            SolidStateDrive solidStateDrive = new SolidStateDrive(3);

            this.storage.GetVehicle(1).LoadProduct(solidStateDrive);
            this.storage.GetVehicle(1).LoadProduct(solidStateDrive);

            int expectedCount = 2;

            Assert.AreEqual(expectedCount, this.storage.UnloadVehicle(1));
        }
Ejemplo n.º 18
0
        private IComponent CreateComponent(int id, string componentType,
                                           string manufacturer, string model,
                                           decimal price, double overallPerformance,
                                           int generation)
        {
            Type type = GetDefaultType(componentType);

            if (type == null)
            {
                throw new ArgumentException
                          (ExceptionMessages.InvalidComponentType);
            }

            IComponent component = null;

            if (componentType
                == ComponentType.CentralProcessingUnit.ToString())
            {
                component = new CentralProcessingUnit(id, manufacturer,
                                                      model, price, overallPerformance, generation);
            }
            if (componentType
                == ComponentType.Motherboard.ToString())
            {
                component = new Motherboard(id, manufacturer,
                                            model, price, overallPerformance, generation);
            }
            if (componentType
                == ComponentType.PowerSupply.ToString())
            {
                component = new PowerSupply(id, manufacturer,
                                            model, price, overallPerformance, generation);
            }
            if (componentType
                == ComponentType.RandomAccessMemory.ToString())
            {
                component = new RandomAccessMemory(id, manufacturer,
                                                   model, price, overallPerformance, generation);
            }
            if (componentType
                == ComponentType.SolidStateDrive.ToString())
            {
                component = new SolidStateDrive(id, manufacturer,
                                                model, price, overallPerformance, generation);
            }
            if (componentType
                == ComponentType.VideoCard.ToString())
            {
                component = new VideoCard(id, manufacturer,
                                          model, price, overallPerformance, generation);
            }

            return(component);
        }
Ejemplo n.º 19
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            var computer = this.computers.FirstOrDefault(x => x.Id == computerId);

            if (computer == null)
            {
                throw new ArgumentException("Computer with this id does not exist.");
            }

            Models.Products.Components.IComponent component = null;

            switch (componentType)
            {
            case nameof(CentralProcessingUnit):
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case nameof(Motherboard):
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case nameof(PowerSupply):
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case nameof(RandomAccessMemory):
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case nameof(SolidStateDrive):
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case nameof(VideoCard):
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
                break;
            }

            if (component == null)
            {
                throw new ArgumentException("Component type is invalid.");
            }

            if (this.components.Any(x => x.Id == component.Id))
            {
                throw new ArgumentException("Component with this id already exists.");
            }

            computer.AddComponent(component);
            this.components.Add(component);

            return($"Component {component.GetType().Name} with id {component.Id} added successfully in computer with id {computer.Id}.");
        }
Ejemplo n.º 20
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            var type = new ComponentType();

            var computer = computers.FirstOrDefault(c => c.Id == computerId);

            if (computer == null)
            {
                throw new ArgumentException(ExceptionMessages.NotExistingComputerId);
            }

            if (components.Select(c => c.Id).Contains(id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }

            IComponent component = null;

            if (!Enum.TryParse(componentType, out type))
            {
                throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }
            else if (type == ComponentType.CentralProcessingUnit)
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (type == ComponentType.Motherboard)
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (type == ComponentType.PowerSupply)
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (type == ComponentType.RandomAccessMemory)
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (type == ComponentType.SolidStateDrive)
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (type == ComponentType.VideoCard)
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }

            components.Add(component);
            computer.AddComponent(component);

            return(string.Format(SuccessMessages.AddedComponent, componentType, id, computerId));
        }
Ejemplo n.º 21
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price,
                                   double overallPerformance, int generation)
        {
            IComputer computer = this.computers.FirstOrDefault(c => c.Id == computerId);

            if (computer == null)
            {
                throw new ArgumentException("Computer with this id does not exist.");
            }


            IComponent component = this.components.FirstOrDefault(c => c.Id == id);

            if (component != null)
            {
                throw new ArgumentException("Component with this id already exists.");
            }

            if (componentType == Common.Enums.ComponentType.CentralProcessingUnit.ToString())
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == Common.Enums.ComponentType.Motherboard.ToString())
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == Common.Enums.ComponentType.PowerSupply.ToString())
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == Common.Enums.ComponentType.RandomAccessMemory.ToString())
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == Common.Enums.ComponentType.SolidStateDrive.ToString())
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == Common.Enums.ComponentType.VideoCard.ToString())
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else
            {
                throw new ArgumentException("Component type is invalid.");
            }

            this.components.Add(component);
            computer.AddComponent(component);

            return($"Component {componentType} with id {id} added successfully in computer with id {computerId}.");
        }
Ejemplo n.º 22
0
        //This method is exceptionally done with reflection because of reasons!
        //https://stackoverflow.com/questions/14349512/unit-test-fails-on-run-all-but-not-on-run-selected-tests-with-all-selected
        public void UnloadVehicleMethodWorksCorrectly()
        {
            SolidStateDrive solidStateDrive = new SolidStateDrive(3);
            Vehicle         van             = new Van();
            var             method          = typeof(Storage).GetMethod("AddVehicle", BindingFlags.Instance | BindingFlags.NonPublic);
            int             garageSlot      = (int)method.Invoke(storage, new object[] { van });

            this.storage.GetVehicle(1).LoadProduct(solidStateDrive);

            int expectedCount = 1;

            Assert.AreEqual(expectedCount, this.storage.UnloadVehicle(1));
        }
Ejemplo n.º 23
0
        public void SolidStateDriveTest()
        {
            //-- Arrange
            SolidStateDrive ssd1 = new SolidStateDrive(30);

            string expected = "SSD cost is 30$ and weighs 0,2 Kg.";

            //-- Act
            string actual = ssd1.description;

            //-- Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 24
0
        public string AddComponent(int computerId, int id, string componentType, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            IComputer currComp = computers.FirstOrDefault(c => c.Id == computerId);

            if (!computers.Contains(currComp))
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.NotExistingComputerId));
            }

            var currComponent = components.FirstOrDefault(c => c.Id == id);

            if (currComponent != null)
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.ExistingComponentId));
            }

            IComponent component = null;

            if (componentType == nameof(CentralProcessingUnit))
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(Motherboard))
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(PowerSupply))
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(RandomAccessMemory))
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(SolidStateDrive))
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (componentType == nameof(VideoCard))
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else
            {
                throw new ArgumentException(string.Format(Common.Constants.ExceptionMessages.InvalidComponentType));
            }

            currComp.AddComponent(component);
            components.Add(component);
            return(string.Format(Common.Constants.SuccessMessages.AddedComponent, componentType, id, computerId));
        }
Ejemplo n.º 25
0
        public string AddComponent(int computerId, int id, string componentTypeName, string manufacturer, string model, decimal price, double overallPerformance, int generation)
        {
            var currentComputer = this.computers.FirstOrDefault(x => x.Id == computerId);

            NonExistingComputeId(currentComputer);

            if (!Enum.TryParse(componentTypeName, out ComponentType componentType))
            {
                throw new ArgumentException(ExceptionMessages.InvalidComponentType);
            }
            if (this.components.Any(x => x.Id == id))
            {
                throw new ArgumentException(ExceptionMessages.ExistingComponentId);
            }

            IComponent component = null;

            switch (componentType)
            {
            case ComponentType.CentralProcessingUnit:
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.Motherboard:
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.PowerSupply:
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.RandomAccessMemory:
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.SolidStateDrive:
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
                break;

            case ComponentType.VideoCard:
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
                break;
            }


            currentComputer.AddComponent(component);
            components.Add(component);

            return(string.Format(SuccessMessages.AddedComponent, componentTypeName, id, computerId));
        }
        private async Task <PC> BuildPC(PCBindingModel model)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var             pcCase          = context.Cases.FirstOrDefault(c => $"{c.Manufacturer} {c.ModelName}" == model.Case);
            var             processor       = context.Processors.FirstOrDefault(p => $"{p.Manufacturer} {p.ModelName}" == model.Processor);
            var             graphicsCard    = context.GraphicsCards.FirstOrDefault(gc => $"{gc.Manufacturer} {gc.ModelName}" == model.GraphicsCard);
            var             motherboard     = context.Motherboards.FirstOrDefault(m => $"{m.Manufacturer} {m.ModelName}" == model.Motherboard);
            var             memory          = context.Memory.FirstOrDefault(m => $"{m.Manufacturer} {m.ModelName} {m.Amount} GB" == model.Memory);
            var             powerSupply     = context.PowerSupplies.FirstOrDefault(ps => $"{ps.Manufacturer} {ps.ModelName}" == model.PowerSupply);
            HardDiskDrive   hardDiskDrive   = context.HardDiskDrives.FirstOrDefault(hdd => $"{hdd.Manufacturer} {hdd.ModelName} {hdd.MemoryCapacity} GB" == model.HardDiskDrive);
            SolidStateDrive solidStateDrive = context.SolidStateDrives.FirstOrDefault(ssd => $"{ssd.Manufacturer} {ssd.ModelName} {ssd.MemoryCapacity} GB" == model.SolidStateDrive);

            var pc = new PC()
            {
                BuildName            = model.BuildName,
                Case                 = pcCase,
                GraphicsCard         = graphicsCard,
                Processor            = processor,
                Memory               = memory,
                Motherboard          = motherboard,
                PowerSupply          = powerSupply,
                User                 = user,
                NumberOfMemorySticks = model.NumberOfMemorySticks,
                TotalPrice           = pcCase.Price + graphicsCard.Price + processor.Price + (memory.Price * model.NumberOfMemorySticks) + motherboard.Price + powerSupply.Price
            };

            if (hardDiskDrive != null)
            {
                pc.HardDiskDrive = hardDiskDrive;
                pc.TotalPrice   += hardDiskDrive.Price;
                if (solidStateDrive != null)
                {
                    pc.SolidStateDrive = solidStateDrive;
                    pc.TotalPrice     += solidStateDrive.Price;
                }
                else
                {
                    pc.MaxSystemRating -= 1;
                }
            }
            else
            {
                pc.SolidStateDrive  = solidStateDrive;
                pc.TotalPrice      += solidStateDrive.Price;
                pc.MaxSystemRating -= 1;
            }

            return(pc);
        }
Ejemplo n.º 27
0
        public string AddComponent(int computerId, int id, string componentType,
                                   string manufacturer, string model, decimal price,
                                   double overallPerformance, int generation)
        {
            ComponentType cType     = new ComponentType();
            IComponent    component = null;

            if (DoesComputerExist(computerId))
            {
                throw new ArgumentException(COMPUTER_DOESNT_EXIST);
            }
            else if (computers.Where(x => x.Id == computerId).Any(x => x.Components.Any(x => x.Id == id)))
            {
                throw new ArgumentException("Component with this id already exists.");
            }
            else if (!Enum.TryParse <ComponentType>(componentType, out cType))
            {
                throw new ArgumentException("Component type is invalid.");
            }
            else if (cType == ComponentType.CentralProcessingUnit)
            {
                component = new CentralProcessingUnit(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.Motherboard)
            {
                component = new Motherboard(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.PowerSupply)
            {
                component = new PowerSupply(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.RandomAccessMemory)
            {
                component = new RandomAccessMemory(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.SolidStateDrive)
            {
                component = new SolidStateDrive(id, manufacturer, model, price, overallPerformance, generation);
            }
            else if (cType == ComponentType.VideoCard)
            {
                component = new VideoCard(id, manufacturer, model, price, overallPerformance, generation);
            }

            components.Add(component);
            IComputer computer = computers.Where(x => x.Id == computerId).FirstOrDefault();

            computer.AddComponent(component);
            return($"Component {component.GetType().Name} with id {component.Id} added successfully in computer with id {computer.Id}.");
        }
Ejemplo n.º 28
0
        public void Consts_AllSpecificProducts_ShouldSetConstsAndPropertyValuesCorrectlyUponInitialisation()
        {
            var gpu = new Gpu(5);
            var hd  = new HardDrive(10);
            var ram = new Ram(50);
            var ssd = new SolidStateDrive(100);

            Assert.AreEqual(0.7, gpu.Weight, "GPU weight mismatch!");
            Assert.AreEqual(1, hd.Weight, "Hard Drive weight mismatch!");
            Assert.AreEqual(0.1, ram.Weight, "RAM weight mismatch!");
            Assert.AreEqual(0.2, ssd.Weight, "Solid State Drive weight mismatch!");

            Assert.AreEqual(5, gpu.Price, "GPU price mismatch!");
            Assert.AreEqual(10, hd.Price, "Hard Drive price mismatch!");
            Assert.AreEqual(50, ram.Price, "RAM price mismatch!");
            Assert.AreEqual(100, ssd.Price, "Solid State Drive price mismatch!");
        }
Ejemplo n.º 29
0
        public void SolidStateDrivesController_WithValidId_ShouldReturnDetailsOfEntityByGivenId()
        {
            var dbSsd = new SolidStateDrive()
            {
                Interface      = "Sata 3",
                Manufacturer   = "SSDs",
                MemoryCapacity = 256,
                ModelName      = "PowerfulSSD",
                Price          = 300,
                ReadSpeed      = 1000,
                WriteSpeed     = 1000
            };

            dbContext.SolidStateDrives.Add(dbSsd);
            dbContext.SaveChanges();

            var dbSsdModel = Mapper.Map <SolidStateDriveViewModel>(dbContext.SolidStateDrives.First());

            var result = this.controller.Details(1);

            var resultView = result as ViewResult;

            var ssdModel = (SolidStateDriveViewModel)resultView.Model;

            //Property ModelName is unique and there is no need to check every property explicitly.
            Assert.AreEqual(dbSsdModel.ModelName, ssdModel.ModelName);
            Assert.AreEqual(dbSsdModel.Interface, ssdModel.Interface);
            Assert.AreEqual(dbSsdModel.Manufacturer, ssdModel.Manufacturer);
            Assert.AreEqual(dbSsdModel.MemoryCapacity, ssdModel.MemoryCapacity);
            Assert.AreEqual(dbSsdModel.Price, ssdModel.Price);
            Assert.AreEqual(dbSsdModel.ReadSpeed, ssdModel.ReadSpeed);
            Assert.AreEqual(dbSsdModel.WriteSpeed, ssdModel.WriteSpeed);

            //var modelMotherboards = Mapper.Map<IEnumerable<MotherboardViewModel>>(motherboards);

            //var result = this.controller.Index();

            //var resultView = result as ViewResult;

            //Assert.IsInstanceOfType(resultView.Model, typeof(IEnumerable<MotherboardViewModel>));

            //CollectionAssert.AreEqual(modelMotherboards as List<MotherboardViewModel>, resultView.Model as List<MotherboardViewModel>);
        }
        private static async Task SeedSsds(ApplicationDbContext dbContext)
        {
            using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
            {
                connection.Open();
                var           command = new SqlCommand(SqlCommands.SelectSolidStateDrivesSql, connection);
                var           ssds    = new List <SolidStateDrive>();
                SqlDataReader reader  = await command.ExecuteReaderAsync();

                try
                {
                    while (reader.Read())
                    {
                        var ssd = new SolidStateDrive
                        {
                            Brand            = reader["Brand"].ToString(),
                            Capacity         = reader["Capacity"].ToString(),
                            Image            = (byte[])reader["Image"],
                            ImgUrl           = reader["ImgUrl"].ToString(),
                            DeviceType       = reader["DeviceType"].ToString(),
                            FormFactor       = reader["FormFactor"].ToString(),
                            Name             = reader["Name"].ToString(),
                            Interface        = reader["Interface"].ToString(),
                            MemoryComponents = reader["MemoryComponents"].ToString(),
                            UsedFor          = reader["UsedFor"].ToString(),
                            CategoryId       = 8,
                        };
                        ssds.Add(ssd);
                    }

                    dbContext.SolidStateDrives.AddRange(ssds);
                    await dbContext.SaveChangesAsync();
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    reader.Close();
                }
            }
        }