Ejemplo n.º 1
0
        public void AddToDatabaseSensor_WhenSensorIsNotNull()
        {
            //Arrange
            var dbContextMock    = new Mock <ApplicationDbContext>();
            var httpClientMock   = new Mock <IHttpClientProvider>();
            var emailServiceMock = new Mock <IEmailService>();

            List <Sensor> sensors = new List <Sensor>();
            Sensor        sensor  = new Sensor()
            {
                Id              = 5,
                Name            = "termometur",
                URL             = "theGreatUrl",
                PollingInterval = 20,
                IsPublic        = true,
                OwnerId         = "stringId"
            };

            var sensorSetMock = new Mock <DbSet <Sensor> >().SetupData(sensors);

            dbContextMock.SetupGet(m => m.Sensors).Returns(sensorSetMock.Object);

            var sensorServices = new Dataflow.DataServices.SensorService(dbContextMock.Object, httpClientMock.Object, emailServiceMock.Object);

            //Act
            sensorServices.AddSensor(sensor);

            //Assert
            Assert.AreSame(sensor, sensors[0]);
        }
Ejemplo n.º 2
0
        public void ThrowArgumentNullException_WhenParameterIsNull()
        {
            //Arrange
            var dbContextMock    = new Mock <ApplicationDbContext>();
            var httpClientMock   = new Mock <IHttpClientProvider>();
            var emailServiceMock = new Mock <IEmailService>();

            var sensorServices = new Dataflow.DataServices.SensorService(dbContextMock.Object, httpClientMock.Object, emailServiceMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentNullException>(() => sensorServices.AddSensor(null));
        }