Ejemplo n.º 1
0
        public void Return_Successfully_AllApiSensors(int id, string description, string icbSensorId, double maxVal, double minVal, string tag, string url, double value, int pollingInterval)
        {
            //Arrange
            contextOptions = new DbContextOptionsBuilder <smartDormitoryDbContext>()
                             .UseInMemoryDatabase(databaseName: "Return_Successfully_AllApiSensors")
                             .Options;

            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                assertContext.MeasureTypes.Add(new MeasureType
                {
                    Id   = 1,
                    Type = "C"
                });

                assertContext.SaveChanges();

                assertContext.Sensors.Add(new Sensor
                {
                    Id              = id,
                    Description     = description,
                    IcbSensorId     = icbSensorId,
                    MaxValue        = maxVal,
                    MinValue        = minVal,
                    Tag             = tag,
                    Url             = url,
                    Value           = value,
                    TimeStamp       = DateTime.Now,
                    PollingInterval = pollingInterval,
                    ModifiedOn      = DateTime.Now,
                    MeasureTypeId   = 1
                });

                assertContext.SaveChanges();
            }

            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                var mesureTypesServiceMock   = new Mock <IMeasureTypesService>();
                var ICBApiSensorsServiceMock = new ICBApiSensorsService(assertContext, mesureTypesServiceMock.Object);

                //Act
                var allSensors = ICBApiSensorsServiceMock.ListAllApiSensors().ToList();

                //Assert

                Assert.IsTrue(allSensors[0].Id == id);
                Assert.IsTrue(allSensors[0].Description == description);
                Assert.IsTrue(allSensors[0].Tag == tag);
                Assert.IsTrue(allSensors[0].MinValue == minVal);
                Assert.IsTrue(allSensors[0].MaxValue == maxVal);
                Assert.IsTrue(allSensors[0].Value == value);
                Assert.IsTrue(allSensors[0].PollingInterval == pollingInterval);
                Assert.IsTrue(allSensors[0].Url == url);
                Assert.IsTrue(allSensors[0].IcbSensorId == icbSensorId);
                Assert.IsTrue(allSensors[0].MeasureTypeId == 1);
            }
        }
        public void ThrowArgumentException_WhenSensorExists()
        {
            //Arrange
            contextOptions = new DbContextOptionsBuilder <smartDormitoryDbContext>()
                             .UseInMemoryDatabase(databaseName: "ThrowArgumentNullException_WhenSensorExists")
                             .Options;

            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                assertContext.MeasureTypes.Add(new MeasureType()
                {
                    Type = "Type"
                });
                assertContext.SaveChanges();
            }

            //Act && Assert
            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                var measureTypeServiceMock = new MeasureTypesService(assertContext);

                Assert.ThrowsException <ArgumentException>(() => measureTypeServiceMock.AddMeasureType("Type"));
            }
        }
        public void ReturnCountOfAllNotDeletedUserSensorsBySearchName(string searchName)
        {
            // Arrange
            contextOptions = new DbContextOptionsBuilder <smartDormitoryDbContext>()
                             .UseInMemoryDatabase(databaseName: "ReturnCountOfAllNotDeletedUserSensorsBySearchName")
                             .Options;

            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                var userId      = Guid.NewGuid().ToString();
                var userSensor1 = new UserSensors
                {
                    UserId          = userId,
                    SensorId        = 1,
                    Name            = "Some name",
                    Description     = "Some description",
                    MinValue        = 11,
                    MaxValue        = 18,
                    PollingInterval = 13,
                    Latitude        = 1.15,
                    Longitude       = 5.15,
                    IsPublic        = true,
                    Alarm           = false,
                    IsDeleted       = false,
                    ImageUrl        = "Some Url",
                };

                var userSensor2 = new UserSensors
                {
                    UserId          = userId,
                    SensorId        = 1,
                    Name            = "Some name1",
                    Description     = "Some description1",
                    MinValue        = 12,
                    MaxValue        = 19,
                    PollingInterval = 23,
                    Latitude        = 2.15,
                    Longitude       = 6.15,
                    IsPublic        = true,
                    Alarm           = false,
                    IsDeleted       = true,
                    ImageUrl        = "Some Url 1",
                };
                var userSensor3 = new UserSensors
                {
                    UserId          = userId + "123",
                    SensorId        = 1,
                    Name            = "Some name2",
                    Description     = "Some description2",
                    MinValue        = 13,
                    MaxValue        = 20,
                    PollingInterval = 33,
                    Latitude        = 3.15,
                    Longitude       = 7.15,
                    IsPublic        = false,
                    Alarm           = false,
                    IsDeleted       = false,
                    ImageUrl        = "Some Url 2",
                };

                assertContext.UserSensors.AddRange(userSensor1, userSensor2, userSensor3);

                assertContext.Users.AddRange(new User
                {
                    Id          = userId,
                    UserName    = "******",
                    UserSensors = new List <UserSensors>()
                    {
                        userSensor1, userSensor2
                    }
                },
                                             new User
                {
                    Id          = userId + "123",
                    UserName    = "******",
                    UserSensors = new List <UserSensors>()
                    {
                        userSensor3
                    }
                });

                assertContext.SaveChanges();
            }

            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                var userSensorServiceMock = new UserSensorService(assertContext);

                // Act
                var totalSensorsCountMock = userSensorServiceMock.TotalByName(searchName);

                // Assert
                Assert.IsTrue(totalSensorsCountMock == 1);
            }
        }
