Ejemplo n.º 1
0
        public void DislplayAnonimousIfNameWasNotSelected()
        {
            // Arrange
            var dbContext      = host.Services.GetService <AppDbContext>();
            var userManager    = host.Services.GetService <UserManager <AppUser> >();
            var roleManager    = host.Services.GetService <RoleManager <IdentityRole> >();
            var signalRContext = host.Services.GetService <IConnectionManager>();
            var hub            = new ChatHub(dbContext, userManager, roleManager);
            Mock <HubCallerContext> mockClientContext = new Mock <HubCallerContext>();

            mockClientContext.Setup(m => m.Items).Returns(new Dictionary <object, object>());
            hub.Context = mockClientContext.Object;

            // Act
            // Do Nothing

            // Assert
            Assert.Equal("Имя не установлено", hub.GetName().Result);
        }
Ejemplo n.º 2
0
        public async Task CanSetName()
        {
            // Arrange
            var dbContext      = host.Services.GetService <AppDbContext>();
            var userManager    = host.Services.GetService <UserManager <AppUser> >();
            var roleManager    = host.Services.GetService <RoleManager <IdentityRole> >();
            var signalRContext = host.Services.GetService <IConnectionManager>();
            var hub            = new ChatHub(dbContext, userManager, roleManager);
            Mock <HubCallerContext> mockClientContext = new Mock <HubCallerContext>();

            mockClientContext.Setup(m => m.Items).Returns(new Dictionary <object, object>());
            hub.Context = mockClientContext.Object;

            // Act
            await hub.SetName("Ivan");

            // Assert
            Assert.Equal("Ivan", hub.GetName().Result);
        }