Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 91 lines (76 sloc) 2.862 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
using SignalR.Hubs;
using Xunit;

namespace SignalR.Tests
{
    public class DefaultHubResolverFacts
    {
[Fact]
        public void ShouldResolveHubByTypeName()
        {
            var resolver = new DefaultDependencyResolver();
            var hubResolver = new ReflectedHubDescriptorProvider(resolver);
            HubDescriptor hub;
            hubResolver.TryGetHub("HubWithoutAttribute", out hub);

            Assert.NotNull(hub);
            Assert.Equal(hub.Name, "HubWithoutAttribute");
            Assert.Equal(hub.NameSpecified, false);
        }

[Fact]
        public void ShouldResolveHubByHubNameAttribute()
        {
            var resolver = new DefaultDependencyResolver();
            var hubResolver = new ReflectedHubDescriptorProvider(resolver);
            HubDescriptor hub;
            hubResolver.TryGetHub("NameFromAttribute", out hub);

            Assert.NotNull(hub);
            Assert.Equal(hub.Name, "NameFromAttribute");
            Assert.Equal(hub.NameSpecified, true);
        }

[Fact]
        public void ShouldNotResolveHubByFullTypeName()
        {
            var resolver = new DefaultDependencyResolver();
            var hubResolver = new ReflectedHubDescriptorProvider(resolver);
            HubDescriptor hub;
            hubResolver.TryGetHub("SignalR.Tests.HubWithoutAttribute", out hub);

            Assert.Null(hub);
        }

[Fact]
        public void ShouldNotResolveHubByTypeNameIfAttributeExists()
        {
            var resolver = new DefaultDependencyResolver();
            var hubResolver = new ReflectedHubDescriptorProvider(resolver);
            HubDescriptor hub;
            hubResolver.TryGetHub("HubWithAttribute", out hub);

            Assert.Null(hub);
        }

[Fact]
        public void ShouldIgnoreCaseWhenDiscoveringHubs()
        {
            var resolver = new DefaultDependencyResolver();
            var hubResolver = new ReflectedHubDescriptorProvider(resolver);
            HubDescriptor hub;
            hubResolver.TryGetHub("hubwithoutattribute", out hub);

            Assert.NotNull(hub);
            Assert.Equal(hub.Name, "HubWithoutAttribute");
            Assert.Equal(hub.NameSpecified, false);
        }

[Fact]
        public void ShouldIgnoreCaseWhenDiscoveringHubsUsingManager()
        {
            var resolver = new DefaultDependencyResolver();
            var manager = new DefaultHubManager(resolver);
            var hub = manager.GetHub("hubwithoutattribute");

            Assert.NotNull(hub);
            Assert.Equal(hub.Name, "HubWithoutAttribute");
            Assert.Equal(hub.NameSpecified, false);
        }

[HubName("NameFromAttribute")]
        public class HubWithAttribute : Hub
        {
        }

        public class HubWithoutAttribute : Hub
        {
        }
    }
}
Something went wrong with that request. Please try again.