Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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]);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
        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();
        }
Exemplo n.º 15
0
        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"));
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
 public BikeTask(BikeShop bikeShop, CityTaskController controller)
 {
     this.bikeShop  = bikeShop;
     taskController = controller;
 }