Exemplo n.º 1
0
        public void Create()
        {
            // Arrange
            var order = new Order
            {
                OrderDate           = DateTime.Today,
                CustomerId          = 1,
                DesiredDeliveryDate = DateTime.Today,
                AddressId           = 1,
                OrderProducts       = new List <OrderProduct>
                {
                    new OrderProduct
                    {
                        Id              = 1,
                        OrderedAmount   = 100,
                        DeliveredAmount = 100,
                        OrderId         = 1,
                        ProductId       = 1
                    }
                }
            };

            // Act
            _orderController.Create(order);

            // Assert
            _mockSetOrder.Verify(x => x.Add(order), Times.Once);
            _mockContext.Verify(x => x.SaveChanges(), Times.Once);
        }
Exemplo n.º 2
0
        public void CreateViewLoads()
        {
            // act
            var actual = (ViewResult)controller.Create();

            // assert
            Assert.AreEqual("Create", actual.ViewName);
        }
Exemplo n.º 3
0
            public void CreateTheOrder()
            {
                sut.Create(expectedOrderToAdd);

                dataStoreMock.Verify(x => x.BeginTransaction());
                dataStoreMock.Verify(x => x.Add(It.Is <Order>(
                                                    y => y.Reference == expectedOrderToAdd.Reference &&
                                                    y.Type == OrderTypes.Activate.ToString() &&
                                                    y.Status == "New"
                                                    )));
            }
