public void Delete_WhenIdIsLargerThanZero_RemoveIsCalled()
        {
            // Act
            controller.Delete(1);

            // Assert against the mock object
            fakeRoomRepository.Verify(x => x.Remove(1), Times.Once);
        }
Exemple #2
0
        public void Delete_WhenRoomIdIsValid_ReturnViewRoom()
        {
            // Act
            var result = controller.Delete(2) as ViewResult;
            var room   = result.Model as Room;
            var roomId = room.Id;

            // Assert Verify
            Assert.InRange <int>(roomId, 1, 2);
        }
Exemple #3
0
        public async void DeleteRoom_ShouldReturnNoContent_WhenSuccessful()
        {
            mockRepo.Setup(r => r.GetRoomById(kitchenId))
            .Returns(kitchen);
            mockRepo.Setup(r => r.SaveAllAsync())
            .Returns(Task.FromResult(true));

            var result = await controller.Delete(kitchenId);

            result.Should().BeOfType <NoContentResult>();
        }
Exemple #4
0
        public void DeleteTest()
        {
            _mockRoomRepo.Setup(x => x.Find(1)).Returns(new Room());
            var result = _roomsController.Delete(1) as ViewResult;

            Assert.AreEqual("Delete", result.ViewName);
        }
Exemple #5
0
        public void DeleteUserPositive()

        {
            var repo = new Mock <RoomsRep>(db);

            RoomsController controller = new RoomsController(repo.Object);

            var data = controller.Delete(01) as OkObjectResult;

            Assert.AreEqual(200, data.StatusCode);
        }
Exemple #6
0
        public void Delete(int?id)
        {
            // Arrange
            RoomsController controller = new RoomsController();

            // Act
            ViewResult result = controller.Delete(id) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public async Task Delete_WhenCalled_DeleteFailed_ReturnsServerError()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var room       = new Room()
            {
                Name = "test_room_1"
            };

            mockedRepo.Setup(repo => repo.GetRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(room);
            mockedRepo.Setup(repo => repo.DeleteRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(false);

            var mockedListenerClient = new Mock <ISensorListenerAPI>();

            mockedListenerClient.Setup(client => client.NotifyHomeyTopic <double>("test", 0));

            var controller = new RoomsController(mockedRepo.Object, mockedListenerClient.Object);
            var result     = await controller.Delete("00000000-0000-0000-0000-000000000001");

            var contentResult = (result as StatusCodeResult).StatusCode;

            Assert.Equal(StatusCodes.Status500InternalServerError, contentResult);
        }
        public async Task Delete_WhenCalled_UnkownObject_ReturnsNotFound()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var room       = new Room()
            {
                Name = "test_room_1"
            };

            mockedRepo.Setup(repo => repo.GetRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync((Room)null);
            mockedRepo.Setup(repo => repo.DeleteRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(false);

            var mockedListenerClient = new Mock <ISensorListenerAPI>();

            mockedListenerClient.Setup(client => client.NotifyHomeyTopic <double>("test", 0));

            var controller = new RoomsController(mockedRepo.Object, mockedListenerClient.Object);
            var result     = await controller.Delete("00000000-0000-0000-0000-000000000001");

            var contentResult = result as NotFoundResult;

            Assert.NotNull(contentResult);
        }
        public async Task Delete_WhenCalled_ReturnsOk()
        {
            var mockedRepo = new Mock <IHomeRepository>();
            var room       = new Room()
            {
                Name = "test_room_1"
            };

            mockedRepo.Setup(repo => repo.GetRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(room);
            mockedRepo.Setup(repo => repo.DeleteRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(true);

            var mockedListenerClient = new Mock <ISensorListenerAPI>();

            mockedListenerClient.Setup(client => client.NotifyHomeyTopic <double>("test", 0));

            var controller = new RoomsController(mockedRepo.Object, mockedListenerClient.Object);
            var result     = await controller.Delete("00000000-0000-0000-0000-000000000001");

            var contentResult = (result as OkObjectResult).Value;

            Assert.NotNull(contentResult);
            Assert.Equal(contentResult, room);
        }
        public void Delete_RedirectsWhenInputDataIsIncorrect()
        {
            var result = _controller.Delete(-1) as NotFoundResult;

            Assert.AreEqual(404, result.StatusCode);
        }