本文整理汇总了C#中JabbR.Services.ChatService类的典型用法代码示例。如果您正苦于以下问题:C# ChatService类的具体用法?C# ChatService怎么用?C# ChatService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChatService类属于JabbR.Services命名空间,在下文中一共展示了ChatService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakesUserOwner
public void MakesUserOwner()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo"
};
var user2 = new ChatUser
{
Name = "foo2"
};
repository.Add(user);
repository.Add(user2);
var room = new ChatRoom
{
Name = "Room",
Creator = user
};
room.Owners.Add(user);
user.OwnedRooms.Add(room);
user.Rooms.Add(room);
room.Users.Add(user);
var service = new ChatService(repository);
service.AddOwner(user, user2, room);
Assert.True(room.Owners.Contains(user2));
Assert.True(user2.OwnedRooms.Contains(room));
}
示例2: ThrowsIfNameIsInValid
public void ThrowsIfNameIsInValid()
{
var repository = new InMemoryRepository();
var service = new ChatService(new Mock<ICache>().Object, repository,new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("some in valid name", clientId: null, userAgent: null, password: null));
}
示例3: MakesOwnerAllowedIfRoomLocked
public void MakesOwnerAllowedIfRoomLocked()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo"
};
var user2 = new ChatUser
{
Name = "foo2"
};
repository.Add(user);
repository.Add(user2);
var room = new ChatRoom
{
Name = "Room",
Creator = user,
Private = true
};
room.Owners.Add(user);
user.OwnedRooms.Add(room);
user.Rooms.Add(room);
room.Users.Add(user);
var service = new ChatService(repository, new Mock<ICryptoService>().Object);
service.AddOwner(user, user2, room);
Assert.True(user2.AllowedRooms.Contains(room));
Assert.True(room.AllowedUsers.Contains(user2));
Assert.True(room.Owners.Contains(user2));
Assert.True(user2.OwnedRooms.Contains(room));
}
示例4: ThrowsIfPasswordIsTooShort
public void ThrowsIfPasswordIsTooShort()
{
var repository = new InMemoryRepository();
var service = new ChatService(new Mock<ICache>().Object, repository,new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("SomeUser", clientId: null, userAgent: null, password: "short"));
}
示例5: UnicodeNameIsValid
public void UnicodeNameIsValid()
{
// Fix issue #370
var repository = new InMemoryRepository();
var service = new ChatService(new Mock<ICache>().Object, repository,new Mock<ICryptoService>().Object);
var user = service.AddUser("ТарасБуга", clientId: null, userAgent: null, password: "password");
Assert.Equal("ТарасБуга", user.Name);
}
示例6: ThrowsIfNameInUse
public void ThrowsIfNameInUse()
{
var repository = new InMemoryRepository();
repository.Add(new ChatUser()
{
Name = "taken"
});
var service = new ChatService(new Mock<ICache>().Object, repository,new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddUser("taken", clientId: null, userAgent: null, password: null));
}
示例7: AddsUserToRepository
public void AddsUserToRepository()
{
var crypto = new Mock<ICryptoService>();
crypto.Setup(c => c.CreateSalt()).Returns("salted");
var repository = new InMemoryRepository();
var service = new ChatService(new Mock<ICache>().Object, repository,crypto.Object);
service.AddUser("SomeUser", clientId: null, userAgent: null, password: "password");
var user = repository.GetUserByName("SomeUser");
Assert.NotNull(user);
Assert.Equal("SomeUser", user.Name);
Assert.Equal("salted", user.Salt);
Assert.Equal("8f5793009fe15c2227e3528d0507413a83dff10635d3a6acf1ba3229a03380d8", user.HashedPassword);
}
示例8: ThrowsIfActingUserIsNotAdmin
public void ThrowsIfActingUserIsNotAdmin()
{
var repository = new InMemoryRepository();
var nonAdmin = new ChatUser
{
Name = "foo"
};
var user = new ChatUser
{
Name = "foo2"
};
repository.Add(nonAdmin);
repository.Add(user);
var service = new ChatService(new Mock<ICache>().Object, repository);
Assert.Throws<HubException>(() => service.AddAdmin(nonAdmin, user));
}
示例9: ThrowsIfActingUserIsNotAdmin
public void ThrowsIfActingUserIsNotAdmin()
{
var repository = new InMemoryRepository();
var nonAdmin = new ChatUser
{
Name = "foo"
};
var user = new ChatUser
{
Name = "foo2"
};
repository.Add(nonAdmin);
repository.Add(user);
var service = new ChatService(repository, new Mock<ICryptoService>().Object);
Assert.Throws<InvalidOperationException>(() => service.AddAdmin(nonAdmin, user));
}
示例10: MakesUserAdmin
public void MakesUserAdmin()
{
var repository = new InMemoryRepository();
var admin = new ChatUser
{
Name = "foo",
IsAdmin = true
};
var user = new ChatUser
{
Name = "foo2",
IsAdmin = false
};
repository.Add(admin);
repository.Add(user);
var service = new ChatService(new Mock<ICache>().Object, repository);
service.AddAdmin(admin, user);
Assert.True(user.IsAdmin);
}
示例11: AddsNewMessageToRepository
public void AddsNewMessageToRepository()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo"
};
repository.Add(user);
var room = new ChatRoom
{
Name = "Room"
};
repository.Add(room);
room.Users.Add(user);
user.Rooms.Add(room);
var service = new ChatService(repository);
ChatMessage message = service.AddMessage(user, room, "Content");
Assert.NotNull(message);
Assert.Same(message, room.Messages.First());
Assert.Equal("Content", message.Content);
}
示例12: MarksUserAsOfflineIfNoMoreClients
public void MarksUserAsOfflineIfNoMoreClients()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo",
Status = (int)UserStatus.Inactive
};
user.ConnectedClients.Add(new ChatClient
{
Id = "foo",
User = user
});
repository.Add(user);
var service = new ChatService(repository);
service.DisconnectClient("foo");
Assert.Equal(0, user.ConnectedClients.Count);
Assert.Equal((int)UserStatus.Offline, user.Status);
}
示例13: UpatesUserPassword
public void UpatesUserPassword()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "Test",
HashedPassword = "password".ToSha256()
};
repository.Add(user);
var service = new ChatService(repository);
service.ChangeUserPassword(user, "password", "password2");
Assert.Equal("password2".ToSha256(), user.HashedPassword);
}
示例14: SetupNinject
private static KernelBase SetupNinject(ApplicationSettings settings)
{
var kernel = new StandardKernel(new[] { new FactoryModule() });
kernel.Bind<JabbrContext>()
.To<JabbrContext>();
kernel.Bind<IJabbrRepository>()
.To<PersistedRepository>();
kernel.Bind<IChatService>()
.To<ChatService>();
kernel.Bind<IDataProtection>()
.To<JabbRDataProtection>();
kernel.Bind<IFormsAuthenticationProvider>()
.To<JabbRFormsAuthenticationProvider>();
kernel.Bind<ILogger>()
.To<RealtimeLogger>();
// We're doing this manually since we want the chat repository to be shared
// between the chat service and the chat hub itself
kernel.Bind<Chat>()
.ToMethod(context =>
{
var resourceProcessor = context.Kernel.Get<ContentProviderProcessor>();
var repository = context.Kernel.Get<IJabbrRepository>();
var cache = context.Kernel.Get<ICache>();
var service = new ChatService(cache, repository);
return new Chat(resourceProcessor,
service,
repository,
cache);
});
kernel.Bind<ICryptoService>()
.To<CryptoService>()
.InSingletonScope();
kernel.Bind<IResourceProcessor>()
.To<ResourceProcessor>()
.InSingletonScope();
kernel.Bind<IApplicationSettings>()
.ToConstant(settings);
kernel.Bind<IJavaScriptMinifier>()
.To<AjaxMinMinifier>()
.InSingletonScope();
kernel.Bind<IMembershipService>()
.To<MembershipService>();
kernel.Bind<IAuthenticationService>()
.ToConstant(new AuthenticationService());
kernel.Bind<IAuthenticationCallbackProvider>()
.To<JabbRAuthenticationCallbackProvider>();
kernel.Bind<ICache>()
.To<DefaultCache>()
.InSingletonScope();
kernel.Bind<IChatNotificationService>()
.To<ChatNotificationService>();
if (String.IsNullOrEmpty(settings.VerificationKey) ||
String.IsNullOrEmpty(settings.EncryptionKey))
{
kernel.Bind<IKeyProvider>()
.ToConstant(new FileBasedKeyProvider());
}
else
{
kernel.Bind<IKeyProvider>()
.To<AppSettingKeyProvider>()
.InSingletonScope();
}
var serializer = new JsonNetSerializer(new JsonSerializerSettings()
{
DateFormatHandling = DateFormatHandling.IsoDateFormat
});
kernel.Bind<IJsonSerializer>()
.ToConstant(serializer);
kernel.Bind<UploadCallbackHandler>()
.ToSelf()
.InSingletonScope();
kernel.Bind<UploadProcessor>()
.ToSelf()
.InSingletonScope();
kernel.Bind<ContentProviderProcessor>()
//.........这里部分代码省略.........
示例15: ThrowsIfUserIsAlreadyAnOwner
public void ThrowsIfUserIsAlreadyAnOwner()
{
var repository = new InMemoryRepository();
var user = new ChatUser
{
Name = "foo"
};
repository.Add(user);
var room = new ChatRoom
{
Name = "Room"
};
room.Users.Add(user);
room.Owners.Add(user);
user.OwnedRooms.Add(room);
user.Rooms.Add(room);
var service = new ChatService(repository);
Assert.Throws<InvalidOperationException>(() => service.AddOwner(user, user, room));
}