Exemplo n.º 4
0
            public void ReturnOk()
            {
                var expectedOrder = new OrderToAdd
                {
                    Reference = Guid.NewGuid()
                };

                var actual = sut.Create(expectedOrder);

                actual.Should().BeOfType <OkResult>();
            }
        public void Create_Should_Return412IfORderInvalid()
        {
            var options = new DbContextOptionsBuilder <UserOrderContext>()
                          .UseInMemoryDatabase(databaseName: "order_controller_tests3")
                          .Options;
            var testUser  = new User("test", "mc testy face", 1);
            var testOrder = new OrderDTO()
            {
                TrackingId = "1234",
                Name       = "nnnn",
                Street     = "sssss",
                City       = "cccc",
                State      = "ssss",
                ZipCode    = "zzzzz",
                UserId     = 2
            };

            using (var context = new UserOrderContext(options))
            {
                context.Users.Add(testUser);
                context.SaveChanges();
            }

            using (var context = new UserOrderContext(options))
            {
                var ordersController = new OrdersController(context);
                var ordersResult     = ordersController.Create(testOrder) as ObjectResult;

                Assert.Equal(412, ordersResult.StatusCode);

                context.Database.EnsureDeleted();
            }
        }
        public void Create_Should_ReturnOrderLocation()
        {
            var options = new DbContextOptionsBuilder <UserOrderContext>()
                          .UseInMemoryDatabase(databaseName: "order_controller_tests2")
                          .Options;
            var testUser  = new User("test", "mc testy face", 1);
            var testOrder = new OrderDTO()
            {
                TrackingId = "1234",
                Name       = "nnnn",
                Street     = "sssss",
                City       = "cccc",
                State      = "ssss",
                ZipCode    = "zzzzz",
                UserId     = 1
            };

            using (var context = new UserOrderContext(options))
            {
                context.Users.Add(testUser);
                context.SaveChanges();
            }

            using (var context = new UserOrderContext(options))
            {
                var ordersController = new OrdersController(context);
                var ordersResult     = ordersController.Create(testOrder) as CreatedAtRouteResult;
                var order            = (Order)ordersResult.Value;
                Assert.Equal(201, ordersResult.StatusCode);
                Assert.Equal("GetUserOrders", ordersResult.RouteName);
                Assert.Equal(testOrder.TrackingId, order.TrackingId);

                context.Database.EnsureDeleted();
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var controller = new OrdersController();

            var order = new OrderPostModel()
            {
                Date     = DateTime.UtcNow,
                Products = new List <ProductPostModel>()
                {
                    new ProductPostModel()
                    {
                        Name  = "Brik",
                        Price = 40000
                    },
                    new ProductPostModel()
                    {
                        Name  = "Wood",
                        Price = 40000
                    }
                },
                User = new UserPostModel()
                {
                    FirstName   = "John",
                    LastName    = "cddd",
                    PhoneNumber = "+380912573499"
                }
            };

            var a = controller.Create(order);
        }
Exemplo n.º 8
0
        public async void TestCreate_InvalidOrder_ShouldFail()
        {
            // Arrange
            OrdersController controller = new OrdersController(_context);

            InitializeOrder();
            order.UserId = 99;

            try
            {
                // Act
                var result = await controller.Create(order);

                // Assert
                Assert.IsType <ViewResult>(result);
                ViewResult viewResult = (ViewResult)result;
                Assert.NotNull(viewResult.ViewData.ModelState);
                Assert.NotEmpty(viewResult.ViewData.ModelState.Keys);

                foreach (string item in viewResult.ViewData.ModelState.Keys)
                {
                    Assert.Equal("", item);
                }
            }
            catch (Exception ex)
            {
                Assert.Equal("System.NullReferenceException", ex.GetType().ToString());
            }
        }
        public void Create_Should_return_200_ok()
        {
            var orderRequest = new OrderRequestModel()
            {
                Pizzas = new List <string>()
                {
                    "margarita"
                },
                Drinks = new List <string>()
                {
                    "cocacola"
                },
                ExtraIngredients = new List <string>()
                {
                    "kronärtskocka"
                }
            };

            //Arrange
            var menu           = new Menu();
            var validate       = new Validate(menu);
            var calculatePrice = new CalculateOrderPrice();
            var order          = new Order(calculatePrice, menu, validate);

            var controller = new  OrdersController(order, menu);

            var actual = controller.Create(orderRequest);

            var contentResult = actual.As <OkObjectResult>();

            actual.Should().Be(contentResult);
        }
        public async Task CreateFailedValidation()
        {
            var orderModel       = new OrderModel();
            var validationResult = ValidationResult.New();

            validationResult.AddErrorMessage <OrderModel>("Not Valid");

            var validator = new Mock <IValidator>(MockBehavior.Strict);

            validator
            .Setup(x => x.ValidateAsync(orderModel))
            .ReturnsAsync(validationResult)
            .Verifiable("Validation operation not performed");

            var controller = new OrdersController(
                logger: _logger,
                validator: validator.Object,
                apiLayerTranslator: Mock.Of <IApiLayerTranslator>(MockBehavior.Strict),
                ordersEngine: Mock.Of <IOrdersEngine>(MockBehavior.Strict));


            var result = await controller.Create(orderModel);


            Assert.That(result, Is.TypeOf <BadRequestObjectResult>());
            validator.VerifyAll();
        }
        public void CreateLoadsView()
        {
            OrdersController controller = new OrdersController();
            // act
            ViewResult actual = (ViewResult)controller.Create();

            // assert
            Assert.AreEqual("Create", actual.ViewName);
        }
Exemplo n.º 12
0
        public void Remove_from_Order_should_throw_expected_exception_if_item_does_not_exist()
        {
            var inputNames = new List <string>()
            {
                "Coca cola"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            Assert.ThrowsException <ArgumentNullException>(() => controller.RemoveItemFromOrder(1, "Fanta"));
        }
Exemplo n.º 13
0
        public void Create()
        {
            // Arrange
            OrdersController controller = new OrdersController();

            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 14
0
        public void Add_to_Order_should_throw_expected_exception_if_item_does_not_exist()
        {
            var inputNames = new List <string>()
            {
                "Coca cola"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            Assert.ThrowsException <ArgumentNullException>(() => controller.AddItemToOrder(1, "Rymdpizza"));
        }
Exemplo n.º 15
0
        public void Complete_order_should_throw_expected_exception_if_status_is_wrong()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            Assert.ThrowsException <InvalidOperationException>(() => controller.Complete(1));
        }
        public async Task Create_OrderReturns_ViewResult()
        {
            Order newOrder = new Order();

            mock.Setup(repo => repo.AddAsync(newOrder)).Throws(new Exception());
            controller = new OrdersController(mock.Object);
            controller.ModelState.AddModelError("Name", "Required");

            var result = await controller.Create(newOrder);

            var viewResult = Assert.IsType <ViewResult>(result);
        }
Exemplo n.º 17
0
        public async Task Confirm_order_should_throw_expected_exception_if_status_is_wrong()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController(new Storage(), new StorageApiClientFake());

            controller.Create(inputNames);
            controller.Cancel(1);
            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => controller.Confirm(1));
        }
Exemplo n.º 18
0
        public void CreateOrder()
        {
            var options = new DbContextOptionsBuilder <OrderContext>()
                          .UseInMemoryDatabase(databaseName: "create_order")
                          .Options;

            Customer customer;
            Item     item;
            Order    order;

            using (var context = new OrderContext(options))
            {
                var controller = new CustomersController(context);
                customer = controller.Create(new CreateCustomer {
                    Name = "customer"
                });
                customer.Name.ShouldEqual("customer");
            }


            using (var context = new OrderContext(options))
            {
                var controller = new ItemsController(context);
                item = controller.Create(new CreateItem {
                    Name = "item"
                });
                item.Name.ShouldEqual("item");
            }

            using (var context = new OrderContext(options))
            {
                var controller = new OrdersController(context);
                order = controller.Create(new CreateOrder {
                    CustomerId = customer.Id
                });
                order.Customer.Name.ShouldEqual(customer.Name);
            }

            using (var context = new OrderContext(options))
            {
                var controller = new OrdersController(context);
                order = controller.GetById(order.Id);
                order.Customer.Name.ShouldEqual(customer.Name);
            }

            // using (var context = new OrderContext(options))
            // {
            //     var controller = new OrdersController(context);
            //     order = controller.Update(new CreateOrder { CustomerId = customer.Id });
            //     order.Customer.Name.ShouldEqual(customer.Name);
            // }
        }
Exemplo n.º 19
0
        public void Delete_order_should_delete_order_with_matching_id()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController(new Storage(), new StorageApiClientFake());

            controller.Create(inputNames);
            Assert.AreEqual(1, controller.Get(1).Id);
            controller.DeleteOrder(1);
            Assert.AreEqual(null, controller.Get(1));
        }
