Exemplo n.º 1
0
        public void CanMakeCarWithSafetyRating()
        {
            int        expected   = 3;
            CarOptions carOptions = new CarOptions {
                SafetyRating = 3
            };
            ICar car = _carFactory.MakeCar(carOptions);

            Assert.AreEqual(expected, car.GetSafetyRating());
        }
Exemplo n.º 2
0
        public void CanMakeCarWithPrice()
        {
            double     expected   = 1000.00;
            CarOptions carOptions = new CarOptions {
                Price = 1000.00
            };
            ICar car = _carFactory.MakeCar(carOptions);

            Assert.AreEqual(expected, car.GetPrice());
        }
Exemplo n.º 3
0
        public void CanMakeCarWithColor()
        {
            String     expected   = "Red";
            CarOptions carOptions = new CarOptions {
                Color = "Red"
            };
            ICar car = _carFactory.MakeCar(carOptions);

            Assert.AreEqual(expected, car.GetColor());
        }
Exemplo n.º 4
0
        public void CanMakeCarWithBluetooth()
        {
            CarOptions carOptions = new CarOptions {
                OtherOptions = new Dictionary <String, Object>()
                {
                    { "Bluetooth", true }
                }
            };
            ICar car = _carFactory.MakeCar(carOptions);

            Assert.IsTrue((bool)car.GetOption("Bluetooth"));
        }
Exemplo n.º 5
0
        static void Main()
        {
            // The bitwise OR of 0001 and 0100 is 0101.
            CarOptions options = CarOptions.SunRoof | CarOptions.FogLights;

            // Because the Flags attribute is specified, Console.WriteLine displays
            // the name of each enum element that corresponds to a flag that has
            // the value 1 in variable options.
            Console.WriteLine(options);
            // The integer value of 0101 is 5.
            Console.WriteLine((int)options);
        }
