Пример #1
0
        public async Task Should_Request_Nickname_When_Connect()
        {
            // arrage
            Guid   expectedConnectionUid = Guid.NewGuid();
            Client expectedClient        = new Client()
            {
                ConnectionUid = expectedConnectionUid
            };

            Client             actualClient  = null;
            SetNicknameCommand actualCommand = null;

            DomainEvents.OnCommand += (connectionUid, command) =>
            {
                actualClient  = connectionUid;
                actualCommand = command as SetNicknameCommand;
                return(Task.CompletedTask);
            };

            ClientFactoryMock.Setup(mock => mock.Create(expectedConnectionUid)).Returns(expectedClient);

            // act
            await ChatFacade.ConnectAsync(expectedConnectionUid);

            // assert
            Assert.AreEqual(expectedConnectionUid, actualClient.ConnectionUid);
            Assert.IsNotNull(actualCommand);
        }
Пример #2
0
        public static async Task Main(string[] args)
        {
            name    = "console " + random.Next(0, 10000);
            service = new ChatService();
            service.OnReceivedMessage += Service_OnReceivedMessage;
            Console.WriteLine("Enter IP:");
            var ip = Console.ReadLine();

            service.Init(ip, ip != "localhost");

            await service.ConnectAsync();

            Console.WriteLine("You are connected...");

            await JoinRoom();

            var keepGoing = true;

            do
            {
                var text = Console.ReadLine();
                if (text == "exit")
                {
                }
                else if (text == "leave")
                {
                    await service.LeaveChannelAsync(room, name);
                    await JoinRoom();
                }
                else
                {
                    await service.SendMessageAsync(room, name, $"{name}:{text}");
                }
            }while (keepGoing);
        }
Пример #3
0
        public static async Task Main(string[] args)
        {
            service = new ChatService();
            service.OnReceivedMessage += Service_OnReceivedMessage;
            Console.WriteLine("Enter IP:");
            var ip = Console.ReadLine();

            service.Init(ip);

            await service.ConnectAsync();

            Console.WriteLine("You are connected...");
            Console.WriteLine($"Enter room ({string.Join(",", service.GetRooms())}):");
            var room = Console.ReadLine();

            await service.JoinChannelAsync(room, "console app");

            var keepGoing = true;

            do
            {
                var text = Console.ReadLine();
                if (text == "exit")
                {
                    keepGoing = false;
                }
                else
                {
                    await service.SendMessageAsync(room, "console app", text);
                }
            }while (keepGoing);
        }
Пример #4
0
        public static async Task Main(string[] args)
        {
            var name = $"Console {random.Next(0, 10000)}";

            service = new ChatService();
            service.OnReceiveMessage += (s, e) =>
            {
                if (e.User == name)
                {
                    return;
                }

                Console.WriteLine($"{e.User}: {Environment.NewLine}{e.Message}");
            };

            service.OnEnteredOrExisted += (s, e) =>
            {
                Console.WriteLine($"{e.User} entered.");
            };

            Console.WriteLine("Enter server Ip address:");
            var ipAddress = Console.ReadLine();

            service.Init(ipAddress, !IsLoopbackIpAddress(ipAddress));

            await service.ConnectAsync();

            Console.WriteLine("You are connected...");

            var room = await joinRoom(name);

            var keepConnected = true;

            do
            {
                var text = Console.ReadLine();
                if (text.Trim().Equals("exit", StringComparison.OrdinalIgnoreCase))
                {
                    keepConnected = false;
                }
                else if (text.Trim().Equals("leave", StringComparison.OrdinalIgnoreCase))
                {
                    await service.LeaveChannelAsync(room, name);

                    await joinRoom(name);
                }
                else
                {
                    await service.SendMessageAsync(room, name, text.Trim());
                }
            }while (keepConnected);
        }
Пример #5
0
        /// <summary>Main method.</summary>
        /// <param name="args">Application arguments.</param>
        /// <returns>Async Task.</returns>
        public static async Task Main(string[] args)
        {
            service = new ChatService();
            service.OnReceivedMessage += Service_OnReceivedMessage;
            service.OnEnteredOrExited += Service_OnEnteredOrExited;
            Console.WriteLine("Enter user name:");
            name = Console.ReadLine();
            Console.WriteLine("Enter IP:");
            string ip = Console.ReadLine();

            service.Init(ip, ip != "localhost");

            await service.ConnectAsync();

            Console.WriteLine("You are connected...");

            bool keepGoing = await JoinRoom();

            if (!keepGoing)
            {
                return;
            }

            do
            {
                string text = Console.ReadLine();
                if (text == "exit")
                {
                    keepGoing = false;
                }
                else if (text == "leave")
                {
                    await service.LeaveChannelAsync(room, name);

                    keepGoing = await JoinRoom();
                }
                else
                {
                    await service.SendMessageAsync(room, name, text);
                }
            }while (keepGoing);
        }
Пример #6
0
        private static async Task TestMulticast()
        {
            name    = "console " + random.Next(0, 10000);
            service = new ChatService();
            service.OnReceivedMessage += Service_OnReceivedMessage;
            System.Console.WriteLine("Enter IP:");
            var ip = System.Console.ReadLine();

            service.Init(ip, ip != "localhost");

            await service.ConnectAsync();

            System.Console.WriteLine("You are connected...");

            await JoinRoom();

            var keepGoing = true;

            do
            {
                var text = System.Console.ReadLine();
                if (text == "exit")
                {
                    keepGoing = false;
                }
                else if (text == "leave")
                {
                    await service.LeaveChannelAsync(room, name);

                    System.Console.WriteLine($"You've left of {room} Room");
                    await JoinRoom();
                }
                else
                {
                    await service.SendMessageAsync(room, name, text);
                }
            }while (keepGoing);
        }