Esempio n. 1
0
 public RecommendsMarketController(IRecommendsMarketService recommendsMarketService)
 {
     _recommendsMarketService = recommendsMarketService;
 }
        public RecommendsMarketServiceTest()
        {
            _productRepositoryMock = new Mock <IProductRepository>();
            _products = new List <Product>
            {
                new Product
                {
                    Name                    = "Agua",
                    Market                  = "tonin",
                    Price                   = 2.05d,
                    PenultimatePrice        = 2.05d,
                    SearchableName          = "agua",
                    TemOferta               = false,
                    DateOfLastPurchase      = "26/08/2020",
                    DatePenultimatePurchase = "26/08/2020"
                },
                new Product
                {
                    Name                    = "Linguica",
                    Market                  = "tonin",
                    Price                   = 10.05d,
                    PenultimatePrice        = 10.05d,
                    SearchableName          = "linguica",
                    TemOferta               = false,
                    DateOfLastPurchase      = "26/08/2020",
                    DatePenultimatePurchase = "26/08/2020"
                },
                new Product
                {
                    Name                    = "Agua",
                    Market                  = "savegnago",
                    Price                   = 1.95d,
                    PenultimatePrice        = 2.07d,
                    SearchableName          = "agua",
                    TemOferta               = true,
                    DateOfLastPurchase      = "26/08/2020",
                    DatePenultimatePurchase = "26/08/2020"
                },
                new Product
                {
                    Name                    = "Linguica",
                    Market                  = "savegnago",
                    Price                   = 11.05d,
                    PenultimatePrice        = 9.95d,
                    SearchableName          = "linguica",
                    TemOferta               = false,
                    DateOfLastPurchase      = "26/08/2020",
                    DatePenultimatePurchase = "26/08/2020"
                },
                new Product
                {
                    Name                    = "Iorgute",
                    Market                  = "tonin",
                    Price                   = 1.54d,
                    PenultimatePrice        = 2.07d,
                    SearchableName          = "iorgute",
                    TemOferta               = false,
                    DateOfLastPurchase      = "26/08/2020",
                    DatePenultimatePurchase = "26/08/2020"
                },
            };

            _productRepositoryMock.Setup(x => x.GetAsync(It.IsAny <string>())).Returns(Task.FromResult <ICollection <Product> >(_products));

            _searchableNames = new List <string>();
            _searchableNames.Add("linguica");
            _searchableNames.Add("agua");
            _searchableNames.Add("iorgute");
            _productRepositoryMock.Setup(x => x.GetSearchableNamesAsync()).Returns(Task.FromResult <ICollection <string> >(_searchableNames));

            _productRepositoryMock.Setup(x => x.AddAsync(new List <Product>(), "")).Returns(Task.FromResult(new { }));
            _productRepositoryMock.Setup(x => x.AddSearchableNamesAsync(new List <string>())).Returns(Task.FromResult(new { }));
            _productRepositoryMock.Setup(x => x.GetMarkets()).Returns(Task.FromResult <ICollection <string> >(new List <string> {
                "tonin", "savegnago"
            }));

            _recommendsMarket = new RecommendsMarket {
                Items = new List <RecommendsMarketItem>()
            };
            _recommendsMarketRepositoryMock = new Mock <IRecommendsMarketRepository>();
            _recommendsMarketRepositoryMock.Setup(x => x.GetRecommendsMarket()).Returns(Task.FromResult <RecommendsMarket>(_recommendsMarket));
            _recommendsMarketRepositoryMock.Setup(x => x.SaveAsync(It.IsAny <RecommendsMarket>())).Returns(Task.FromResult(new { }));

            _recommendsMarketService = new RecommendsMarketService(_productRepositoryMock.Object, _recommendsMarketRepositoryMock.Object);

            _request = new List <string>();
            _request.Add("linguica");
            _request.Add("agua");
            _request.Add("coca-cola");
            _request.Add("iorgute");
        }