public void Adding_existing_computer_to_existing_order_increases_OrderLine_quantity()
        {
            ComputersController computersController = new ComputersController();
            ComputerInfoDto     computerInfoDto     = computersController.FindComputerByName("MacBook Pro 15");
            Decimal             expectedPrice       = computerInfoDto.Price;
            NewOrderDto         newOrderDto         = new NewOrderDto
            {
                OrderLines = new List <NewOrderLineDto> {
                    new NewOrderLineDto {
                        ComputerId = computerInfoDto.Id, Quantity = 1
                    }
                },
            };
            NewOrderIdDto newOrderIdDto = ordersController.CreateNewOrder(newOrderDto);

            Assert.IsNotNull(newOrderIdDto);

            ComputerInfoDto secondComputerInfoDto = computersController.GetComputerInfo(computerInfoDto.Id);

            expectedPrice += secondComputerInfoDto.Price;
            ordersController.AddComputerToOrder(newOrderIdDto.Id, new AddComputersToOrderDto
            {
                OrderLines = new List <AddOrderLineDto> {
                    new AddOrderLineDto {
                        ComputerId = secondComputerInfoDto.Id, Quantity = 1
                    }
                },
            });
            OrderInformationDto orderInformationDto = ordersController.GetOrderInformation(newOrderIdDto.Id);

            Assert.AreEqual(1, orderInformationDto.OrderLinesInfo.Count);
            Assert.AreEqual(computerInfoDto.Id, orderInformationDto.OrderLinesInfo[0].ComputerId);
            Assert.AreEqual(expectedPrice, orderInformationDto.Price);
        }
Esempio n. 2
0
        public void Update_computer_name()
        {
            ComputersController computersController = new ComputersController();

            _managementController.AddComputer(new AddComputerDto
            {
                Name          = "TestComputer",
                Description   = "New computer",
                Price         = 1500,
                ImageFilename = "test.png"
            });

            ComputerInfoDto   computerInfoDto   = computersController.FindComputerByName("TestComputer");
            UpdateComputerDto updateComputerDto = new UpdateComputerDto
            {
                Name          = "Amstrad CPC",
                Description   = "New Amstrad with 128Kb",
                Price         = 1000,
                ImageFilename = "amstrad.png"
            };

            _managementController.UpdateComputer(computerInfoDto.Id, updateComputerDto);

            ComputerInfoDto updatedComputer = computersController.GetComputerInfo(computerInfoDto.Id);

            Assert.AreEqual(computerInfoDto.Id, updatedComputer.Id);
            Assert.AreEqual(updateComputerDto.Name, updatedComputer.Name);
            Assert.AreEqual(updateComputerDto.Description, updatedComputer.Description);
            Assert.AreEqual(updateComputerDto.Price, updatedComputer.Price);
            Assert.AreEqual(updateComputerDto.ImageFilename, updatedComputer.ImageFilename);
        }
        public void Raise_an_error_when_searching_a_non_existing_computer()
        {
            ComputersController computersController = new ComputersController();
            string computerName = "Unknown";

            Exception exception = Assert.Throws <Exception>(() => computersController.FindComputerByName(computerName));

            Assert.AreEqual("Computer not found, name: Unknown", exception.Message);

            exception = Assert.Throws <Exception>(() => computersController.GetComputerInfo("unknownid"));
            Assert.AreEqual("Computer not found, Id: unknownid", exception.Message);
        }
Esempio n. 4
0
        public void Delete_computer()
        {
            ComputersController computersController = new ComputersController();

            _managementController.AddComputer(new AddComputerDto
            {
                Name          = "TestComputer",
                Description   = "New computer",
                Price         = 1500,
                ImageFilename = "test.png"
            });
            ComputerInfoDto computerInfoDto = computersController.FindComputerByName("TestComputer");

            _managementController.DeleteComputer(computerInfoDto.Id);

            Exception exception = Assert.Throws <Exception>(() => computersController.GetComputerInfo("TestComputer"));

            Assert.AreEqual("Computer not found, Id: TestComputer", exception.Message);
        }