public void GetImByName_FindsImWithMatchingUserName_AndCaches() { var matchingUser = new User { Id = "U1", Name = "foo" }; var otherUser = new User { Id = "U2", Name = "bar" }; _api.Users.List().Returns(new UserListResponse { Members = { otherUser, matchingUser } }); var expectedIm = new Im { Id = "D123", User = matchingUser.Id }; _api.Im.Open(matchingUser.Id, true).Returns(new ImResponse { Channel = expectedIm }); _sut.GetImByName("@foo") .ShouldComplete() .And.ShouldBe(expectedIm); _sut.GetImByName("foo") .ShouldComplete() .And.ShouldBe(expectedIm); _api.Users.Received(1).List(); _api.Im.ReceivedWithAnyArgs(1).Open(Arg.Any <string>()); }
public async Task GetImByName_FindsImWithMatchingUserName_AndCaches() { var matchingUser = new User { Id = "U1", Name = "foo" }; var otherUser = new User { Id = "U2", Name = "bar" }; _api.Users.List().Returns(new UserListResponse { Members = { otherUser, matchingUser } }); var expectedIm = new Conversation { Id = "D123", User = matchingUser.Id, IsIm = true }; _api.Conversations.OpenAndReturnInfo(UserIds(matchingUser.Id)).Returns(new ConversationOpenResponse { Channel = expectedIm }); var result = await _sut.GetImByName("@foo"); result.ShouldBeA <Im>() .And(im => { im.Id.ShouldBe(expectedIm.Id); im.User.ShouldBe(expectedIm.User); }); _sut.GetImByName("foo") .ShouldComplete() .And.ShouldBe(result); await _api.Users.Received(1).List(); await _api.Conversations.ReceivedWithAnyArgs(1).OpenAndReturnInfo(Arg.Any <string[]>()); }