Exemplo n.º 6
0
    static void Main(string[] args)
    {
        // combine two of the values together
        CarOptions ops = CarOptions.AlloyWheels | CarOptions.SatNav;

        // test to see if the combined value contains SatNav
        bool hasSatNav = (ops & CarOptions.SatNav) == CarOptions.SatNav;

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Exemplo n.º 7
0
        public void CanMakeCarWithNavigationSystem()
        {
            String     expected   = "ATMOS";
            CarOptions carOptions = new CarOptions {
                OtherOptions = new Dictionary <String, Object>()
                {
                    { "CarNav", "ATMOS" }
                }
            };
            ICar car = _carFactory.MakeCar(carOptions);

            Assert.AreEqual(expected, car.GetOption("CarNav"));
        }
Exemplo n.º 8
0
        public void EnumWithFlagsTest()
        {
            CarOptions options = CarOptions.SunRoof | CarOptions.FogLights;

            // ",를 구분자로 Flags를 출력해야 한다"
            Assert.Equal(
                "SunRoof, FogLights",
                options.ToString());

            Assert.Equal(
                (int)CarOptions.SunRoof + (int)CarOptions.FogLights,
                (int)options);
        }
Exemplo n.º 9
0
        public IndexModel(IConfiguration configuration,
                          IOptions <EmailOptions> emailOptions,
                          IOptionsSnapshot <CarOptions> carOptionsSnapshot,
                          IOptionsMonitor <EmailOptions> emailOptionsMonitor,
                          IOptions <VendorDetailOptions> vendorDetailOptions
                          )
        {
            _configurationRoot = configuration as IConfigurationRoot;

            _emailOptions        = emailOptions;
            _emailOptionsMonitor = emailOptionsMonitor;

            _teslaOptionsSnapshot      = carOptionsSnapshot.Get(CarOptions.Tesla);
            _cybertruckOptionsSnapshot = carOptionsSnapshot.Get(CarOptions.CyberTruck);
            _vendorDetailOptions       = vendorDetailOptions;
        }
        static void Main()
        {
            // The bitwise OR of 0001 and 0100 is 0101.
            CarOptions options = CarOptions.Rims | CarOptions.ParkAssistance;

            // Because the Flags attribute is specified, Console.WriteLine displays
            // the name of each enum element that corresponds to a flag that has
            // the value 1 in variable options.
            Console.WriteLine(options);

            if ((options & CarOptions.SunRoof) != 0)
            {
                Console.WriteLine("The car has a SunRoof!");
            }
            else
            {
                Console.WriteLine("Never mind, it's raining anyway");
            }
            // The integer value of 0110 is 6.
            Console.WriteLine((int)options);
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Volume myVolume = Volume.Medium;

            switch (myVolume)
            {
            case Volume.Low:
                Console.WriteLine("The volume is low.");
                break;

            case Volume.Medium:
                Console.WriteLine("The volume is medium.");
                break;

            case Volume.High:
                Console.WriteLine("The volume is high.");
                break;
            }

            Console.WriteLine("Meat.Rare = {0}", Meat.Rare.ToString());
            Console.WriteLine("Meat.Medium = {0}", Meat.Medium);
            Console.WriteLine("Meat.WellDone = {0}", Meat.WellDone);

            EnumTricks enumTricks = new EnumTricks();

            enumTricks.ListEnumByName();
            enumTricks.ListEnumByValue();

            CarOptions options = CarOptions.SunRoof | CarOptions.FogLights;

            Console.WriteLine(options);
            Console.WriteLine((int)options);

            CarOptions2 options2 = CarOptions2.SunRoof | CarOptions2.FogLights;

            Console.WriteLine(options2);
            Console.WriteLine((int)options2);

            Console.ReadKey();
        }
Exemplo n.º 12
0
 static void Main(string[] args)
 {
     int        x       = (int)Day.Wed;
     CarOptions options = CarOptions.SunRoof | CarOptions.ForLights;
 }
Exemplo n.º 13
0
        public void fromXmlString11Test()
        {
            CarOptions obj_ = (CarOptions)SerializeXmlObject.fromXmlStringObject("<Util.Util.CarOptions value=\"Spoiler, SunRoof\" />");

            Assert.AreEqual(CarOptions.Spoiler | CarOptions.SunRoof, obj_);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            OverflowExample();

            //Big Integer
            BigInteger bigIntFromDouble   = new BigInteger(4564564564542332);
            BigInteger assignedFromDouble = (BigInteger)4564564564542332;

            //Sorted set
            SortedSet <int> MySortedSet = new SortedSet <int> {
                8, 2, 1, 5, 10, 5, 10, 8
            };

            //Tuple
            Tuple <int, int, int, int, int> MultiplesOfTwo = Tuple.Create(2, 4, 6, 8, 10);

            Console.WriteLine(MultiplesOfTwo.Item2);
            var multiples = new Tuple <int, int, int, int, int, int, int, Tuple <int, int, int> >(2, 4, 6, 8, 10, 12, 14, new Tuple <int, int, int>(3, 6, 9));

            Console.WriteLine(multiples.Rest.Item1);

            //Complex number
            Complex c1 = new Complex(8, 2);
            Complex c2 = new Complex(8, 2);
            Complex c3 = c1 + c2;

            //File.ReadLines
            IEnumerable <string> FileContent = File.ReadLines("MyFile.txt");

            foreach (string Line in FileContent)
            {
                Console.Write(Line);
            }

            //Memory stream
            MemoryStream destinationStream = new MemoryStream();

            using (FileStream sourceStream = File.Open(@"c:\temp.txt", FileMode.Open))
            {
                sourceStream.CopyTo(destinationStream);
            }

            //Try parse
            Guid myGuid;

            Guid.TryParse("not a guid", out myGuid);

            //Enum example
            CarOptions myCar = CarOptions.MP3Player | CarOptions.AirCon | CarOptions.Turbo;

            Console.WriteLine("Does car have MP3? {0}", myCar.HasFlag(CarOptions.MP3Player));
            Console.ReadKey();

            //IsNullOrWhiteSpace
            String.IsNullOrWhiteSpace(" ");

            //Clear
            StringBuilder sb = new StringBuilder("long string");

            sb.Clear();

            //Special folder additions
            var test = Environment.SpecialFolder.CDBurning;

            //64 bit changes
            Console.WriteLine(Environment.Is64BitOperatingSystem);
            Console.WriteLine(Environment.Is64BitProcess);

            //stopwatch
            var sw = new Stopwatch();

            sw.Start();

            //httpwebrequest
            string loadbalancerIp = "http://127.0.0.1/";
            string host           = "mywebsite.com";
            var    request        = WebRequest.Create("http://127.0.0.1/") as HttpWebRequest;

            var socket = new System.Net.Sockets.Socket(new System.Net.Sockets.SocketInformation());

            socket.Connect(new DnsEndPoint("www.microsoft.com", 80));
            request.Date = System.DateTime.Now;
            sw.Restart();
        }
Exemplo n.º 15
0
 public Car()
 {
     this.Options = new CarOptions();
 }
Exemplo n.º 16
0
        public void toXmlString11Test()
        {
            CarOptions j_ = CarOptions.Spoiler | CarOptions.SunRoof;

            Assert.AreEqual("<Util.Util.CarOptions value=\"SunRoof, Spoiler\"/>", SerializeXmlObject.toXmlString(j_));
        }
Exemplo n.º 17
0
        static void types_test1()
        {
            //byte
            byte byteValue1 = 201;

            Console.WriteLine(byteValue1);

            byte byteValue2 = 0x00C9;

            Console.WriteLine(byteValue2);

            byte byteValue3 = 0b1100_1001;

            Console.WriteLine(byteValue3);

            //char
            char[] chars = new char[4];

            chars[0] = 'X';
            chars[1] = '\x0058';
            chars[2] = (char)88;
            chars[3] = '\u0058';

            foreach (char c in chars)
            {
                Console.WriteLine(c + " ");
            }

            //int,float,short,double
            int    x = 3;
            float  y = 4.5f;
            short  z = 5;
            double w = 1.7E+3;

            // Result of the 2nd argument is a double:
            Console.WriteLine("The sum is {0}", x + y + z + w);

            //enum
            // The bitwise OR of 0001 and 0100 is 0101.
            CarOptions options = CarOptions.SunRoof | CarOptions.FogLights;

            // Because the Flags attribute is specified, Console.WriteLine displays
            // the name of each enum element that corresponds to a flag that has
            // the value 1 in variable options.
            Console.WriteLine(options);
            // The integer value of 0101 is 5.
            Console.WriteLine((int)options);

            //int
            int intValue1 = 90_946;

            Console.WriteLine(intValue1);

            int intValue2 = 0x0001_6342;

            Console.WriteLine(intValue2);

            int intValue3 = 0b0001_0110_0011_0100_0010;

            Console.WriteLine(intValue3);

            int intValue4 = 0x_0001_6342;       // C# 7.2 onwards

            Console.WriteLine(intValue4);

            int intValue5 = 0b_0001_0110_0011_0100_0010;       // C# 7.2 onwards

            Console.WriteLine(intValue5);
            // The example displays the following output:
            //          90946
            //          90946
            //          90946
            //          90946
            //          90946
        }