public void Test_GetNotificationById_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.GetNotificationById(ObjectId.GenerateNewId().ToString()); // Assert Assert.IsType <NotFoundResult>(notFoundResult.Result); }
public void Test_GetNotificationById_ReturnsRightItem() { // 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.GetNotificationById(notification.Id.ToString()).Result as OkObjectResult; // Assert Assert.IsType <NotificationReadDto>(okResult.Value); Assert.Equal(notification.Id.ToString(), (okResult.Value as NotificationReadDto).Id); }