示例#1
0
        public void Post_returns_expected_responses()
        {
            var controller = new ExampleController(Helpers.MockExampleBusinessLogic(), Helpers.MockIAppSettings());

            using var scope = new AssertionScope();
            var response = controller.Post(Helpers.TestModel);

            response.Should().BeAssignableTo <CreatedAtActionResult>();

            response = controller.Post(Helpers.NullModel);
            response.Should().BeAssignableTo <BadRequestResult>();

            response = controller.Post(new ExampleModel());
            response.Should().BeAssignableTo <UnprocessableEntityObjectResult>();
        }
        public void Post_NoReturn_NoExeption()
        {
            // Arrange
            var controller = new ExampleController();

            // Act
            controller.Post("");

            // Assert
            // As This example dont have a repository,
            // we are not able to verify if the object was fully updated
        }
示例#3
0
        public void Should_ReturnBadRequest_When_IncorrectModel()
        {
            // Arrange
            var model = new ExampleCommand()
            {
                Type = 0
            };

            // Act
            var controller = new ExampleController();

            var result = controller.Post(model);

            // Assert
            var okObjectResult = result.Should().BeOfType <BadRequestObjectResult>().Subject;

            okObjectResult.StatusCode.Should().Be(400);
        }
示例#4
0
        public void TestMethod2()
        {
            var options = new DbContextOptionsBuilder <MyContext>()
                          .UseInMemoryDatabase("dbNamn")   // Databasinstansen får samma namn.
                          .Options;
            var item = new ExampleModel()
            {
                Name  = "Test",
                Value = "Value"
            };
            var controller = new ExampleController(new MyContext(options));

            IActionResult postResult = controller.Post(item);

            var objectResult = (OkObjectResult)postResult;
            int id           = (int)objectResult.Value;

            IActionResult  getResult     = controller.Get(id);
            OkObjectResult objectResult2 = (OkObjectResult)getResult;
            ExampleModel   model         = (ExampleModel)objectResult2.Value;

            Assert.AreEqual(item.Name, model.Name);
        }