Beispiel #1
0
        public async void GetDeviceByMail_ActionExecutes_ReturnResultWithDeviceDto(int id)
        {
            _mockService.Setup(x => x.GetByIdAsync(id)).ReturnsAsync(Response <DeviceDto> .Success(customers.Find(x => x.Id == id), 200));
            var result = await _controller.GetById(id);

            Assert.IsType <ObjectResult>(result);
        }
Beispiel #2
0
        public void GetById_NoneExistingIdPassedReturn404()
        {
            var _controller = new DeviceController();

            var result = _controller.GetById(4);

            Assert.IsInstanceOfType(result, typeof(NotFoundResult), "Pas de 404");
        }
Beispiel #3
0
        public void GetById_ExistingIdPassedReturnOkObject()
        {
            var _controller = new DeviceController();

            var result = _controller.GetById(1);

            Assert.IsInstanceOfType(result, typeof(OkObjectResult), "Pas du bon type");
        }
Beispiel #4
0
        public void GetById_ExistingPassed_ReturnsRightItem()
        {
            // Arrange
            var _controller = new DeviceController();
            // Act
            var result = _controller.GetById(1) as OkObjectResult;

            // Assert
            Assert.IsInstanceOfType(result.Value, typeof(Device), "Pas une Devise");
            Assert.AreEqual(new Device(1, "Dollar", 1.08), (Device)result.Value, "Devises pas identiques");
        }
        public async Task GetById_WithDeviceId_ReturnsDevice()
        {
            // Arrange
            var testDevice = new Device()
            {
                Id   = 10,
                Name = "DeviceName"
            };
            var dbContext = Setup.GetDbContext();

            dbContext.Devices.Add(testDevice);
            dbContext.SaveChanges();
            var controller = new DeviceController(dbContext);

            // Act
            var result = await controller.GetById(testDevice.Id);

            // Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(result);
            var device         = Assert.IsAssignableFrom <DeviceViewModel>(okObjectResult.Value);

            Assert.Equal(testDevice.Id, device.Id);
            Assert.Equal(testDevice.Name, device.Name);
        }