public void ThrowArgumenException_WhenParameterAreInvalid(int page, int pageSize) { //Arrange var contextMock = new Mock <smartDormitoryDbContext>(); var mesureTypesServiceMock = new Mock <IMeasureTypesService>(); var ICBApiSensorsServiceMock = new ICBApiSensorsService(contextMock.Object, mesureTypesServiceMock.Object); //Act && Assert Assert.ThrowsException <ArgumentException>(() => ICBApiSensorsServiceMock.ListAllSensors(page, pageSize)); }
public void Return_Successfully_AllSensors(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_AllSensors") .Options; using (var assertContext = new smartDormitoryDbContext(contextOptions)) { assertContext.MeasureTypes.Add(new MeasureType { Id = 1, Type = "C" }); assertContext.SaveChanges(); 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 }); assertContext.SaveChanges(); } using (var assertContext = new smartDormitoryDbContext(contextOptions)) { var mesureTypesServiceMock = new Mock <IMeasureTypesService>(); var ICBApiSensorsServiceMock = new ICBApiSensorsService(assertContext, mesureTypesServiceMock.Object); //Act var allSensors = ICBApiSensorsServiceMock.ListAllSensors(1, 2).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); Assert.IsTrue(allSensors.Count == 2); } }