Esempio n. 1
0
        public void initialise()
        {
            _mockRepository = new Mock <IDrinksRepository>();

            var mockUoW = new Mock <IUnitOfWork>();

            mockUoW.SetupGet(d => d.Drinks).Returns(_mockRepository.Object);

            _controller = new DrinksController(mockUoW.Object);
        }
Esempio n. 2
0
        public async Task TestGetDrinksAsync()
        {
            var mockRepo = new Mock <IRepositoryWrapper>();

            mockRepo.Setup(repo => repo.Drinks.GetAll())
            .ReturnsAsync(_fakeData.GetFakeDrinks());

            var controller = new DrinksController(mockRepo.Object);

            var drinks = await controller.GetDrinks();

            Assert.Equal(2, drinks.Count());
        }
Esempio n. 3
0
        public void Setup()
        {
            mockUnitOfWork = Substitute.For <IUnitOfWork>();

            var profile       = new MappingProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(profile));

            mapper = new Mapper(configuration);

            uut = new DrinksController(mockUnitOfWork, mapper);

            defaultList = new List <Drink>()
            {
                new Drink()
                {
                    BarName    = "TestBar",
                    DrinksName = "Øl",
                    Image      = "øl.jpg",
                    Price      = 12,
                    Bar        = null,
                },
                new Drink()
                {
                    BarName    = "TestBar",
                    DrinksName = "Fadøl",
                    Image      = "fadøl.jpg",
                    Price      = 20,
                    Bar        = null,
                }
            };
            defaultDrink = defaultList[0];

            // Direct conversion without navigational property
            correctResultList = new List <DrinkDto>()
            {
                new DrinkDto()
                {
                    BarName    = "TestBar",
                    DrinksName = "Øl",
                    Image      = "øl.jpg",
                    Price      = 12,
                },
                new DrinkDto()
                {
                    BarName    = "TestBar",
                    DrinksName = "Fadøl",
                    Image      = "fadøl.jpg",
                    Price      = 20,
                }
            };
        }
Esempio n. 4
0
        public void GetByIdLocation()
        {
            //Define the mock data
            var data = new List <Location>
            {
                new Location {
                    id          = 1, gogId = "ChIJ_w0bJLzUf0cRy_s3-sYl0UU", address = "Via Zamboni, 16/d, 40126 Bologna, Italia", telephone = "051 1889 9835", description = null,
                    geolocation = "(44.495439, 11.348128999999972)", name = "Lab16", openingHours = "Lunedì: 07:00–03:00 | Martedì: 07:00–03:00 | Mercoledì: 07:00–03:00 | Giovedì: 07:00–03:00 | Venerdì: 07:00–03:00 | Sabato: 17:30–03:30 | Domenica: 17:30–03:30",
                    rating      = 4.4F, website = "http://www.lab16.it/", url = "https://plus.google.com/108077084127565302676/about?hl=it-IT", drinks = new List <Drink> {
                        new Drink {
                            id = 4, description = "Drink1", name = "Drink1", price = 5.00M
                        },
                        new Drink {
                            id = 5, description = "Drink2", name = "Drink2", price = 3.50M
                        },
                        new Drink {
                            id = 6, description = "Drink3", name = "Drink3", price = 4.00M
                        }
                    }
                }
            }.AsQueryable();


            //Define the mock type as DbSet<Location>
            var mockSet = new Mock <DbSet <Location> >();
            //Define the mock Repository as databaseEf
            var mockContext = new Mock <databaseEF>();


            //Bind all data  attributes to your mockSe

            mockSet.As <IQueryable <Location> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Location> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Location> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Location> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            //Setting up the mockSet to mockContext
            mockContext.Setup(c => c.locations).Returns(mockSet.Object);

            //Init the WebAPI service
            var service = new DrinksController(mockContext.Object);

            //Check the equality between the returned data and the expected data
            Assert.AreEqual("Drink1", service.GetByLocId(data.First().id).First().name);
        }
Esempio n. 5
0
 public void Setup()
 {
     _twilioBaristaContextMock = new Mock <TwilioBaristaContext>();
     _repositoryMock           = new Mock <DrinkRepository>(_twilioBaristaContextMock.Object);
     _controller = new DrinksController(_repositoryMock.Object);
 }
Esempio n. 6
0
 public void SetUp()
 {
     drinkRepository = Substitute.For <IRepository <Drink, string> >();
     controller      = new DrinksController(drinkRepository);
 }