Пример #1
0
        public async void GetDevices_ActionExecutes_ReturnResultWithCustomersDto()
        {
            _mockService.Setup(x => x.GetAllAsync()).ReturnsAsync(Response <IEnumerable <DeviceDto> > .Success(customers, 200));
            var result = await _controller.GetAll();

            Assert.IsType <ObjectResult>(result);
        }
        public async Task GetAll_WhenCalled_ReturnsCollectionOfDevices()
        {
            // Arrange
            var testDevices = GetDevices();
            var dbContext   = Setup.GetDbContext();

            dbContext.Devices.AddRange(testDevices);
            dbContext.SaveChanges();
            var controller = new DeviceController(dbContext);

            // Act
            var result = await controller.GetAll();

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

            Assert.All(testDevices, testDevice =>
            {
                var device = devices.SingleOrDefault(d => d.Id == testDevice.Id);
                Assert.NotNull(device);
                Assert.Equal(testDevice.Name, device.Name);
            });
        }