Exemple #1
0
        public void Should_return_their_count_when_given_exist_devices()
        {
            var devices = new List <Device>
            {
                new Device {
                    Id = 1
                },
                new Device {
                    Id = 2
                },
                new Device {
                    Id = 3
                },
            };

            //Arrange
            var mockDevices = devices.AsQueryable().BuildMockDbSet();

            _deviceRepository.Setup(x => x.Table).Returns(mockDevices.Object);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            //Act
            var devicesCount = _deviceApiService.GetDevicesCount();

            //Assert
            devicesCount.ShouldEqual(3);
        }
        public void SetUp()
        {
            _tenantMappingService = new Mock <ITenantMappingService>();
            _deviceRepository     = new Mock <IRepository <Device> >();

            _devices = new List <Device>();

            for (int i = 0; i < 1000; i++)
            {
                _devices.Add(new Device()
                {
                    Id = i + 1
                });
            }

            _devices = _devices.OrderBy(x => x.Id).ToList();

            var mockDevice = _devices.AsQueryable().BuildMockDbSet();

            _deviceRepository.Setup(x => x.Table).Returns(mockDevice.Object);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            AutoMapperApiConfiguration.MapperConfigurationExpression.CreateMap <Device, DeviceDto>();
        }
Exemple #3
0
        public void Should_return_null_when_negative_or_zero_device_id_passed(int negativeOrZeroDeviceId)
        {
            //Arrange
            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            //Act
            var result = _deviceApiService.GetDeviceById(negativeOrZeroDeviceId);

            //Assert
            result.ShouldBeNull();
        }
        public void Should_return_empty_collection_when_no_given_devices_exist()
        {
            //Arrange
            _deviceRepository.Setup(x => x.Table).Returns(new List <Device>().AsQueryable);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            //Act
            var result = _deviceApiService.GetDevices();

            //Assert
            result.Count.ShouldEqual(0);
        }
Exemple #5
0
        public void Should_return_zero_when_given_no_devices_exist()
        {
            //Arrange
            _deviceRepository.Setup(x => x.Table).Returns(new List <Device>().AsQueryable());

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            //Act
            var devicesCount = _deviceApiService.GetDevicesCount();

            //Assert
            devicesCount.ShouldEqual(0);
        }
Exemple #6
0
 public QueueController(TransactionApiService transService,
                        TransactionApiRepo transactionRepo,
                        DeviceApiService devService,
                        DeviceApiRepo devRepo,
                        CounterApiRepo counterRepo,
                        IHubContext <QueueHub, IQueHub> hubContext)
 {
     _transService    = transService;
     _transactionRepo = transactionRepo;
     _devService      = devService;
     _devRepo         = devRepo;
     _counterRepo     = counterRepo;
     _hubContext      = hubContext;
 }
