ITemperatureDataService GetTemperatureDataService() { var mockContext = new Mock <IUnitOfWork>(); var expectedTemperatureData = new TemperatureData() { TemperatureDataID = 1, Temperature = 12, Huminity = 45, WindPower = 5 }; var mockDbSet = new Mock <ITemperatureData>(); mockDbSet.Setup(z => z.Find( It.IsAny <Func <TemperatureData, bool> >(), It.IsAny <int>(), It.IsAny <int>())) .Returns( new List <TemperatureData>() { expectedTemperatureData } ); mockContext .Setup(context => context.TemperatureDatas) .Returns(mockDbSet.Object); ITemperatureDataService TemperatureDataService = new TemperatureDataService(mockContext.Object); return(TemperatureDataService); }
public void GetTemperatureDatas_UserIsAdmin_ThrowMethodAccessException() { // Arrange User user = new Admin(1, "test", 1); SecurityContext.SetUser(user); var mockUnitOfWork = new Mock <IUnitOfWork>(); ITemperatureDataService TemperatureDataService = new TemperatureDataService(mockUnitOfWork.Object); // Act // Assert Assert.Throws <MethodAccessException>(() => TemperatureDataService.GetTemperatureDatas(0)); }
public TemperatureEntriesController(TemperatureDataService dataService) { _dataService = dataService; }