예제 #1
0
        public async Task GetFavoriteVendors_ReturnVendors()
        {
            //arrange

            Favorite fav1 = new Favorite()
            {
                userName = "******", vendorId = 0
            };
            Favorite fav2 = new Favorite()
            {
                userName = "******", vendorId = 1
            };
            Favorite fav3 = new Favorite()
            {
                userName = "******", vendorId = 2
            };
            var favorites = new List <Favorite> {
                fav1, fav2, fav3
            };

            Vendor v1 = new Vendor()
            {
                id = 0, userName = "******", name = "name0", website = "website_0"
            };
            Vendor v2 = new Vendor()
            {
                id = 1, userName = "******", name = "name1", website = "website_1"
            };
            Vendor v3 = new Vendor()
            {
                id = 2, userName = "******", name = "name2", website = "website_2"
            };
            var vendors = new List <Vendor> {
                v1, v2, v3
            };


            _favoritesQueryMock.Setup(x => x.GetAllByUserName("aml5071"))
            .Returns(Task.Factory.StartNew(() => favorites));

            _vendorsQueryMock.Setup(x => x.GetById(It.IsAny <int>()))
            .Returns((int i) => Task.Factory.StartNew(() => vendors[i]));

            //act

            var task = await _uut.GetFavoriteVendors("aml5071");

            //assert

            Assert.IsType <OkObjectResult>(task);

            var result        = task as OkObjectResult;
            var vendorsResult = result.Value as List <Vendor>;

            Assert.Equal(vendors, vendorsResult);
        }