public void MemoryController_WithValidId_ShouldDeleteMemoryFromDb()
        {
            int id       = 1;
            var dbMemory = new Memory()
            {
                Amount       = 8,
                Frequency    = 2444,
                Manufacturer = "Memories",
                ModelName    = "Magma reaper",
                ModulesType  = "SIMM",
                Price        = 175,
                Socket       = "PGHT",
                Type         = "DDR4"
            };

            dbContext.Memory.Add(dbMemory);
            dbContext.SaveChanges();

            controller.DeleteConfirmed(id);

            var memory = dbContext.Memory.FirstOrDefault();

            var countOfEntities = dbContext.Memory.ToList().Count;

            Assert.IsNull(memory);
            Assert.AreEqual(0, countOfEntities);
        }
        public void PowerSuppliesController_ShouldReturnViewResultWithPowerSupplyBindingModel()
        {
            var dbPowerSupply = new PowerSupply()
            {
                Connector            = "36 pin",
                Effectiveness        = 99,
                Manufacturer         = "ConnectorsInc",
                ModelName            = "con",
                NumberOfCoolingVents = 2,
                Pfc   = "pcf",
                Power = 1000,
                Price = 1500
            };

            dbContext.PowerSupplies.Add(dbPowerSupply);
            dbContext.SaveChanges();

            var id = dbContext.PowerSupplies.First().Id;

            var result = this.controller.Edit(id);

            Assert.IsInstanceOfType(result, typeof(ViewResult));

            var resultViewModel = (result as ViewResult).Model;

            Assert.IsInstanceOfType(resultViewModel, typeof(PowerSupplyBindingModel));
        }
Example #3
0
        public void PowerSupplieController_WithValidModel_ShouldEditPowerSupplyAndAddToDb()
        {
            var dbPowerSupply = new PowerSupply()
            {
                Connector            = "24 pin",
                Effectiveness        = 90,
                Manufacturer         = "Connectors",
                ModelName            = "Cnt5S",
                NumberOfCoolingVents = 8,
                Pfc   = "PFC",
                Power = 800,
                Price = 300
            };

            dbContext.PowerSupplies.Add(dbPowerSupply);
            dbContext.SaveChanges();

            var powerSupplyModel = new PowerSupplyBindingModel()
            {
                Connector            = "12 pin",
                Effectiveness        = 80,
                Manufacturer         = "ConnectorsInc",
                ModelName            = "Cnt5SP+",
                NumberOfCoolingVents = 4,
                Pfc   = "PFCMAX",
                Power = 600,
                Price = 500
            };

            var powerSupply = dbContext.PowerSupplies.First();

            controller.Edit(powerSupply.Id, powerSupplyModel);

            var dbEditedPowerSupply = dbContext.PowerSupplies.First();

            Assert.IsNotNull(dbEditedPowerSupply);
            Assert.AreEqual(dbEditedPowerSupply.Connector, powerSupplyModel.Connector);
            Assert.AreEqual(dbEditedPowerSupply.Effectiveness, powerSupplyModel.Effectiveness);
            Assert.AreEqual(dbEditedPowerSupply.Manufacturer, powerSupplyModel.Manufacturer);
            Assert.AreEqual(dbEditedPowerSupply.ModelName, powerSupplyModel.ModelName);
            Assert.AreEqual(dbEditedPowerSupply.NumberOfCoolingVents, powerSupplyModel.NumberOfCoolingVents);
            Assert.AreEqual(dbEditedPowerSupply.Pfc, powerSupplyModel.Pfc);
            Assert.AreEqual(dbEditedPowerSupply.Power, powerSupplyModel.Power);
            Assert.AreEqual(dbEditedPowerSupply.Price, powerSupplyModel.Price);
        }
        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>);
        }