Exemple #7
0
        public void Should_return_null_when_null_is_returned_by_repository()
        {
            int deviceId = 3;

            //Arrange
            _deviceRepository.Setup(x => x.Table).Returns(new List <Device>().AsQueryable());
            _deviceRepository.Setup(x => x.GetById(deviceId)).Returns(new Device());

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            //Act
            var result = _deviceApiService.GetDeviceById(deviceId);

            //Assert
            result.ShouldBeNull();
        }
        public void SetUp()
        {
            _baseDate = new DateTime(2018, 6, 6);

            _tenantMappingService = new Mock <ITenantMappingService>();
            _deviceRepository     = new Mock <IRepository <Device> >();

            var device1 = new Device()
            {
                Id           = 6,
                SerialNo     = "SE1",
                ModelNo      = "MD1",
                Longitude    = 1.333,
                Latitude     = 12.1331,
                StoreId      = 2,
                Status       = "1",
                CreatedOnUtc = _baseDate.AddDays(10),
            };

            var device2 = new Device()
            {
                Id           = 2,
                SerialNo     = "SE2",
                ModelNo      = "MD2",
                Longitude    = 18.8912,
                Latitude     = 111.3123,
                StoreId      = 2,
                Status       = "1",
                CreatedOnUtc = _baseDate.AddMonths(1),
            };

            _devices = new List <Device> {
                device1, device2
            };

            var mockDevice = _devices.AsQueryable().BuildMockDbSet();

            _deviceRepository.Setup(x => x.Table).Returns(mockDevice.Object);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            AutoMapperApiConfiguration.MapperConfigurationExpression.CreateMap <Device, DeviceDto>();
        }
        public void SetUp()
        {
            _baseDate = new DateTime(2016, 2, 23);

            _tenantMappingService = new Mock <ITenantMappingService>();
            _deviceRepository     = new Mock <IRepository <Device> >();

            _devices = new List <Device>
            {
                new Device()
                {
                    Id = 2, CreatedOnUtc = _baseDate.AddMonths(2)
                },
                new Device()
                {
                    Id = 3, CreatedOnUtc = _baseDate.AddMonths(10)
                },
                new Device()
                {
                    Id = 1, CreatedOnUtc = _baseDate.AddMonths(7)
                },
                new Device()
                {
                    Id = 4, CreatedOnUtc = _baseDate
                },
                new Device()
                {
                    Id = 5, CreatedOnUtc = _baseDate.AddMonths(3)
                },
            };

            var mockDevices = _devices.AsQueryable().BuildMockDbSet();

            _deviceRepository.Setup(x => x.Table).Returns(mockDevices.Object);

            _tenantMappingService.Setup(x => x.Authorize(It.IsAny <Device>())).Returns(true);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);
        }
Exemple #10
0
        public void SetUp()
        {
            _baseDate = new DateTime(2016, 2, 23);

            _tenantMappingService = new Mock <ITenantMappingService>();
            _deviceRepository     = new Mock <IRepository <Device> >();

            _devices = new List <Device>
            {
                new Device()
                {
                    Id = 2, CreatedOnUtc = _baseDate.AddMonths(2)
                },
                new Device()
                {
                    Id = 3, CreatedOnUtc = _baseDate.AddMonths(10)
                },
                new Device()
                {
                    Id = 1, CreatedOnUtc = _baseDate.AddMonths(7)
                },
                new Device()
                {
                    Id = 4, CreatedOnUtc = _baseDate
                },
                new Device()
                {
                    Id = 5, CreatedOnUtc = _baseDate.AddMonths(3)
                },
            };

            var mockDevice = _devices.AsQueryable().BuildMockDbSet();

            _deviceRepository.Setup(x => x.Table).Returns(mockDevice.Object);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            AutoMapperApiConfiguration.MapperConfigurationExpression.CreateMap <Device, DeviceDto>();
        }
Exemple #11
0
        public void SetUp()
        {
            _tenantMappingService = new Mock <ITenantMappingService>();
            _deviceRepository     = new Mock <IRepository <Device> >();

            _devices = new List <Device>
            {
                new Device()
                {
                    Id = 2
                },
                new Device()
                {
                    Id = 3
                },
                new Device()
                {
                    Id = 1
                },
                new Device()
                {
                    Id = 4
                },
                new Device()
                {
                    Id = 5
                },
            };

            var mockDevice = _devices.AsQueryable().BuildMockDbSet();

            _deviceRepository.Setup(x => x.Table).Returns(mockDevice.Object);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            AutoMapperApiConfiguration.MapperConfigurationExpression.CreateMap <Device, DeviceDto>();
        }
Exemple #12
0
        public void Should_return_same_device_when_device_is_returned_by_repository()
        {
            int    deviceId = 3;
            Device device   = new Device()
            {
                Id = 3, ModelNo = "some model"
            };

            //Arrange
            var list = new List <Device>();

            list.Add(device);

            _deviceRepository.Setup(x => x.Table).Returns(list.AsQueryable());
            _deviceRepository.Setup(x => x.GetById(deviceId)).Returns(device);

            _deviceApiService = new DeviceApiService(_tenantMappingService.Object, _deviceRepository.Object);

            //Act
            var result = _deviceApiService.GetDeviceById(deviceId);

            //Assert
            result.ShouldBeTheSameAs(device);
        }