/// <summary> /// Implemente uma classe Televisão que tenha métodos para ligar e /// desligar, aumentar ou diminuir o volume(com mínimo de 0 e máximo de 100) e /// subir ou baixar o canal(entre 1 e 83). /// </summary> public void Ex09_08_3() { Television television = new Television(); string op = ""; int s; while (op != "S") { Console.Clear(); Console.WriteLine("on or ON - Turn on the television."); Console.WriteLine("off or OFF - Turn off the television."); Console.WriteLine("ic or IC - Increase the channel."); Console.WriteLine("dc or DC - Decrease the channel."); Console.WriteLine("iv or IV - Increase the volume."); Console.WriteLine("dv or DV - Decrease the volume."); Console.WriteLine("s or S - Exit."); Console.WriteLine(); Console.WriteLine(television); Console.WriteLine(); Console.Write("Option: "); op = Console.ReadLine().ToUpper(); switch (op) { case "ON": television.TurnOn(); break; case "OFF": television.TurnOff(); break; case "IC": television.IncreaseChannel(); break; case "DC": television.DecreaseChannel(); break; case "IV": television.IncreaseVolume(); break; case "DV": television.DecreaseVolume(); break; case "S": break; default: Console.WriteLine("Invalid Option."); break; } } }
static void Main(string[] args) { //Creacion de Televsion y de Monitor en la Fabrica Fabrica <Television> f1 = new Fabrica <Television>(4); Fabrica <Monitor> f2 = new Fabrica <Monitor>(2); //Creacion de 4 Televisores Television t1 = new Television(1, 32, ECalidad.FullHD4K, EMarcaTel.Philips); Television t2 = new Television(2, 42, ECalidad.FullHD, EMarcaTel.LG); Television t3 = new Television(3, 32, ECalidad.FullHD8K, EMarcaTel.LG); Television t4 = new Television(4, 52, ECalidad.FullHD8K, EMarcaTel.Sony); //Creacion de 2 Monitores Monitor c1 = new Monitor(1, 20, ECalidad.FullHD, EMarcaMoni.ViewSonic); Monitor c2 = new Monitor(2, 18, ECalidad.FullHD8K, EMarcaMoni.Zowie); //YA INGRESADO //f1 += c1; f1 += t1; f1 += t2; f1 += t3; f2 += c2; //YA INGRESADO f1 += t4; f2 += c1; //SIN LUGAR f1 += t4; Console.WriteLine(f1.Mostrar()); Console.WriteLine(f2.Mostrar()); /*using (XmlTextWriter writer = new XmlTextWriter("DatosTelevisores.xml", Encoding.UTF8)) * { * //Creo un objeto que 'sabe' como serializar a XML * //Le tengo que indicar que tipo de objeto se va a serializar * XmlSerializer ser = new XmlSerializer(typeof(Fabrica<Television>)); * * //Utilizo el método Serialize, pasándole el 'escritor' de XML * //y el objeto a serializar * ser.Serialize(writer, f1); * } * * * using (XmlTextWriter writer = new XmlTextWriter("DatosMonitores.xml", Encoding.UTF8)) * { * //Creo un objeto que 'sabe' como serializar a XML * //Le tengo que indicar que tipo de objeto se va a serializar * XmlSerializer ser = new XmlSerializer(typeof(Fabrica<Monitor>)); * * //Utilizo el método Serialize, pasándole el 'escritor' de XML * //y el objeto a serializar * ser.Serialize(writer, f2); * } */ Console.ReadLine(); }
public void BeforeMoveingTest() { var target = new Television("TV", 1, 1); var expected = Power.Off; target.BeforeMoveing(); var actual = target.Power; Assert.AreEqual(expected, actual); }
public void MoveTest() { var target = new Television("TV", 1, 1); var expected = new Location(2, 2).ToString(); target.Move(2, 2); var actual = target.Location.ToString(); Assert.AreEqual(expected, actual); }
public void TestTVOff() { Device device = new Television(); Command command = new Off(device); DeviceButton button = new DeviceButton(command); button.press(); button.press(); Assert.AreEqual(device.status, Status.off); }
public static void Run() { // The TV's remote control is an ISignalling<Tuple<TVEvent, int>>, // and also an IObservable<Tuple<TVEvent, int>> (see Simulation 4 below): ISignalling<TVEvent, int> remote = new TVRemote(); // The TV is in fact an IMachine<TVState, TVStatus, TVEvent, int>, // here shortened to its base type IMachine<TVStatus> for simple enumeration purpose: IMachine<TVStatus> television = new Television(); // The state of the TV is in fact an IState<TVStatus, TVEvent, int>, // here shortened to its base type IState<TVStatus> for simple enumeration purpose: IState<TVStatus> state = new TVState(); // Enumerating over the IEnumerable<TVEvent> (SampleSimulation1), // which is the source of triggers for state transitions: Console.WriteLine("Simulation 1:"); foreach (TVStatus value in state.Using(SampleSimulation1).Start(TVStatus.Unplugged)) ;// not interested in doing anything special after each successful transition... // Enumerating over the IEnumerable<TVEvent> (SampleSimulation2), // which is the source of triggers for state transitions: Console.WriteLine("Simulation 2:"); foreach (TVStatus value in state.Using(SampleSimulation2).Start(TVStatus.Unplugged)) // Just echo the state that we transitioned TO on the console: Console.WriteLine("\t{0}", value); // Anti-pattern: // this coding style does work but isn't recommended: Console.WriteLine("Simulation 3:"); if (!state.Start(TVStatus.Unplugged).IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.Plug) && !state.IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.SwitchOn) && !state.IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.SwitchOff) && !state.IsFinal) { Console.WriteLine("\t... Done? {0}", state.IsFinal); if (state.Consume(TVEvent.Destroy) && !state.IsFinal) Console.WriteLine("(not executed)"); else Console.WriteLine("\t... Done? {0}", state.IsFinal); } } } } Console.WriteLine("Simulation 4:"); // Ensure we are back in the start state: state = television.Using(remote).Start(TVStatus.Unplugged); // Now use the various remote control's Emit signatures: remote.Emit(TVEvent.Plug); remote.Emit(TVEvent.SwitchOn, 1); remote.Emit(new Tuple<TVEvent, int>(TVEvent.SwitchOff, 2)); remote.Emit(new KeyValuePair<TVEvent, int>(TVEvent.Unplug, 3)); remote.Emit(TVEvent.Destroy, 4); }
public void TurnOnTV_ShouldSetProperties() { // Arrange Television television = new Television(); // Act television.TurnOn(); // Assert Assert.IsTrue(television.IsOn, "Hey, the television didn't turn on"); Assert.AreEqual(2, television.CurrentVolume); }
/// <summary>Rerieves an instance of Television for the specified key.</summary> /// <param name="key">A value that uniquely identifies the television.</param> /// <returns>Returns an instance of <see cref="Television"/>.</returns> public Television Find(Guid key) { var records = _eventStore.Read(key); var history = records.Select <EventRecord, EntityEventArgs>(record => record.EventData.FromBinary <EntityEventArgs>()); Television entity = new Television(key); foreach (var historicEvent in history) { entity.EntityState.Load(historicEvent); } return(entity); }
public void Shallow_Return_Top_Level_Copy() { var tv = GetTelevision(); Television tvClone = tv.Clone() as Television; Assert.NotNull(tvClone); Assert.Equal(tv.Quantity, tvClone.Quantity); Assert.Equal(tv.Worthiness, tvClone.Worthiness); Assert.Equal(tv.Stock.Name, tvClone.Stock.Name); Assert.Equal(tv.Stock.Manager.FirstName, tvClone.Stock.Manager.FirstName); }
static void Main(string[] args) { var electrodomestico = new Electrodomestico(); var lavadora = new Lavadora(); var television = new Television(); var objects = new ICommonPriceFunctions[] { electrodomestico, lavadora, television }; foreach (var ob in objects) { var finalPrice = ob.FinalPrice(); } Console.ReadLine(); }
public IActionResult Index() { Television television = new Television(); television.Name = "Martha"; television.SerialNumber = "J123DF4"; ViewData["ViewTelevision"] = television; TempData["TempTelevision"] = television; ViewBag.ViewBagTelevision = television; return(View()); }
public void DefaultTelevisionTest() { //Arrange your variables Television tv; //Act by performing the action you want to test tv = new Television(); //Assert by validating your expected outputs Assert.IsFalse(tv.IsOn); Assert.AreEqual(3, tv.CurrentChannel); Assert.AreEqual(2, tv.CurrentVolume); }
static void Main(string[] args) { var electrodomestico = new Electrodomestico(); var lavadora = new Lavadora(); var television = new Television(); var objects = new iSaveable[] { electrodomestico, lavadora, television }; foreach (var ob in objects) { ob.Save(); } Console.ReadLine(); }
public void WhenIChangeChannelAndTvIsOnThenChannelChanges() { //Arrange Television tv = new Television(); tv.TurnOn(); //Act tv.ChangeChannel(5); //Assert Assert.AreEqual(5, tv.CurrentChannel); }
public void Television_ChannelDownPast18Tests() { Type type = typeof(Television); Television tv = (Television)Activator.CreateInstance(type); type.GetMethod("TurnOn").Invoke(tv, null); type.GetMethod("ChangeChannel").Invoke(tv, new object[] { 4 }); type.GetMethod("ChannelDown").Invoke(tv, null); Assert.AreEqual(3, type.GetProperty("CurrentChannel").GetValue(tv), "ChannelDown should have incremented CurrentChannel by 1."); type.GetMethod("ChannelDown").Invoke(tv, null); Assert.AreEqual(18, type.GetProperty("CurrentChannel").GetValue(tv), "ChannelDown should not let CurrentChannel go past 3. Reset to 18."); }
public void WhenIChannelUpFrom18ItShouldBe3() { //Arrange Television tv = new Television(); tv.TurnOn(); tv.ChangeChannel(18); //Act tv.ChannelUp(); //Assert Assert.AreEqual(3, tv.CurrentChannel); }
public void SetChannelAbove18() { // Arrange Television tv = new Television(); tv.TurnOn(); int currentChannel = tv.CurrentChannel; // Act tv.ChangeChannel(19); // Assert Assert.AreEqual(currentChannel, tv.CurrentChannel); }
public void DoesATvTurnOnWhenITurnItOn() { //Arrange Television tv = new Television(); //Act tv.TurnOn(); //Assert //Assert.IsFalse(tv.IsOn); Assert.AreEqual(true, tv.IsOn); Assert.AreEqual(3, tv.CurrentChannel); Assert.AreEqual(2, tv.CurrentVolume); }
public void Television_Constructor() { Type type = typeof(Television); Television tv = (Television)Activator.CreateInstance(type); PropertyInfo prop = type.GetProperty("IsOn"); Assert.AreEqual(false, prop.GetValue(tv), "New TVs should be turned off by default."); prop = type.GetProperty("CurrentChannel"); Assert.AreEqual(3, prop.GetValue(tv), "New TVs should have the CurrentChannel set to 3 by default."); prop = type.GetProperty("CurrentVolume"); Assert.AreEqual(2, prop.GetValue(tv), "New TVs should have the CurrentVolume set to 2 by default."); }
public void ChannelUP_HappyPath() { // Arrange Television television = new Television(); int currentChannel; television.TurnOn(); currentChannel = television.CurrentChannel; // Act television.ChannelUp(); // Assert Assert.AreEqual(++currentChannel, television.CurrentChannel); }
public void ChangingChannelToNegative_ShouldLeaveChannelAsIs() { // Arrange - create a new tv and turn it on, store the current channel Television tv = new Television(); tv.TurnOn(); int oldChannel = tv.CurrentChannel; // Act - change the channel to -1 tv.ChangeChannel(-1); // Assert - make sure channel is still the original value. Assert.AreEqual(oldChannel, tv.CurrentChannel, "Changing the channel to -1 should have left the current channel alone."); }
public void TestVolumeDownTV() { int expected = 5; Device device = new Television(); Command command = new VolumeDown(device); DeviceButton button = new DeviceButton(command); for (int i = 0; i < 5; i++) { button.press(); } Assert.AreEqual(expected, device.volume); }
// Methods (Main Method) static void Main(string[] args) { Console.WriteLine("Hello World!"); //Console.Read(); int myFirstInteger; myFirstInteger = 10; Console.WriteLine(myFirstInteger); myFirstInteger = 20; Console.WriteLine(myFirstInteger); //const int myFirstConstantInteger = 10; //myFirstConstantInteger = 20; Television t = new Television(); t.Display(); Student student = new Student(); student.DepartmentId = 10; student.StudentId = 1; Console.WriteLine(student.TakeBook(10)); Student.AddCount(); Console.WriteLine(Student.GetCount()); Student student2 = new Student(); Student.AddCount(); student2.DepartmentId = 11; student2.StudentId = 2; Console.WriteLine(Student.GetCount()); //Console.WriteLine(student.) int number = 5; MyNumber myNumber = new MyNumber(number); if (myNumber.IsEven()) { Console.WriteLine("Even"); Console.WriteLine(myNumber.GetSignalColorPremium()); } else { Console.WriteLine("Odd"); } }
public static void Main() { ICommand command; IElectronicDevice device; DeviceButton button; device = new Television(); command = new TurnOn(device); button = new DeviceButton(command); button.Press(); command = new TurnOff(device); button = new DeviceButton(command); button.Press(); command = new TurnUp(device); button = new DeviceButton(command); button.Press(); button.Press(); button.Press(); command = new TurnDown(device); button = new DeviceButton(command); button.Press(); // ----------------------------------- device = new Radio(); command = new TurnOn(device); button = new DeviceButton(command); button.Press(); command = new TurnOff(device); button = new DeviceButton(command); button.Press(); command = new TurnUp(device); button = new DeviceButton(command); button.Press(); button.Press(); button.Press(); command = new TurnDown(device); button = new DeviceButton(command); button.Press(); }
public void Television_ChangeChannelTests() { Type type = typeof(Television); Television tv = (Television)Activator.CreateInstance(type); // Change Channel before Turning On type.GetMethod("ChangeChannel").Invoke(tv, new object[] { 5 }); Assert.AreEqual(3, type.GetProperty("CurrentChannel").GetValue(tv), "The TV was not turned on. CurrentChannel should not have changed."); // Turn it on and change it type.GetMethod("TurnOn").Invoke(tv, null); type.GetMethod("ChangeChannel").Invoke(tv, new object[] { 5 }); Assert.AreEqual(5, type.GetProperty("CurrentChannel").GetValue(tv), "The Channel was Changed to 5. CurrentChannel should now be 5."); }
public void Save(Television entity) { foreach (var eventArgs in entity.EntityState.Changes) { var change = (EntityEventArgs)eventArgs; var record = new EventRecord { EntityKey = entity.Key, EventKey = change.Key, Version = entity.EntityState.Version, SystemType = entity.GetType().AssemblyQualifiedName, EventData = change.ToBinary() }; _eventStore.Write(record); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { tvLivingRoom = new Television("leefkamer"); radioKitchen = new Radio("keuken"); lampHallway = new SmartLamp("gang"); electricalAppliances = new List <ElectricalAppliance> { tvLivingRoom, radioKitchen, lampHallway }; lblTVLivingRoomVolume.Content = tvLivingRoom.CurrentVolume; lblRadioKitchenVolume.Content = radioKitchen.CurrentVolume; }
public void Shallow_Modifies_Copy_If_Changed() { var tv = GetTelevision(); Television tvClone = tv.Clone() as Television; tvClone.Stock.Manager.LastName = "ModifiedLastName"; tv.Stock.Name = "ModifiedName"; tv.Quantity--; Assert.NotNull(tvClone); Assert.NotEqual(tv.Quantity, tvClone.Quantity); Assert.Equal(tv.Worthiness, tvClone.Worthiness); Assert.Equal(tv.Stock.Name, tvClone.Stock.Name); Assert.Equal(tv.Stock.Manager.FirstName, tvClone.Stock.Manager.FirstName); }
private static Television GetTelevision() { Television television = new Television(); television.Quantity = 120; television.Worthiness = 10; television.Stock = new Stock { Manager = new Employee { LastName = "TestManager", FirstName = "Test" }, Name = "TestStock" }; return(television); }
public static void Main() { ISwitchable light = new Light(); ISwitchable television = new Television(); ICommand lightOff = new OffSwitchCommand(light); ICommand lightOn = new OnSwitchCommand(light); ICommand tvOff = new OffSwitchCommand(television); ICommand tvOn = new OnSwitchCommand(television); lightOff.Execute(); tvOn.Execute(); lightOn.Execute(); tvOff.Execute(); }
static void Main() { Television tv = new Television(); if (tv.IsOn() == false) { tv.TurnOn(); } tv.ChangeChannel(3); tv.IncreaseVolume(); tv.IncreaseVolume(); tv.IncreaseVolume(); tv.IncreaseVolume(); tv.TurnOff(); }
public static void Main(string[] args) { // our application will need some reveiver object Television device = new Television(); // our application will need an invoker object, which // in turns relies on concrete command objects: ICommand on = new OnCommand(device); // command to switch device on ICommand off = new OffCommand(device); // command to switch device off ICommand up = new UpCommand(device); // command to turn volume up ICommand down = new DownCommand(device);// command to turn volume down // now we are ready to create our invoker object which // we should think of as some sort of application menu. RemoteControl menu = new RemoteControl(on, off, up, down); // client code is now able to access the invoker object menu.SwitchPowerOn(); menu.RaiseVolume(); menu.RaiseVolume(); menu.RaiseVolume(); menu.LowerVolume(); menu.SwitchPowerOff(); }
public void ShouldThrowOutofRangeExceptionTooLow() { var tv = new Television("", 10); tv.Volume = -1; }
public UpCommand(Television device) { _television = device; }
public DownCommand(Television device) { _television = device; }