Ejemplo n.º 4
0
        public void Return_SensorTotalCount(int id, string description, string icbSensorId, double maxVal, double minVal, string tag, string url, double value, int pollingInterval)
        {
            //Arrange
            contextOptions = new DbContextOptionsBuilder <smartDormitoryDbContext>()
                             .UseInMemoryDatabase(databaseName: "Return_SensorTotalCount")
                             .Options;
            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                assertContext.MeasureTypes.Add(new MeasureType
                {
                    Id   = 1,
                    Type = "C"
                });

                assertContext.Sensors.AddRange(new Sensor
                {
                    Id              = id,
                    Description     = description,
                    IcbSensorId     = icbSensorId,
                    MaxValue        = maxVal,
                    MinValue        = minVal,
                    Tag             = tag,
                    Url             = url,
                    Value           = value,
                    TimeStamp       = DateTime.Now,
                    PollingInterval = pollingInterval,
                    ModifiedOn      = DateTime.Now,
                    MeasureTypeId   = 1
                },
                                               new Sensor
                {
                    Id              = 2,
                    Description     = description,
                    IcbSensorId     = icbSensorId,
                    MaxValue        = maxVal,
                    MinValue        = minVal,
                    Tag             = tag,
                    Url             = url,
                    Value           = value,
                    TimeStamp       = DateTime.Now,
                    PollingInterval = pollingInterval,
                    ModifiedOn      = DateTime.Now,
                    MeasureTypeId   = 1
                },

                                               new Sensor
                {
                    Id              = 3,
                    Description     = description,
                    IcbSensorId     = icbSensorId,
                    MaxValue        = maxVal,
                    MinValue        = minVal,
                    Tag             = "AnotherTag",
                    Url             = url,
                    Value           = value,
                    TimeStamp       = DateTime.Now,
                    PollingInterval = pollingInterval,
                    ModifiedOn      = DateTime.Now,
                    MeasureTypeId   = 1
                });

                assertContext.SaveChanges();
            }

            using (var assertContext = new smartDormitoryDbContext(contextOptions))
            {
                var mesureTypesServiceMock   = new Mock <IMeasureTypesService>();
                var ICBApiSensorsServiceMock = new ICBApiSensorsService(assertContext, mesureTypesServiceMock.Object);

                //Act
                var count = ICBApiSensorsServiceMock.Total();

                //Assert
                Assert.IsTrue(count == 3);
            }
        }