示例#1
0
        public async void TestCreate_InvalidOrderDetail_ShouldFail()
        {
            // Arrange
            OrderDetailsController controller = new OrderDetailsController(_context);

            InitializeOrderDetail();
            orderDetail.GameId = 99;

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

                // 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("Microsoft.EntityFrameworkCore.DbUpdateException", ex.GetType().ToString());
            }
        }
示例#2
0
        public void OrderDetails_CreatesView()
        {  // return type is void not async task
            // Arrange
            var dbContext  = _serviceProvider.GetRequiredService <ApplicationDbContext>();
            var controller = new OrderDetailsController(dbContext);

            // Act
            var result = controller.Create(); // controller uses sync methods (not async)

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.ViewName);
            Assert.NotNull(viewResult.ViewData);
        }