Exemplo n.º 1
0
        public void Get_GetComputer_ValidateReturn(Computer computer)
        {
            //Given
            using (var context = new HardwareContext(_options))
            {
                context.Computers.Add(computer);
                context.SaveChanges();
            }

            //When
            using (var context = new HardwareContext(_options))
            {
                Assert.Equal(1, context.Computers.Count());
            }

            ActionResult <Computer> result;

            //Then
            using (var context = new HardwareContext(_options))
            {
                var computersController = new ComputersController(context);
                result = computersController.Get(computer.Id);
            }

            var okResult = Assert.IsType <OkObjectResult>(result.Result);
            var value    = Assert.IsType <Computer>(okResult.Value);

            Assert.Equal(computer, value, new ModelEqualityComparer <Computer>());
        }
Exemplo n.º 2
0
        public void Get_ShouldReturnWelcomeMessage()
        {
            // Arrange.
            var controller = new ComputersController();

            controller.Request = HttpRequestHandler.GenerateHttpRequestMessage();
            var expected = "Welcome to Wind API! - ComputersController";

            // Act.
            var result = controller.Get();

            // Assert.
            Assert.IsNotNull(result);
            var getResult = result.Content.ReadAsAsync <string>().Result;

            Assert.AreEqual(expected, getResult);
        }