Пример #1
0
        public async void DeleteNotification_ReturnsBadRequestObjectResult_WhenUserOrNotificationGuidIdIsInvalid(string testUserId, string testNotificationId)
        {
            //Arrange
            var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object);

            //Act
            var result = await controller.DeleteNotification(testUserId, testNotificationId);

            //Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal($"User id: {testUserId} or notification id: {testNotificationId} is not valid guid.", badRequestObjectResult.Value);
        }
        public void Test_DeleteNotification_ReturnsNotFoundResult()
        {
            // Arrange
            var mockRepo   = new Mock <IMongoDataRepository <Notification> >();
            var mockHub    = new Mock <IHubContext <LiveNotificationHub> >();
            var controller = new NotificationsController(mockRepo.Object, mockHub.Object, Mapper);

            // Act
            var notFoundResult = controller.DeleteNotification(ObjectId.GenerateNewId().ToString());

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
Пример #3
0
        public async void DeleteNotificaton_ReturnsNotFoundObjectResult_WhenTheUserDoesntExist()
        {
            //Arrange
            _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>()))
            .ReturnsAsync(false);

            var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object);

            //Act
            var result = await controller.DeleteNotification(ConstIds.ExampleUserId, ConstIds.ExampleNotificationId);

            //Assert
            var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.Equal($"User: {ConstIds.ExampleUserId} not found.", notFoundObjectResult.Value);
            _mockUserService.Verify();
        }
Пример #4
0
        public async void DeleteNotification_ReturnsInternalServerErrorResult_WhenExceptionThrownInService()
        {
            //Arrange
            _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>()))
            .Throws(new ArgumentNullException(nameof(Guid)))
            .Verifiable();

            var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object);

            //Act
            var result = await controller.DeleteNotification(ConstIds.ExampleUserId, ConstIds.ExampleNotificationId);

            //Assert
            var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode);
            _mockUserService.Verify();
        }
Пример #5
0
        public async void DeleteNotification_ReturnsNoContentResult_WhenTheNotificationHasBeenRemoved()
        {
            //Arrange
            _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>()))
            .ReturnsAsync(true)
            .Verifiable();
            _mockNotificationService.Setup(Service => Service.DeleteNotificationAsync(It.IsAny <Guid>()))
            .Verifiable();

            var controller = new NotificationsController(_loggerMock.Object, _mockNotificationService.Object, _mockUserService.Object);

            //Act
            var result = await controller.DeleteNotification(ConstIds.ExampleUserId, ConstIds.ExampleNotificationId);

            //Act
            var noContentResult = Assert.IsType <NoContentResult>(result);

            _mockUserService.Verify();
            _mockNotificationService.Verify();
        }
        public void Test_DeleteNotification_ReturnsOkResult()
        {
            // Arrange
            var mockRepo = new Mock <IMongoDataRepository <Notification> >();

            double[]     position     = new double[] { 30.2, 50.3 };
            Notification notification = this.Mock.MockNotification(position);

            notification.Id        = ObjectId.GenerateNewId();
            notification.CreatedAt = notification.UpdatedAt = DateTime.UtcNow;

            mockRepo.Setup(repo => repo.GetObjectByIdAsync(notification.Id.ToString()))
            .Returns(Task.FromResult(notification));

            var mockHub    = new Mock <IHubContext <LiveNotificationHub> >();
            var controller = new NotificationsController(mockRepo.Object, mockHub.Object, Mapper);

            // Act
            var okResult = controller.DeleteNotification(notification.Id.ToString());

            // Assert
            Assert.IsType <OkObjectResult>(okResult.Result);
        }