Base solution for your next web application
Open Closed

Testing Publish and Notification #2509


User avatar
0
drsmallbone created

Hi,

I am having an issue with testing if a notification is received. I have set up a unit test to but my test never completes, when I debug the test when it hits my publish method it just ends. I am passing a list of of users so it should not be anything to do with subscriptions.

My Test

public class Publisher_Tests : FooTestBase
    {
        private readonly IPublisher _notificationPublisher;
        private readonly IUserNotificationManager _userNotificationManager;

        public Publisher_Tests()
        {
            _notificationPublisher = Resolve();
            _userNotificationManager = Resolve();
        }

        [Fact]
        public void Publish_ShouldPublishGeneralNotification()
        {
            string notificationName = "TestGeneralNotification";
            UserIdentifier userIndentifier = new UserIdentifier(1, 2);
            List userIdentifiers = new List
            {
                userIndentifier
            };
            _notificationPublisher.Publish(notificationName, userIdentifiers);

            UsingDbContext(context =>
            {
                var output = _userNotificationManager.GetUserNotificationCount(userIndentifier);
                output.ShouldBeGreaterThan(0);
            });
        }
    }

My Method

public class Publisher : DomainService, IPublisher
    {
        private readonly INotificationPublisher _notificationPublisher;

        public Publisher(INotificationPublisher notificationPublisher)
        {
            _notificationPublisher = notificationPublisher;
        }

        public void Publish(string notificationName, List userIdentifiers)
        {
            _notificationPublisher.Publish(notificationName, null, null, NotificationSeverity.Info, userIdentifiers.ToArray());
        }

        public async Task PublishAsync(string notificationName, List userIdentifiers)
        {
            await _notificationPublisher.PublishAsync(notificationName, null, null, NotificationSeverity.Info, userIdentifiers.ToArray());
        }
    }

Any help would be really appreciated.


3 Answer(s)