예제 #1
0
        public async void Task2_GetById_Return_NotFoundResult()
        {
            //Arrange
            var Id = 32;

            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);

            //Act
            var result = await _controller.GetCodeCategory(Id);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
예제 #2
0
        public async void Task4_Put_Update_Category_NoContentResult()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);
            int newId = 21;

            //Act
            var category = new CodeCategory()
            {
                CategoryId   = newId,
                CategoryName = "Update Bedding"
            };
            var updatedData = await _controller.PutCodeCategory(newId, category);

            //Assert
            Assert.IsType <NoContentResult>(updatedData);
        }
예제 #3
0
        private async void Task5_Delete_Category_OkResult()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);
            var category = new CodeCategory()
            {
                CategoryName = "New and Del Pickle",
            };

            //Act
            var resultCreate = await _controller.PostCodeCategory(category);

            var okResult  = resultCreate.Should().BeOfType <CreatedAtActionResult>().Subject;
            var resClient = okResult.Value.Should().BeAssignableTo <CodeCategory>().Subject;
            int delId     = resClient.CategoryId;
            var result    = await _controller.DeleteCodeCategory(delId);

            //Assert
            Assert.IsType <OkObjectResult>(result);
        }
예제 #4
0
        public async void Task3_Post_NewCategory_FindName()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);
            var category = new CodeCategory()
            {
                CategoryName = "NewPickle",
            };

            //Act
            var result = await _controller.PostCodeCategory(category);

            //Assert
            var okResult  = result.Should().BeOfType <CreatedAtActionResult>().Subject;
            var resClient = okResult.Value.Should().BeAssignableTo <CodeCategory>().Subject;

            resClient.CategoryName.Should().Be("NewPickle");

            //delete JayNew
            int newId        = _context.CodeCategory.FirstOrDefault(p => p.CategoryName == "NewPickle").CategoryId;
            var resultDelete = await _controller.DeleteCodeCategory(newId);
        }