예제 #1
0
파일: ToxLoop.cs 프로젝트: Tornjk/SharpTox
        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);
        }
예제 #2
0
        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 _);
                    }
                }
        }
예제 #3
0
파일: ToxLoop.cs 프로젝트: Tornjk/SharpTox
 public void Start_NullToxIterate_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => ToxLoop.Start(null));
 }