/// <summary> /// Map DBSize => Size /// Uses enum to determine which size class to return. /// </summary> /// <param name="entity"></param> /// <returns></returns> public ASize Map(DBSize entity) { ASize size = null; switch (entity.SIZE) { case SIZES.SMALL: size = new SmallSize(); break; case SIZES.MEDIUM: size = new MediumSize(); break; case SIZES.LARGE: size = new LargeSize(); break; default: throw new ArgumentException("Size not recognized. Size could not be mapped properly"); } size.ID = entity.ID; return(size); }
/// <summary> /// Initializes a new instance of the <see cref="Service"/> class with default values /// </summary> public Service() { serviceSize = new SmallSize(); serviceBulkRate = new FlatBulkRate(); serviceType = new WritingService(); numberOfProducts = 1; }
public void Test_SmallSizeName() { // arrange var sut = new SmallSize(); // act var actual = sut.Name; // assert Assert.Equal(actual, "Small Size"); }
public void Test_SmallSizePrice() { // arrange var sut = new SmallSize(); // act var actual = sut.Price; // assert Assert.Equal(actual, 3.0m); }
public void Test_SizeEnum() { // arrange var sut = new SmallSize(); // act var actual = sut.SIZE; // assert Assert.True(actual == SIZES.SMALL); }
public void Test_StorePrice() { // arrange var sut = new SmallSize(); // act var actual = sut.Price; // assert Assert.True(actual == 3m); }
public void Test_SizeName() { // arrange var sut = new SmallSize(); // act var actual = sut.Name; // assert Assert.True(actual == "Small"); }
public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE) { APizza pizza; ASize size; switch (SIZE) { case SIZES.SMALL: size = new SmallSize(); break; case SIZES.MEDIUM: size = new MediumSize(); break; case SIZES.LARGE: size = new LargeSize(); break; default: return(StatusCode(400, "Size not recognized")); } switch (PIZZA) { case PIZZAS.MEAT: pizza = new MeatPizza(size); break; case PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(size); break; case PIZZAS.VEGAN: pizza = new VeganPizza(size); break; case PIZZAS.CUSTOM: return(StatusCode(400, "You entered a custom pizza without providing the crust or toppings")); default: return(StatusCode(400, "Size not recognized")); } pizza.CalculatePrice(); return(Ok(pizza)); }
public override void AddSize() { Size = new SmallSize(); }
public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE, CRUSTS CRUST, [FromQuery] List <TOPPINGS> TOPPING) { APizza pizza; ASize size; ACrust crust; List <ATopping> toppings = new List <ATopping>(); switch (SIZE) { case SIZES.SMALL: size = new SmallSize(); break; case SIZES.MEDIUM: size = new MediumSize(); break; case SIZES.LARGE: size = new LargeSize(); break; default: return(StatusCode(400, "Size not recognized")); } switch (CRUST) { case CRUSTS.DEEPDISH: crust = new DeepDishCrust(); break; case CRUSTS.STANDARD: crust = new StandardCrust(); break; case CRUSTS.STUFFED: crust = new StuffedCrust(); break; case CRUSTS.THIN: crust = new ThinCrust(); break; default: return(StatusCode(400, "Crust not recognized")); } foreach (TOPPINGS toppingEnum in TOPPING) { switch (toppingEnum) { case TOPPINGS.BACON: toppings.Add(new Bacon()); break; case TOPPINGS.CHICKEN: toppings.Add(new Chicken()); break; case TOPPINGS.EXTRACHEESE: toppings.Add(new ExtraCheese()); break; case TOPPINGS.GREENPEPPER: toppings.Add(new GreenPepper()); break; case TOPPINGS.HAM: toppings.Add(new Ham()); break; case TOPPINGS.NOCHEESE: toppings.Add(new NoCheese()); break; case TOPPINGS.PINEAPPLE: toppings.Add(new Pineapple()); break; case TOPPINGS.REDPEPPER: toppings.Add(new RedPepper()); break; case TOPPINGS.SAUSAGE: toppings.Add(new Sausage()); break; default: return(StatusCode(400, "Topping not recognized")); } } pizza = new APizza { PIZZA = PIZZA, Name = Enum.GetName <PIZZAS>(PIZZA), Crust = crust, Toppings = toppings }; switch (PIZZA) { case PIZZAS.MEAT: pizza = new MeatPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.HAWAIIAN: pizza = new HawaiianPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.VEGAN: pizza = new VeganPizza(size); pizza.Crust = crust; pizza.Toppings = toppings; break; case PIZZAS.CUSTOM: pizza = new CustomPizza(crust, size, toppings); break; default: return(StatusCode(400, "Size not recognized")); } pizza.CalculatePrice(); return(Ok(pizza)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { NameLabel.Content = FileName; LoadingBar.Maximum = FileSize; SmallSize = SetSmallSize(FileSize); BytesLabel.Content = "0 / " + SmallSize.ToString("0.00") + PostSize; Connection.SendMessage(new MessageClass(Connection.ID, UserID, Commands.FileOK, ID)); LastTime = DateTime.Now; LastNow = 0; Task.Run(() => { Dispatcher.Invoke(() => { var opacityAnim = new DoubleAnimation(); opacityAnim.From = 0; opacityAnim.To = 1; opacityAnim.Duration = TimeSpan.FromSeconds(2); opacityAnim.RepeatBehavior = RepeatBehavior.Forever; Circle1.BeginAnimation(System.Windows.Shapes.Ellipse.OpacityProperty, opacityAnim); var circleAnim = new DoubleAnimation(); circleAnim.From = 80; circleAnim.To = 20; circleAnim.Duration = TimeSpan.FromSeconds(2); circleAnim.RepeatBehavior = RepeatBehavior.Forever; Circle1.BeginAnimation(System.Windows.Shapes.Ellipse.WidthProperty, circleAnim); Circle1.BeginAnimation(System.Windows.Shapes.Ellipse.HeightProperty, circleAnim); }); Thread.Sleep(670); Dispatcher.Invoke(() => { var opacityAnim = new DoubleAnimation(); opacityAnim.From = 0; opacityAnim.To = 1; opacityAnim.Duration = TimeSpan.FromSeconds(2); opacityAnim.RepeatBehavior = RepeatBehavior.Forever; Circle2.BeginAnimation(System.Windows.Shapes.Ellipse.OpacityProperty, opacityAnim); var circleAnim = new DoubleAnimation(); circleAnim.From = 80; circleAnim.To = 20; circleAnim.Duration = TimeSpan.FromSeconds(2); circleAnim.RepeatBehavior = RepeatBehavior.Forever; Circle2.BeginAnimation(System.Windows.Shapes.Ellipse.WidthProperty, circleAnim); Circle2.BeginAnimation(System.Windows.Shapes.Ellipse.HeightProperty, circleAnim); }); Thread.Sleep(670); Dispatcher.Invoke(() => { var opacityAnim = new DoubleAnimation(); opacityAnim.From = 0; opacityAnim.To = 1; opacityAnim.Duration = TimeSpan.FromSeconds(2); opacityAnim.RepeatBehavior = RepeatBehavior.Forever; Circle3.BeginAnimation(System.Windows.Shapes.Ellipse.OpacityProperty, opacityAnim); var circleAnim = new DoubleAnimation(); circleAnim.From = 80; circleAnim.To = 20; circleAnim.Duration = TimeSpan.FromSeconds(2); circleAnim.RepeatBehavior = RepeatBehavior.Forever; Circle3.BeginAnimation(System.Windows.Shapes.Ellipse.WidthProperty, circleAnim); Circle3.BeginAnimation(System.Windows.Shapes.Ellipse.HeightProperty, circleAnim); }); /* * while (true) * { * try * { * Dispatcher.Invoke(() => Circle1.Width -= 1); * Dispatcher.Invoke(() => Circle1.Height -= 1); * Dispatcher.Invoke(() => Circle1.Opacity += 0.017); * if (Dispatcher.Invoke(() => Circle1.Opacity >= 1)) * { * Dispatcher.Invoke(() => Circle1.Width = 79); * Dispatcher.Invoke(() => Circle1.Height = 79); * Dispatcher.Invoke(() => Circle1.Opacity = 0); * } * Dispatcher.Invoke(() => Circle2.Width -= 1); * Dispatcher.Invoke(() => Circle2.Height -= 1); * Dispatcher.Invoke(() => Circle2.Opacity += 0.017); * if (Dispatcher.Invoke(() => Circle2.Opacity >= 1)) * { * Dispatcher.Invoke(() => Circle2.Width = 79); * Dispatcher.Invoke(() => Circle2.Height = 79); * Dispatcher.Invoke(() => Circle2.Opacity = 0); * } * Dispatcher.Invoke(() => Circle3.Width -= 1); * Dispatcher.Invoke(() => Circle3.Height -= 1); * Dispatcher.Invoke(() => Circle3.Opacity += 0.017); * if (Dispatcher.Invoke(() => Circle3.Opacity >= 1)) * { * Dispatcher.Invoke(() => Circle3.Width = 79); * Dispatcher.Invoke(() => Circle3.Height = 79); * Dispatcher.Invoke(() => Circle3.Opacity = 0); * } * * Thread.Sleep(36); * } * catch * { * break; * } * }*/ }); }
public void SetData(byte[] data) { while (true) { try { using (var fs = new FileStream(Settings.PathToSave + FileName, FileMode.OpenOrCreate, FileAccess.Write)) { fs.Seek(0, SeekOrigin.End); fs.Write(data, 0, data.Length); } Connection.SendMessage(new MessageClass(Connection.ID, UserID, Commands.FileOK, ID)); if ((DateTime.Now - LastTime).TotalSeconds >= 1) { SpeedLabel.Content = (LastNow / (DateTime.Now - LastTime).TotalSeconds / 1024 / 1024).ToString("0.00") + "MB/s"; LastTime = DateTime.Now; LastNow = 0; } LoadingBar.Value += data.Length; NowSize += data.Length; LastNow += data.Length; BytesLabel.Content = GetSmallSize(NowSize).ToString("0.00") + " / " + SmallSize.ToString("0.00") + PostSize; break; } catch { } } }
static void Main(string[] args) { //system enums //initializing a WeekDay with a value of Sunday value won't work Console.WriteLine("System enum examples"); Console.WriteLine( $"Initialize {nameof(WeekDay)} with {nameof(DayOfWeek.Sunday)} shouldn't be possible'"); try { var s = new WeekDay(DayOfWeek.Sunday); Console.WriteLine("FAIL"); } catch { Console.WriteLine("OK"); } //mondays will always be mondays (sorry...) Console.WriteLine(); Console.WriteLine( $"A {nameof(WeekDay)} with value {nameof(DayOfWeek.Monday)} should equal {nameof(DayOfWeek)} with value {nameof(DayOfWeek.Monday)}"); var monday = new WeekDay(DayOfWeek.Monday); Console.WriteLine(monday == DayOfWeek.Monday ? "OK" : "FAIL"); //compare var friday = new WeekDay(DayOfWeek.Friday); Console.WriteLine(); Console.WriteLine("Compare: less than"); Console.WriteLine($"{monday} < {nameof(WeekDay)}.{DayOfWeek.Friday} = {monday < friday}"); Console.WriteLine($"{monday} < {nameof(DayOfWeek)}.{DayOfWeek.Friday} = {monday < DayOfWeek.Friday}"); Console.WriteLine($"{friday} < {nameof(WeekDay)}.{DayOfWeek.Monday} = {friday < monday}"); Console.WriteLine($"{friday} < {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {friday < DayOfWeek.Monday}"); Console.WriteLine($"{monday} < {nameof(WeekDay)}.{DayOfWeek.Monday} = {monday < monday}"); Console.WriteLine($"{monday} < {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {monday < DayOfWeek.Monday}"); Console.WriteLine(); Console.WriteLine("Compare: greater than"); Console.WriteLine($"{monday} > {nameof(WeekDay)}.{DayOfWeek.Friday} = {monday > friday}"); Console.WriteLine($"{monday} > {nameof(DayOfWeek)}.{DayOfWeek.Friday} = {monday > DayOfWeek.Friday}"); Console.WriteLine($"{friday} > {nameof(WeekDay)}.{DayOfWeek.Monday} = {friday > monday}"); Console.WriteLine($"{friday} > {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {friday > DayOfWeek.Monday}"); Console.WriteLine($"{monday} > {nameof(WeekDay)}.{DayOfWeek.Monday} = {monday > monday}"); Console.WriteLine($"{monday} > {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {monday > DayOfWeek.Monday}"); Console.WriteLine(); Console.WriteLine("Compare: less than or equal"); Console.WriteLine($"{monday} <= {nameof(WeekDay)}.{DayOfWeek.Friday} = {monday <= friday}"); Console.WriteLine($"{monday} <= {nameof(DayOfWeek)}.{DayOfWeek.Friday} = {monday <= DayOfWeek.Friday}"); Console.WriteLine($"{friday} <= {nameof(WeekDay)}.{DayOfWeek.Monday} = {friday <= monday}"); Console.WriteLine($"{friday} <= {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {friday <= DayOfWeek.Monday}"); Console.WriteLine($"{monday} <= {nameof(WeekDay)}.{DayOfWeek.Monday} = {monday <= monday}"); Console.WriteLine($"{monday} <= {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {monday <= DayOfWeek.Monday}"); Console.WriteLine(); Console.WriteLine("Compare: greater than or equal"); Console.WriteLine($"{monday} >= {nameof(WeekDay)}.{DayOfWeek.Friday} = {monday >= friday}"); Console.WriteLine($"{monday} >= {nameof(DayOfWeek)}.{DayOfWeek.Friday} = {monday >= DayOfWeek.Friday}"); Console.WriteLine($"{friday} >= {nameof(WeekDay)}.{DayOfWeek.Monday} = {friday >= monday}"); Console.WriteLine($"{friday} >= {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {friday >= DayOfWeek.Monday}"); Console.WriteLine($"{monday} >= {nameof(WeekDay)}.{DayOfWeek.Monday} = {monday >= monday}"); Console.WriteLine($"{monday} >= {nameof(DayOfWeek)}.{DayOfWeek.Monday} = {monday >= DayOfWeek.Monday}"); //custom enums //initializing with an invalid enum value won't work Console.WriteLine(); Console.WriteLine("Custom enum examples"); Console.WriteLine( $"Initialize {nameof(SmallSize)} with {nameof(Size.Value.Large)} shouldn't be possible'"); try { var s = new SmallSize(Size.Value.Large); Console.WriteLine("FAIL"); } catch { Console.WriteLine("OK"); } var xSmall = new SmallSize(Size.Value.ExtraSmall); Console.WriteLine(); Console.WriteLine($"{nameof(SmallSize)} with value {nameof(Size.Value.ExtraSmall)} ToString:"); Console.WriteLine(xSmall); //cast object to underlying enum representation Console.WriteLine(); Console.WriteLine($"Cast {nameof(SmallSize)} to {nameof(Size.Value)}"); Console.WriteLine($"{(Size.Value)xSmall} = {(Size.Value)xSmall}"); //cast object to integer representation Console.WriteLine(); Console.WriteLine($"Cast {nameof(SmallSize)} to int"); Console.WriteLine($"{xSmall} = {(int)xSmall}"); //compare object against underlying enum value in a switch Console.WriteLine(); Console.WriteLine($"Switch {nameof(SmallSize)} comparing to {nameof(Size.Value)}"); switch ((Size.Value)xSmall) { case Size.Value.ExtraSmall: Console.WriteLine("OK"); break; default: Console.WriteLine("FAIL"); break; } //compare object against underlying int value in a switch Console.WriteLine(); Console.WriteLine($"Switch {nameof(SmallSize)} comparing to int"); switch ((int)xSmall) { case (int)Size.Value.ExtraSmall: Console.WriteLine("OK"); break; default: Console.WriteLine("FAIL"); break; } //comparing two objects with the same underlying enum, //and no inheritance relation between the types var realSmall = new SmallSize(Size.Value.Small); var anySmall = new AnySize(Size.Value.Small); Console.WriteLine(); Console.WriteLine($"{nameof(realSmall)} does not equal {nameof(anySmall)} (2 tests)"); Console.WriteLine(realSmall != anySmall ? "OK" : "FAIL"); Console.WriteLine(anySmall != realSmall ? "OK" : "FAIL"); //comparing two objects with the same underlying enum, //and derived types var basicSmall = new BasicSize(Size.Value.Small); var extendedSmall = new ExtendedSize(Size.Value.Small); Console.WriteLine(); Console.WriteLine($"{nameof(basicSmall)} equals {nameof(extendedSmall)} (2 tests)"); Console.WriteLine(basicSmall == extendedSmall ? "OK" : "FAIL"); Console.WriteLine(extendedSmall == basicSmall ? "OK" : "FAIL"); }