Ejemplo n.º 1
0
        public void toOunceTest()
        {
            ConversionMethods conversionTest = new ConversionMethods();
            double            result         = conversionTest.toOunces(15);

            Assert.AreEqual(0.52910942924, result, 0.001);
        }
Ejemplo n.º 2
0
        private static void DoIt(TcpClient clientConnection)
        {
            NetworkStream stream = clientConnection.GetStream();
            StreamReader  reader = new StreamReader(stream);
            StreamWriter  writer = new StreamWriter(stream);

            while (true)
            {
                string request = reader.ReadLine();
                if (string.IsNullOrEmpty(request))
                {
                    break;
                }
                Console.WriteLine("Request: " + request);
                string response     = request;
                var    splitRequest = request.Split();

                double conversionNumber = double.Parse(splitRequest[1]);
                Console.WriteLine($"Converting {conversionNumber} to ounces:");

                switch (splitRequest[0])
                {
                case ("toounces"):
                    ConversionMethods toOuncesObject = new ConversionMethods();
                    double            OunceResult    = toOuncesObject.toOunces(conversionNumber);
                    Console.WriteLine($"Result: {OunceResult} oz");
                    break;

                case ("tograms"):
                    ConversionMethods toGramsObject = new ConversionMethods();
                    double            GramResult    = toGramsObject.toGrams(conversionNumber);
                    Console.WriteLine($"Result: {GramResult} g");
                    break;
                }

                writer.WriteLine(response);
                writer.Flush();
            }

            clientConnection.Close();
            Console.WriteLine("Socket closed");
        }