Created
December 3, 2011 07:12
-
-
Save Buildstarted/1426370 to your computer and use it in GitHub Desktop.
blah.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void MessageAddedToRoomWithHashtagParsed() { | |
string expected = "<a href=\"#/rooms/hashtag\" title=\"#hashtag\">#hashtag</a>"; | |
string clientId = Guid.NewGuid().ToString(); | |
var repository = new InMemoryRepository(); | |
var room = new ChatRoom() { Name = "hashtag" }; | |
var user = new ChatUser() { Name = "testhashtaguser", Id = clientId }; | |
repository.Add(room); | |
repository.Add(user); | |
room.Users.Add(user); | |
user.Rooms.Add(room); | |
var service = new ChatService(repository, new Mock<ICryptoService>().Object); | |
Chat chat = new Chat(service, repository); | |
chat.Caller = new FakeCaller(clientId, room.Name); | |
chat.Context = new FakeHubContext(clientId, null, null); | |
chat.Agent = Hub.GetClients("Chat"); | |
chat.Send("#hashtag"); | |
var message = room.Messages.First(); | |
Assert.Equal(expected, message.Content); | |
} | |
[Fact] | |
public void MessageAddedToRoomWithInvalidHashtagNotParsed() { | |
string expected = "#invalidhashtag"; | |
string clientId = Guid.NewGuid().ToString(); | |
var repository = new InMemoryRepository(); | |
var room = new ChatRoom() { Name = "hashtag" }; | |
var user = new ChatUser() { Name = "testhashtaguser", Id = clientId }; | |
repository.Add(room); | |
repository.Add(user); | |
room.Users.Add(user); | |
user.Rooms.Add(room); | |
var service = new ChatService(repository, new Mock<ICryptoService>().Object); | |
Chat chat = new Chat(service, repository); | |
chat.Caller = new FakeCaller(clientId, room.Name); | |
chat.Context = new FakeHubContext(clientId, null, null); | |
chat.Agent = Hub.GetClients("Chat"); | |
chat.Send("#invalidhashtag"); | |
var message = room.Messages.First(); | |
Assert.Equal(expected, message.Content); | |
} | |
public class FakeCaller : DynamicObject { | |
private string _clientId; | |
private string _activeRoom; | |
public FakeCaller(string clientId, string activeRoom) { | |
this._clientId = clientId; | |
this._activeRoom = activeRoom; | |
} | |
public override bool TryGetMember(GetMemberBinder binder, out object result) { | |
switch(binder.Name) { | |
case "version": | |
result = typeof (Chat).Assembly.GetName().Version.ToString(); | |
return true; | |
case "id": | |
result = _clientId; | |
return true; | |
case "activeRoom": | |
result = _activeRoom; | |
return true; | |
} | |
result = null; | |
return false; | |
} | |
} | |
public class FakeHubContext : SignalR.Hubs.HubContext { | |
public FakeHubContext(string clientId, HttpCookieCollection cookies, IPrincipal user) : base(clientId, cookies, user) { | |
} | |
} | |
public class FakeClientAgent : IClientAgent { | |
#region Implementation of IClientAgent | |
public Task Invoke(string method, params object[] args) { | |
throw new NotImplementedException(); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment