public void Start_ToxIterate_CallIterate() { var scheduler = new TestScheduler(); var iterate = A.Fake <IToxIterate>(); A.CallTo(() => iterate.Iterate()) .Returns(TimeSpan.FromTicks(1)); using (ToxLoop.Start(iterate, scheduler)) { scheduler.AdvanceBy(2); } A.CallTo(() => iterate.Iterate()) .MustHaveHappened(2, Times.OrMore); }
static void Main(string[] args) { using (IToxOptions options = ToxOptions.Default()) using (ITox tox = options.Create()) { tox.OnFriendRequestReceived += OnFriendRequestReceived; tox.OnFriendMessageReceived += OnFriendMessageReceived; tox.OnConnectionStatusChanged += Tox_OnConnectionStatusChanged; foreach (ToxNode node in Nodes) { tox.Bootstrap(node, out _); } tox.Name = "SharpTox"; tox.StatusMessage = "Testing SharpTox"; using (ToxLoop.Start(tox)) { Console.WriteLine($"ID: {tox.Id}"); Console.ReadKey(); } void OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e) { //get the name associated with the friendnumber string name = tox.GetFriendName(e.FriendNumber, out _); //print the message to the console Console.WriteLine("<{0}> {1}", name, e.Message); } void OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e) { //automatically accept every friend request we receive tox.AddFriendNoRequest(e.PublicKey, out _); } } }
public void Start_NullToxIterate_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ToxLoop.Start(null)); }