public void Test_CreateNotification_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.CreateNotification((NotificationCreateDto)null);

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
        public void Test_CreateNotification_ReturnsOkResult()
        {
            // Arrange
            var mockRepo   = new Mock <IMongoDataRepository <Notification> >();
            var mockHub    = new Mock <IHubContext <LiveNotificationHub> >();
            var controller = new NotificationsController(mockRepo.Object, mockHub.Object, Mapper);

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

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

            // Act
            var okResult = controller.CreateNotification(this.Mapper.Map <NotificationCreateDto>(notification));

            // Assert
            Assert.IsType <OkObjectResult>(okResult.Result);
        }
示例#3
0
        public async void NotificationsController_CreateNotification_ShouldCallServiceToCreateNotification()
        {
            // Arrange
            _mockNotificationService.Setup(_ => _.CreateNotification(It.IsAny <NotificationModel>()))
            .ReturnsAsync(new NotificationModel {
                Id = 1
            });

            // Act
            var result = await _controller.CreateNotification(new NotificationModel());

            // Assert
            result.Should().BeOfType <OkNegotiatedContentResult <NotificationModel> >();

            var resultContent = result.As <OkNegotiatedContentResult <NotificationModel> >();

            resultContent.Content.Id.Should().Be(1);

            Mock.VerifyAll();
        }
        public void Test_CreateNotification_ReturnsRightItem()
        {
            // Arrange
            var mockRepo   = new Mock <IMongoDataRepository <Notification> >();
            var mockHub    = new Mock <IHubContext <LiveNotificationHub> >();
            var controller = new NotificationsController(mockRepo.Object, mockHub.Object, Mapper);

            this.Mock.GenerateMockStations();

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

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

            // Act
            var okResult = controller.CreateNotification(this.Mapper.Map <NotificationCreateDto>(notification)).Result as OkObjectResult;

            // Assert
            Assert.IsType <NotificationReadDto>(okResult.Value);
            Assert.True(notification.Position.SequenceEqual((okResult.Value as NotificationReadDto).Position));
        }