コード例 #1
0
        public static void Main(string[] args)
        {
            CakeFactory  cakeFactory = new CakeFactory();
            CakeService  cakeService = new CakeService();
            int          num         = 0;
            IList <Cake> cakes       = cakeFactory.Cakes;
            string       choice;

            do
            {
                Console.WriteLine("enter your choice:\n1.Add Cake\n2.Delete Cake\n3.Update Cake\n4.Search Cake\n5.Display Cakes\nEnter your choice:");
                Console.WriteLine("===========================================================");
                Console.WriteLine();
                var input = Convert.ToInt32(Console.ReadLine());
                if (input == 1)
                {
                    Cake flavor = cakeService.AddCake(ref num, cakes);
                    cakeFactory.Cakes.Add(flavor);
                    Console.WriteLine("\nCake Added successfully\n");
                    cakeService.DisplayCakes(cakes);
                }
                else if (input == 3)
                {
                    cakeService.UpdateCake(cakes);
                }
                else if (input == 5)
                {
                    cakeService.DisplayCakes(cakes);
                }
                else if (input == 2)
                {
                    cakeService.DeleteCake(cakes);
                }
                else if (input == 4)
                {
                    cakeService.SearchCake(cakes);
                }
                else
                {
                    Console.WriteLine("select the correct option");
                }
                Console.WriteLine("\n===========================================================");
                Console.WriteLine();
                Console.WriteLine("if u want to continue press yes");
                choice = Console.ReadLine();
            } while (string.Compare(choice, "yes", true) == 0);
            Console.ReadLine();
        }
コード例 #2
0
        public async Task DeleteCake_WithInvalidId_ShouldDoNoting()
        {
            //Arange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var repo = new Repository <Product>(db);

            var cakeService = new CakeService(null, repo, this.Mapper);

            EditAndDeleteViewModel cake = null;

            //Act

            //Assert
            await Assert.ThrowsAsync <NullReferenceException>(async() => await cakeService.DeleteCake(cake));
        }
コード例 #3
0
        public async Task DeleteCake_WithValidId_ShouldDeleteProduct()
        {
            //Arange
            var db = this.SetDb();

            await this.SeedProducts(db);

            var repo = new Repository <Product>(db);

            var cakeService = new CakeService(null, repo, this.Mapper);

            var cake = await cakeService.GetCakeById(1);

            //Act
            await cakeService.DeleteCake(cake);

            var actualProductsCount = repo.All().Where(p => p.IsDeleted == true).Count();;

            var expectedProductsCount = 1;

            //Assert
            Assert.Equal(expectedProductsCount, actualProductsCount);
        }