Example #5
0
        public void MotherboardsController_WithValidEntities_ShouldReturnAllMotherboardsFromDb()
        {
            var motherboard1 = new Motherboard()
            {
                Chipset    = "SHJ",
                FormFactor = "ATX",
                GraphicsCardSocketNumber = "GCS",
                HDDInterface             = "SATA 3",
                Manufacturer             = "MotherboardsInc",
                MaxMemory           = 32,
                MemorySocketNumber  = "JFD",
                MemoryType          = "DDR3",
                ModelName           = "BIGBOSS",
                NumberOfMemorySlots = 6,
                PowerConnector      = "24 pin",
                Price = 250,
                ProcessorSocketNumber = "SDF",
                SSDInterface          = "USB"
            };

            var motherboard2 = new Motherboard()
            {
                Chipset    = "KSJF",
                FormFactor = "ATX mini",
                GraphicsCardSocketNumber = "GCS",
                HDDInterface             = "SATA 3",
                Manufacturer             = "MotherboardsInc",
                MaxMemory           = 64,
                MemorySocketNumber  = "JFD",
                MemoryType          = "DDR3",
                ModelName           = "SMALLBOSS",
                NumberOfMemorySlots = 6,
                PowerConnector      = "24 pin",
                Price = 250,
                ProcessorSocketNumber = "SDF",
                SSDInterface          = "PCIe"
            };

            dbContext.Motherboards.Add(motherboard1);
            dbContext.Motherboards.Add(motherboard2);
            dbContext.SaveChanges();

            var motherboards = dbContext.Motherboards as IEnumerable <Motherboard>;

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

            var propertiesOfModel = modelMotherboards.First().GetType().GetProperties();

            var result = this.controller.Index();

            var  resultView = result as ViewResult;
            bool asd        = Equals(modelMotherboards.First(), (resultView.Model as List <MotherboardViewModel>).First());

            var modelCollection = (List <MotherboardViewModel>)resultView.Model;

            //var propertiesOfOutput = modelCollection.

            //Property ModelName is unique and there is no need to check every property explicitly.
            Assert.AreEqual(modelMotherboards.First().ModelName, modelCollection.First().ModelName);
            Assert.AreEqual(modelMotherboards.First().MemoryType, modelCollection.First().MemoryType);
            Assert.AreEqual(modelMotherboards.First().MemorySocketNumber, modelCollection.First().MemorySocketNumber);
            Assert.AreEqual(modelMotherboards.First().Chipset, modelCollection.First().Chipset);
            Assert.AreEqual(modelMotherboards.First().FormFactor, modelCollection.First().FormFactor);
            Assert.AreEqual(modelMotherboards.First().GraphicsCardSocketNumber, modelCollection.First().GraphicsCardSocketNumber);
            Assert.AreEqual(modelMotherboards.First().MaxMemory, modelCollection.First().MaxMemory);
            Assert.AreEqual(modelMotherboards.First().SSDInterface, modelCollection.First().SSDInterface);
            Assert.AreEqual(modelMotherboards.First().HDDInterface, modelCollection.First().HDDInterface);
            Assert.AreEqual(modelMotherboards.First().NumberOfMemorySlots, modelCollection.First().NumberOfMemorySlots);
            Assert.AreEqual(modelMotherboards.First().PowerConnector, modelCollection.First().PowerConnector);
            Assert.AreEqual(modelMotherboards.First().Price, modelCollection.First().Price);
            Assert.AreEqual(modelMotherboards.First().ProcessorSocketNumber, modelCollection.First().ProcessorSocketNumber);
            Assert.AreEqual(modelMotherboards.First().Manufacturer, modelCollection.First().Manufacturer);

            Assert.AreEqual(modelMotherboards.Skip(1).First().ModelName, modelCollection.Skip(1).First().ModelName);
            Assert.AreEqual(modelMotherboards.Skip(1).First().MemoryType, modelCollection.Skip(1).First().MemoryType);
            Assert.AreEqual(modelMotherboards.Skip(1).First().MemorySocketNumber, modelCollection.Skip(1).First().MemorySocketNumber);
            Assert.AreEqual(modelMotherboards.Skip(1).First().Chipset, modelCollection.Skip(1).First().Chipset);
            Assert.AreEqual(modelMotherboards.Skip(1).First().FormFactor, modelCollection.Skip(1).First().FormFactor);
            Assert.AreEqual(modelMotherboards.Skip(1).First().GraphicsCardSocketNumber, modelCollection.Skip(1).First().GraphicsCardSocketNumber);
            Assert.AreEqual(modelMotherboards.Skip(1).First().MaxMemory, modelCollection.Skip(1).First().MaxMemory);
            Assert.AreEqual(modelMotherboards.Skip(1).First().SSDInterface, modelCollection.Skip(1).First().SSDInterface);
            Assert.AreEqual(modelMotherboards.Skip(1).First().HDDInterface, modelCollection.Skip(1).First().HDDInterface);
            Assert.AreEqual(modelMotherboards.Skip(1).First().NumberOfMemorySlots, modelCollection.Skip(1).First().NumberOfMemorySlots);
            Assert.AreEqual(modelMotherboards.Skip(1).First().PowerConnector, modelCollection.Skip(1).First().PowerConnector);
            Assert.AreEqual(modelMotherboards.Skip(1).First().Price, modelCollection.Skip(1).First().Price);
            Assert.AreEqual(modelMotherboards.Skip(1).First().ProcessorSocketNumber, modelCollection.Skip(1).First().ProcessorSocketNumber);
            Assert.AreEqual(modelMotherboards.Skip(1).First().Manufacturer, modelCollection.Skip(1).First().Manufacturer);
        }