Exemplo n.º 20
0
        public void CreateShouldCreateNewOrder()
        {
            // Given
            A.CallTo(() => _createOrderCommand.Run()).Returns(Constants.IphoneCaseOrder);

            // When
            var order = _ordersController.Create();

            // Then
            Assert.Equal(Constants.IphoneCaseOrder, order);

            A.CallTo(() => _createOrderCommand.Run()).MustHaveHappened();
        }
Exemplo n.º 21
0
        public void Remove_Addables_to_pizza_should_throw_expected_exception_if_addable_does_not_exist()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            var inputAddable = "Vacuum";

            Assert.ThrowsException <ArgumentNullException>(() => controller.RemoveAddable(1, 2, inputAddable));
        }
Exemplo n.º 22
0
        public void Get_ongoing_Should_return_all_active_orders()
        {
            var inputData = new List <List <string> >()
            {
                new List <string>()
                {
                    "Margarita", "Fanta", "Margarita"
                },
                new List <string>()
                {
                    "Kebabpizza", "Sprite", "Kebabpizza"
                },
                new List <string>()
                {
                    "Hawaii", "Coca cola", "Kebabpizza"
                },
                new List <string>()
                {
                    "Margarita", "Fanta", "Kebabpizza"
                },
                new List <string>()
                {
                    "Hawaii", "Sprite", "Kebabpizza"
                },
                new List <string>()
                {
                    "Kebabpizza", "Fanta", "Kebabpizza"
                },
                new List <string>()
                {
                    "Hawaii", "Sprite", "Kebabpizza"
                },
                new List <string>()
                {
                    "Margarita", "Fanta", "Kebabpizza"
                }
            };
            var ordersController = new OrdersController();

            foreach (var inputNames in inputData)
            {
                ordersController.Create(inputNames);
            }
            for (int i = 1; i < inputData.Count; i += 2)
            {
                ordersController.Confirm(i);
            }
            var actual = ordersController.GetActive();

            Assert.AreEqual(4, actual.Count());
        }
