Ejemplo n.º 1
0
        public async Task GetToppings_Returns_Ok()
        {
            Guid itemId      = Guid.NewGuid();
            var  toppingData = new Topping()
            {
                ItemId = itemId, Name = "Onion", Price = 12, ItemType = ItemType.Topping
            };
            var toppingList = new List <Topping> {
                toppingData
            };

            MockToppingManager.Setup(x => x.GetAllAsync(ItemType.Topping)).ReturnsAsync(new ApiResponse <List <Topping> >
            {
                Result = new ApiResult <List <Topping> > {
                    Data = toppingList
                }
            });

            var result = await itemsController.GetByType(TOPPING) as ObjectResult;

            Assert.NotNull(result.Value);
            Assert.AreEqual(HttpStatusCode.OK, (HttpStatusCode)result.StatusCode);

            ApiResponse <List <Topping> > getAllToppings = result.Value as ApiResponse <List <Topping> >;

            Assert.IsNotNull(getAllToppings.Result.Data);
            Assert.IsNull(getAllToppings.Result.ErrorInfo);

            List <Topping> toppings = getAllToppings.Result.Data;
            var            topping  = toppings.FirstOrDefault();

            Assert.AreEqual(toppingData.ItemId, topping.ItemId);
            Assert.AreEqual(toppingData.Name, topping.Name);
            Assert.AreEqual(toppingData.Price, topping.Price);
            Assert.AreEqual(toppingData.ItemType, topping.ItemType);
        }