Ejemplo n.º 1
0
        public void Get_Empty()
        {
            var restaurantServiceMock = new Mock <IRestaurantService>();

            restaurantServiceMock.Setup(rs => rs.GetByOutCodeAsync(It.IsAny <string>()))
            .Returns(Task.FromResult((IEnumerable <IRestaurant>) new List <IRestaurant>()));

            var restaurantApiController = new RestaurantsApiController(restaurantServiceMock.Object);

            Assert.AreEqual(0, restaurantApiController.Get("foo").Result.Count());
        }
Ejemplo n.º 2
0
        public void Get_MissingParameterTest()
        {
            var restaurantServiceMock = new Mock <IRestaurantService>();

            restaurantServiceMock.Setup(rs => rs.GetByOutCodeAsync(It.IsAny <string>())).Throws(new Exception("shouldn't even call me"));

            var restaurantApiController = new RestaurantsApiController(restaurantServiceMock.Object);

            try
            {
                restaurantApiController.Get(string.Empty).Wait();
            }
            catch (AggregateException ae)
            {
                throw ae.InnerExceptions.First();
            }
        }
Ejemplo n.º 3
0
        public void Get_DistinctCusine()
        {
            var restaurant1 = Mock.Of <IRestaurant>(r => r.Id == 1 && r.Name == "L'Entrecote" && r.Rating == 4.9m &&
                                                    r.CusineTypes == new string[] { "French", "parisian", "french" });

            var restaurantServiceMock = new Mock <IRestaurantService>();

            restaurantServiceMock.Setup(rs => rs.GetByOutCodeAsync(It.IsAny <string>()))
            .Returns(Task.FromResult((IEnumerable <IRestaurant>) new List <IRestaurant>()
            {
                restaurant1
            }));

            var restaurantApiController = new RestaurantsApiController(restaurantServiceMock.Object);
            var restaurants             = restaurantApiController.Get("foo").Result;

            Assert.AreEqual(2, restaurants.Single().CusineTypes.Count());
            Assert.AreEqual(1, restaurants.Single().CusineTypes.Count(c => "french".Equals(c, StringComparison.InvariantCultureIgnoreCase)));
            Assert.AreEqual(1, restaurants.Single().CusineTypes.Count(c => "parisian".Equals(c, StringComparison.InvariantCultureIgnoreCase)));
        }
Ejemplo n.º 4
0
        public void Get_Distinct()
        {
            var restaurant1 = Mock.Of <IRestaurant>(r => r.Id == 1 && r.Name == "Pepe tapas" && r.Rating == 4.9m &&
                                                    r.CusineTypes == new string[] { "spanish", "andalusian" });
            var restaurant2 = Mock.Of <IRestaurant>(r => r.Id == 2 && r.Name == "Juan kitchen" && r.Rating == 0.0m);

            var restaurantServiceMock = new Mock <IRestaurantService>();

            restaurantServiceMock.Setup(rs => rs.GetByOutCodeAsync(It.IsAny <string>()))
            .Returns(Task.FromResult((IEnumerable <IRestaurant>) new List <IRestaurant>()
            {
                restaurant1, restaurant2, restaurant1
            }));

            var restaurantApiController = new RestaurantsApiController(restaurantServiceMock.Object);
            var restaurants             = restaurantApiController.Get("foo").Result;

            Assert.AreEqual(2, restaurants.Count());

            AssertRestaurantEquals(restaurant1, restaurants.Single(r => r.Id == 1));
            AssertRestaurantEquals(restaurant2, restaurants.Single(r => r.Id == 2));
        }