Exemplo n.º 23
0
        public void Cancel_order_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            controller.Cancel(1);
            var actual = controller.Get(1);

            Assert.AreEqual(Order.OrderStatus.Cancelled, actual.Status);
        }
Exemplo n.º 24
0
        public async Task Return_NoContent_When_Created()
        {
            var expectedResponse = new Response <GetOrdersResponse>(
                new GetOrdersResponse("orderId", "orderStatus"),
                string.Empty);

            _createOrderHandler
            .Setup(c => c.Create(It.IsAny <CreateOrderRequest>()))
            .ReturnsAsync(expectedResponse);

            var response = await _ordersController.Create(new CreateOrderRequest(new List <CreateOrderProductsRequest>()));

            Assert.Multiple(() =>
            {
                var objectResult = (OkObjectResult)response;
                Assert.IsNotNull(objectResult);
                Assert.AreEqual((int)HttpStatusCode.OK, objectResult.StatusCode);

                var content = objectResult.Value as GetOrdersResponse;
                Assert.IsNotNull(content);
                Assert.AreEqual(expectedResponse.Value.OrderId, content.OrderId);
                Assert.AreEqual(expectedResponse.Value.OrderStatus, content.OrderStatus);
            });
        }
Exemplo n.º 25
0
        public void Complete_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController(new Storage(), new StorageApiClientFake());

            controller.Create(inputNames);
            controller.Confirm(1);
            controller.Complete(1);
            var actual = controller.Get(1);

            Assert.AreEqual(Order.OrderStatus.Completed, actual.Status);
        }
Exemplo n.º 26
0
        public void Remove_from_Order_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Fanta"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            controller.RemoveItemFromOrder(1, "Fanta");
            var actual = controller.Get(1);

            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(0, actual.Items.Count);
            Assert.AreEqual(0, actual.TotalPrice);
        }
Exemplo n.º 27
0
        public void Confirm_order_should_return_list_of_ingrediens_and_products_and_price()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            var inputAddable = "Kebab";

            controller.AddAddable(1, 2, inputAddable);
            var actual = controller.Confirm(1);

            Assert.AreEqual(Order.OrderStatus.Confirmed, actual.Status);
        }
        public async Task Create_OrderReturns_RedirectToActionResult()
        {
            controller = new OrdersController(mock.Object);
            Order newOrder = new Order
            {
                CustomerId = 1, SupermarketId = 2, OrderDate = DateTime.Parse("5-6-2020")
            };

            var result = await controller.Create(newOrder);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mock.Verify(r => r.AddAsync(newOrder));
        }
Exemplo n.º 29
0
        public void Add_to_Order_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Fanta"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            controller.AddItemToOrder(1, "Coca cola");
            var actual = controller.Get(1);

            Assert.AreEqual(1, actual.Id);
            Assert.AreEqual(2, actual.Items.Count);
            Assert.AreEqual(40, actual.TotalPrice);
        }
Exemplo n.º 30
0
        public void Add_Addables_to_pizza_should_succeed()
        {
            var inputNames = new List <string>()
            {
                "Hawaii", "Fanta", "Kebabpizza"
            };
            var controller = new OrdersController();

            controller.Create(inputNames);
            var inputAddable = "Kebab";
            var actual       = controller.Get(1);

            Assert.AreEqual(0, (actual.Items[2] as Pizza).Addables.Count);
            controller.AddAddable(1, 2, inputAddable);
            Assert.AreEqual(1, (actual.Items[2] as Pizza).Addables.Count);
            Assert.AreEqual(240, actual.TotalPrice);
        }