static void Main(string[] args) { Bike bike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); bs.AddBike(bike); bs.UpdateBike(bike, "Ny description!", 5.0M); Bike updatedBike = new Bike(2, "TestBike", "TestFirma", "Gul", 5.0M, "Ny description!"); if (bs.BikeDict.ContainsKey(bike)) { Console.WriteLine("no"); } else { Console.WriteLine("yes"); } bs.OrderBikesFromStorage(bike, 10); Console.Read(); }
public static void Run() { Console.WriteLine($"{Environment.NewLine}*** PUBLISH SUBSCRIBE PATTERN ***{Environment.NewLine}"); // Make a bike shop IBikeShop shop = new BikeShop("Mountain Bike Guys"); BikeCustomer customerOne = new BikeCustomer(shop, "Tom"); BikeCustomer customerTwo = new BikeCustomer(shop, "Dick"); BikeCustomer customerThree = new BikeCustomer(shop, "Harry"); shop.NewBikeArrived("Road Runner"); shop.NewBikeArrived("GT"); customerOne.UnsubscribeFromNewBikeNotifications(); customerTwo.UnsubscribeFromNewBikeNotifications(); shop.NewBikeArrived("Rocket"); // We don't need to ubsubscribe the last customer (or any of them really) // because they have the same scope as the object they subscribe to. // Memory leaks only occur when objects the sunscriber object is disposed // but's it's subscribtion in the subscribed object last on. // This is a design problem and should be solved at design time. }
public async Task <ActionResult <BikeShop> > PostBikeShop(BikeShop bikeShop) { _context.BikeShops.Add(bikeShop); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBikeShop", new { id = bikeShop.Id }, bikeShop)); }
public async Task <IActionResult> PutBikeShop(int id, BikeShop bikeShop) { if (id != bikeShop.Id) { return(BadRequest()); } _context.Entry(bikeShop).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BikeShopExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CreateBikeTest() { Bike bike = new Bike(2, "HurtigDrengen", "Lynet", "Gul", 19999.99M, "En meget hurtig cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); bs.AddBike(bike); Assert.That(bs.BikeDict.ContainsKey(bike)); }
public void ReadBikeTest() { Bike bike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); bs.AddBike(bike); Assert.That(bs.BikeDict.ContainsKey(bike)); Assert.NotNull(bs.LookAtBike(bike)); }
public void DeleteBikeTest() { Bike bike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); bs.AddBike(bike); Assert.That(bs.BikeDict.ContainsKey(bike)); bs.RemoveBikeFromInventory(bike); Assert.False(bs.BikeDict.ContainsKey(bike)); }
public void BikeShop_Build_BuildsBikes() { // Arrange BikeShop shop = new BikeShop(); Mock <BikeBuilder> mockBuilder = new Mock <BikeBuilder>(); // Act shop.Build(mockBuilder.Object); // Assert mockBuilder.Verify(m => m.AddBrakes(), Times.Once); mockBuilder.Verify(m => m.AddFrame(), Times.Once); mockBuilder.Verify(m => m.AddWheels(), Times.Once); }
public void UpdateBikeTest() { Bike bike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); Bike originalBike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); bs.AddBike(bike); Assert.That(bs.BikeDict.ContainsKey(bike)); bs.UpdateBike(bike, "Ny description!", 5.0M); Assert.That(bs.BikeDict.ContainsKey(bike)); Assert.False(bs.BikeDict.ContainsKey(originalBike)); }
public void FjernlagerOrderTest() { Bike bike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); Fjernlager.AddToStock(bike, 10); Assert.False(bs.BikeDict.ContainsKey(bike)); bs.OrderBikesFromStorage(bike, 10); Assert.That(bs.BikeDict.ContainsKey(bike)); Assert.AreEqual(10, bs.BikeDict[bike]); }
public void PaintRobot_DoWork_ChangesBikeColour() { // Arrange BikeShop shop = new BikeShop(); IBike testBike = new MountainBike("Test"); ConsoleColor originalColour = testBike.Colour; shop.Attach(testBike); // Act shop.AcceptVisitor(new PainterRobot()); // Assert - This could fail if it randomly chooses the original colour again Assert.IsFalse(testBike.Colour == originalColour); }
public void TirePumpRobot_DoWork_ChangesTirePressure() { // Arrange BikeShop shop = new BikeShop(); IBike testBike = new MountainBike("Test"); int originalTirePressure = testBike.TirePressure; shop.Attach(testBike); // Act shop.AcceptVisitor(new TirePumpRobot()); // Assert Assert.IsFalse(testBike.TirePressure == originalTirePressure); }
public static void Run() { Console.WriteLine($"{Environment.NewLine}*** BUILDER PATTERN ***{Environment.NewLine}"); BikeBuilder mBuilder = new MountainBikeBuilder(); BikeBuilder rBuilder = new RoadBikeBuilder(); BikeShop shop = new BikeShop(); shop.Build(mBuilder); mBuilder.Bike.DescribeBike(); shop.Build(rBuilder); rBuilder.Bike.DescribeBike(); }
public static void Run() { Console.WriteLine($"{Environment.NewLine}*** VISITOR PATTERN ***{Environment.NewLine}"); BikeShop shop = new BikeShop(); shop.Attach(new MountainBike("Rocky")); shop.Attach(new RoadBike("Speedy")); shop.Attach(new HybridBike("Rover")); shop.DisplayBikes(); shop.AcceptVisitor(new TirePumpRobot()); shop.AcceptVisitor(new PainterRobot()); shop.DisplayBikes(); }
public void BikeShop_NewBikeEventRaised_SubscriberIsCalled() { // Arrange IBikeShop shop = new BikeShop("Shop"); BikeCustomer customerOne = new BikeCustomer(shop, "Customer"); using (StringWriter writer = new StringWriter()) { // Capture the console output Console.SetOut(writer); // Act shop.NewBikeArrived("Rocket"); // Assert Assert.IsTrue(writer.ToString().Contains("Rocket")); } }
public void SellBikeTest() { Bike bike = new Bike(2, "TestBike", "TestFirma", "Gul", 19999.99M, "En test cykel!"); BikeShop bs = new BikeShop("TestShop", "TestArea", 0000); bs.AddBike(bike); Assert.That(bs.BikeDict.ContainsKey(bike)); bs.SellBike(bike); Assert.AreEqual(0, bs.BikeDict[bike]); Assert.AreEqual(bike.Price, bs.Earnings); int quantity = 100; bs.AddBike(bike, quantity); bs.SellBike(bike); Assert.AreEqual(quantity - 1, bs.BikeDict[bike]); Assert.AreEqual(bike.Price * 2, bs.Earnings); }
public BikeTask(BikeShop bikeShop, CityTaskController controller) { this.bikeShop = bikeShop; taskController = controller; }