Exemple #1
0
        public async void Delete_Device_Deletes_Element()
        {
            builder.UseInMemoryDatabase("Delete_Device_Deletes_Element");
            var options = builder.Options;
            var device  = new Domain.Device();

            using (var context = new TestDbContext(options))
            {
                device = new Domain.Device()
                {
                    Id          = 1,
                    Vendor      = "V1",
                    Status      = true,
                    UId         = 1,
                    DateCreated = DateTime.Today
                };
                context.Devices.Add(device);
                context.SaveChanges();
                var repository = new DeviceRepository(context);
                await repository.Delete(device);

                device = context.Devices.Find(1);
            }

            Assert.True(device == null);
        }
Exemple #2
0
        private void ConfigureData()
        {
            device = new Domain.Device()
            {
                Id          = 1,
                Vendor      = "V1",
                Status      = true,
                DateCreated = DateTime.Today,
                UId         = 1,
                GatewayId   = 1
            };
            deviceDto = new DeviceDto()
            {
                Id          = 1,
                Vendor      = "V1",
                Status      = true,
                DateCreated = DateTime.Today,
                UId         = 1,
                GatewayId   = 1
            };

            mapper = new MapperConfiguration(c => c.AddProfile <AutoMapping>()).CreateMapper();
            deviceRepositoryMock.Get(device.Id).Returns(Task <Domain.Device> .FromResult(device));
            deviceRepositoryMock.Insert(device).Returns(Task <Domain.Device> .FromResult(device));
            deviceRepositoryMock.GetDeviceCount(1).Returns(5);
            deviceRepositoryMock.GetDeviceCount(2).Returns(11);
            deviceRepositoryMock.Delete(device).Returns(Task <Domain.Device> .FromResult(device));
            service = new DeviceService(deviceRepositoryMock, mapper);
        }
Exemple #3
0
        public async void Insert_Null_Device_Throws_Error()
        {
            builder.UseInMemoryDatabase("Insert_Null_Device_Throws_Error");
            var options = builder.Options;

            Domain.Device device = new Domain.Device();
            using (var context = new TestDbContext(options))
            {
                var repository = new DeviceRepository(context);
                await Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.Insert(null));
            }
        }
Exemple #4
0
 /// <summary>
 /// The transform method of the IDeviceMapper
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public DeviceDTO Transform(Domain.Device entity)
 {
     return(new DeviceDTO
     {
         Id = entity.Id,
         Name = entity.Name,
         Mode = entity.Mode.ToString(),
         Status = entity.Status.ToString(),
         ToAlert = entity.ToAlert.ToString(CultureInfo.InvariantCulture),
         ToNotification = entity.ToNotification.ToString(CultureInfo.InvariantCulture),
         Timer = 0,
         Remainingpercent = 0,
         ForeColorOfBar = Color.DarkGray,
         BackColorOfBar = Color.DarkGray
     });
 }
Exemple #5
0
        public async void Delete_Non_Existing_Device_In_Empty_DB_Throws_Error()
        {
            builder.UseInMemoryDatabase("Delete_Non_Existing_Device_In_Empty_DB_Throws_Error");
            var options = builder.Options;

            Domain.Device device = new Domain.Device();
            using (var context = new TestDbContext(options))
            {
                var repository = new DeviceRepository(context);
                device = new Domain.Device()
                {
                    Id          = 1,
                    Vendor      = "V1",
                    Status      = true,
                    UId         = 1,
                    DateCreated = DateTime.Today
                };
                await Assert.ThrowsAsync <DbUpdateConcurrencyException>(async() => await repository.Delete(device));
            }
        }
Exemple #6
0
        /// <summary>
        /// The transform method of the IUpdateDeviceMapper
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Domain.Device Transform(DeviceDTO entity)
        {
            var device = new Domain.Device
            {
                Id             = entity.Id,
                Name           = entity.Name,
                ToAlert        = Int32.Parse(entity.ToAlert),
                ToNotification = Int32.Parse(entity.ToNotification)
            };

            if (entity.Mode != Mode.Off.ToString())
            {
                device.Status = Status.Disabled;
            }
            else
            {
                device.Status = Status.Enabled;
                device.Mode   = Mode.Off;
            }

            return(device);
        }
Exemple #7
0
        public async void Delete_Null_Device_Throws_Error()
        {
            builder.UseInMemoryDatabase("Delete_Null_Device_Throws_Error");
            var options = builder.Options;

            Domain.Device device = new Domain.Device();
            using (var context = new TestDbContext(options))
            {
                var repository = new DeviceRepository(context);
                device = new Domain.Device()
                {
                    Id          = 1,
                    Vendor      = "V1",
                    Status      = true,
                    UId         = 1,
                    DateCreated = DateTime.Today
                };
                context.Devices.Add(device);
                context.SaveChanges();
                await Assert.ThrowsAsync <ArgumentNullException>(async() => await repository.Delete(null));
            }
        }
Exemple #8
0
        public async void Insert_Device_Inserts_Element()
        {
            builder.UseInMemoryDatabase("Insert_Device_Inserts_Element");
            var options = builder.Options;

            Domain.Device device = new Domain.Device();
            using (var context = new TestDbContext(options))
            {
                var repository = new DeviceRepository(context);
                await repository.Insert(new Domain.Device()
                {
                    Id          = 1,
                    Vendor      = "V1",
                    Status      = true,
                    UId         = 1,
                    DateCreated = DateTime.Today
                });

                device = context.Devices.Find(1);
            }

            Assert.True(device != null && device.Id == 1);
        }
Exemple #9
0
        public async void Get_Device_Returns_Element_If_Exists()
        {
            builder.UseInMemoryDatabase("Get_Device_Returns_Element_If_Exists");
            var options = builder.Options;
            var device  = new Domain.Device()
            {
                Id          = 1,
                Vendor      = "V1",
                Status      = true,
                UId         = 1,
                DateCreated = DateTime.Today
            };

            using (var context = new TestDbContext(options))
            {
                context.Add(device);
                context.SaveChanges();
            }

            Domain.Device existingDevice    = null;
            Domain.Device nonExistingDevice = null;

            using (var context = new TestDbContext(options))
            {
                var repository = new DeviceRepository(context);
                existingDevice = await repository.Get(1);

                nonExistingDevice = await repository.Get(2);
            }

            Assert.True(existingDevice != null && nonExistingDevice == null);
            Assert.True(existingDevice.Id == device.Id &&
                        existingDevice.Vendor == device.Vendor &&
                        existingDevice.UId == device.UId &&
                        existingDevice.Status == device.Status &&
                        existingDevice.DateCreated == device.DateCreated);
        }