public void Delete_existing_order() { ComputersController computersController = new ComputersController(); string macBookId = computersController.FindComputerByName("MacBook Pro 15").Id; string imacId = computersController.FindComputerByName("iMac 27").Id; NewOrderDto newOrderDto = new NewOrderDto { OrderLines = new List <NewOrderLineDto> { new NewOrderLineDto { ComputerId = macBookId, Quantity = 2 }, new NewOrderLineDto { ComputerId = imacId, Quantity = 2 } } }; OrdersController ordersController = new OrdersController("emilybeck", "password1"); NewOrderIdDto orderIdDto = ordersController.CreateNewOrder(newOrderDto); Assert.IsTrue(ordersController.All().Exists(order => order.OrderId.Equals(orderIdDto.Id))); _managementController.DeleteOrder(orderIdDto.Id); List <OrderInformationDto> allOrders = ordersController.All(); Assert.IsFalse(allOrders.Exists(order => order.OrderId.Equals(orderIdDto.Id))); }
public void Add_second_computer_to_existing_order() { 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.FindComputerByName("iMac 27"); expectedPrice += secondComputerInfoDto.Price * 2; ordersController.AddComputerToOrder(newOrderIdDto.Id, new AddComputersToOrderDto { OrderLines = new List <AddOrderLineDto> { new AddOrderLineDto { ComputerId = secondComputerInfoDto.Id, Quantity = 2 } } }); OrderInformationDto orderInformationDto = ordersController.GetOrderInformation(newOrderIdDto.Id); Assert.AreEqual(2, orderInformationDto.OrderLinesInfo.Count); Assert.AreEqual(computerInfoDto.Id, orderInformationDto.OrderLinesInfo[0].ComputerId); Assert.AreEqual(secondComputerInfoDto.Id, orderInformationDto.OrderLinesInfo[1].ComputerId); Assert.AreEqual(expectedPrice, orderInformationDto.Price); }
public void Create_new_order_with_one_computer() { ComputersController computersController = new ComputersController(); ComputerInfoDto computerInfoDto = computersController.FindComputerByName("MacBook Pro 15"); int computerQuantity = 1; Decimal expectedPrice = computerInfoDto.Price; List <OrderInformationDto> orders = ordersController.All(); int previousNumberOfItems = orders.Count; NewOrderDto newOrderDto = new NewOrderDto { OrderLines = new List <NewOrderLineDto> { new NewOrderLineDto { ComputerId = computerInfoDto.Id, Quantity = computerQuantity } } }; NewOrderIdDto newOrderIdDto = ordersController.CreateNewOrder(newOrderDto); Assert.IsNotNull(newOrderIdDto); orders = ordersController.All(); OrderInformationDto order = ordersController.All().First(ord => ord.OrderId == newOrderIdDto.Id); Assert.AreEqual(previousNumberOfItems + 1, orders.Count); List <OrderLineInfoDto> newOrderOrderLinesInfo = order.OrderLinesInfo; Assert.AreEqual(1, newOrderOrderLinesInfo.Count); Assert.AreEqual(computerInfoDto.Id, newOrderOrderLinesInfo.First().ComputerId); Assert.AreEqual(computerQuantity, newOrderOrderLinesInfo.First().Quantity); Assert.AreEqual(expectedPrice, order.Price); }
public void Raise_an_error_when_adding_a_computer_to_existing_order_with_negative_quantity() { ComputersController computersController = new ComputersController(); ComputerInfoDto computerInfoDto = computersController.FindComputerByName("MacBook Pro 15"); NewOrderDto newOrderDto = new NewOrderDto { OrderLines = new List <NewOrderLineDto> { new NewOrderLineDto { ComputerId = computerInfoDto.Id, Quantity = 1 } }, }; NewOrderIdDto newOrderIdDto = ordersController.CreateNewOrder(newOrderDto); Assert.IsNotNull(newOrderIdDto); Exception exception = Assert.Throws <Exception>(() => ordersController.AddComputerToOrder(newOrderIdDto.Id, new AddComputersToOrderDto { OrderLines = new List <AddOrderLineDto> { new AddOrderLineDto { ComputerId = computerInfoDto.Id, Quantity = -1 } }, })); Assert.AreEqual("Computer quantity cannot be negative", exception.Message); }
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 Get_computer_detailed_information_by_guid() { ComputersController computersController = new ComputersController(); string computerName = "MacBook Pro 15"; ComputerInfoDto computer = computersController.FindComputerByName(computerName); Assert.AreEqual(computerName, computer.Name); Assert.AreEqual("Macbook pro 15' Description", computer.Description); Assert.AreEqual(1500, computer.Price); }
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); }
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); }
public void Get_computer_image() { ComputersController computersController = new ComputersController(); string computerName = "iMac 27"; string [] expectedResult = { " ", " * * * **** ****** ", " ** ** *** *** * * * ", " ** * ** * * * * * ", " * * * **** * **** * ", " * * * * * * * * ", " *** * * **** *** ****** * ", " " }; ComputerInfoDto computerInfo = computersController.FindComputerByName(computerName); ComputerImageInfoDto imageInfo = computersController.GetComputerImage(computerInfo.Id); imageInfo.Content.ForEach(Console.WriteLine); Assert.AreEqual(expectedResult, imageInfo.Content); }