Exemple #1
0
        public async Task ThrowHttpException_WhenUserIsntLoggedIn()
        {
            // Arrange
            // arrange controller
            Mock <ApplicationDbContext> mockApplicationDbContext = new Mock <ApplicationDbContext>();
            Mock <SensorDbService>      mockSensorDbService      = new Mock <SensorDbService>(mockApplicationDbContext.Object);
            Mock <HttpClient>           mockHttpClient           = new Mock <HttpClient>();
            Mock <SensorApiService>     mockSensorApiService     = new Mock <SensorApiService>(mockHttpClient.Object);

            string loggedUser = "******";

            int testSensorId = 7;

            SensorDisplayData testModel = new SensorDisplayData
            {
                SensorId = testSensorId,
                UserName = "******"
            };

            mockSensorDbService.Setup(x => x.GetSpecificSensorDisplayDataAsync(testSensorId))
            .Returns(Task.Run(() => testModel));

            SensorControllerMock sensorController = new SensorControllerMock(loggedUser, mockSensorDbService.Object, mockSensorApiService.Object);

            // act and assert
            await Assert.ThrowsExceptionAsync <HttpException>(() => sensorController.ModifySelectedSensor(testSensorId));
        }
Exemple #2
0
        public void ThrowHttpException_WhenUserIsntLoggedIn()
        {
            // Arrange
            // arrange controller
            Mock <ApplicationDbContext> mockApplicationDbContext = new Mock <ApplicationDbContext>();
            Mock <SensorDbService>      mockSensorDbService      = new Mock <SensorDbService>(mockApplicationDbContext.Object);
            Mock <HttpClient>           mockHttpClient           = new Mock <HttpClient>();
            Mock <SensorApiService>     mockSensorApiService     = new Mock <SensorApiService>(mockHttpClient.Object);

            string loggedUser = "******";

            SensorControllerMock sensorController = new SensorControllerMock(loggedUser, mockSensorDbService.Object, mockSensorApiService.Object);

            // act and assert
            Assert.ThrowsException <HttpException>(() => sensorController.ModifySelectedSensor(new SensorDisplayData
            {
                UserName = "******"
            }));
        }
Exemple #3
0
        public void CallsModifySpecificSesnorInSensorDbService_WhenUserIsLoggedIn()
        {
            // Arrange
            // arrange controller
            Mock <ApplicationDbContext> mockApplicationDbContext = new Mock <ApplicationDbContext>();
            Mock <SensorDbService>      mockSensorDbService      = new Mock <SensorDbService>(mockApplicationDbContext.Object);
            Mock <HttpClient>           mockHttpClient           = new Mock <HttpClient>();
            Mock <SensorApiService>     mockSensorApiService     = new Mock <SensorApiService>(mockHttpClient.Object);

            string loggedUser = "******";

            SensorDisplayData testSensor = new SensorDisplayData
            {
                UserName = loggedUser
            };

            SensorControllerMock sensorController = new SensorControllerMock(loggedUser, mockSensorDbService.Object, mockSensorApiService.Object);

            //act
            sensorController.ModifySelectedSensor(testSensor);

            // act and assert
            mockSensorDbService.Verify(x => x.ModifySpecificSesnor(testSensor), Times.Once);
        }