Exemplo n.º 1
0
        public void BatteryChargeNegativePercentTest()
        {
            DellBuildStrategy builder = new DellBuildStrategy();
            var computers = builder.BuildComputers();

            Computer laptop = computers[2];
            //reflection test object
            FieldInfo fieldInfo = laptop.GetType().GetField("battery", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldInfo.SetValue(laptop, -1);

            var batteryPower = GetInstanceField(typeof(Computer), laptop, "battery");
            Assert.AreNotEqual(-1, batteryPower);
        }
Exemplo n.º 2
0
        public void SquareZeroNumber32BitTest()
        {
            DellBuildStrategy builder = new DellBuildStrategy();
            var computers = builder.BuildComputers();
            Computer server = computers[1];

            FieldInfo fieldInfo = server.Ram.GetType().GetField("value", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldInfo.SetValue(server.Ram, 0);

            server.Cpu.SquareNumber();

            var originalConsoleOut = Console.Out; // preserve the original stream
            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                server.Cpu.SquareNumber();
                writer.Flush(); // when you're done, make sure everything is written out

                var myString = writer.GetStringBuilder().ToString();
                Console.SetOut(originalConsoleOut);
                Assert.AreEqual("Square of 0 is 0.\r\n", myString);
            }

            Console.SetOut(originalConsoleOut); // restore Console.Out
        }
Exemplo n.º 3
0
        public void SquareFloatingNumber32BitTest()
        {
            DellBuildStrategy builder = new DellBuildStrategy();
            var computers = builder.BuildComputers();
            Computer server = computers[1];

            FieldInfo fieldInfo = server.Ram.GetType().GetField("value", BindingFlags.Instance | BindingFlags.NonPublic);

            bool isWoring = false;
            try
            {
                fieldInfo.SetValue(server.Ram, 1.11111d);
            }
            catch (ArgumentException)
            {
                isWoring = true;
            }

            Assert.AreEqual(true, isWoring);
        }