public void TestInitialize()
        {
            var categories = new List <CategoryEntity>()
            {
                new CategoryEntity()
                {
                    Id                      = 1,
                    Name                    = "Laptops",
                    Description             = "Shop Laptops and find popular brands. Save money.",
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                },
                new CategoryEntity()
                {
                    Id                      = 2,
                    Name                    = "Printers",
                    Description             = "The Best Printers for 2020.",
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                },
                new CategoryEntity()
                {
                    Id                      = 3,
                    Name                    = "Sale",
                    Description             = "Shop all sale items",
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                }
            };

            var mock = new Mock <IDbContext>();

            var categoriesDbSet = DbSetMockHelper.GetQueryableMockDbSet(categories);

            mock.Setup(d => d.GetDbSet <CategoryEntity>()).Returns(categoriesDbSet);

            InjectService(mock.Object);
            InjectService <IUnitOfWorkContext>(mock.Object);

            ConfigureServices();

            Manager   = ServiceProvider.GetRequiredService <ICategoryManager>();
            Converter = ServiceProvider.GetRequiredService <IConverter <CategoryDto, CategoryModel> >();
        }
Exemplo n.º 2
0
        public void TestInitialize()
        {
            var products = new List <ProductEntity>()
            {
                new ProductEntity()
                {
                    Id                      = 1,
                    Name                    = "HP 410",
                    Description             = "All-in-One Wireless Ink Tank Color Printer",
                    Price                   = 90,
                    AvailableCount          = 9,
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                },
                new ProductEntity()
                {
                    Id                      = 2,
                    Name                    = "Epson L3152",
                    Description             = "WiFi All in One Ink Tank Printer",
                    Price                   = 60,
                    AvailableCount          = 19,
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                }
            };

            var categories = new List <CategoryEntity>()
            {
                new CategoryEntity()
                {
                    Id                      = 1,
                    Name                    = "Laptops",
                    Description             = "Shop Laptops and find popular brands. Save money.",
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                },
                new CategoryEntity()
                {
                    Id                      = 2,
                    Name                    = "Printers",
                    Description             = "The Best Printers for 2020.",
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                },
                new CategoryEntity()
                {
                    Id                      = 3,
                    Name                    = "Sale",
                    Description             = "Shop all sale items",
                    ProductCategoryEntities = new List <ProductCategoryEntity>()
                }
            };

            var mock = new Mock <IDbContext>();

            var productsDbSet   = DbSetMockHelper.GetQueryableMockDbSet(products);
            var categoriesDbSet = DbSetMockHelper.GetQueryableMockDbSet(categories);

            mock.Setup(d => d.GetDbSet <ProductEntity>()).Returns(productsDbSet);
            mock.Setup(d => d.GetDbSet <CategoryEntity>()).Returns(categoriesDbSet);

            InjectService(mock.Object);
            InjectService <IUnitOfWorkContext>(mock.Object);

            ConfigureServices();

            Manager   = ServiceProvider.GetRequiredService <IProductManager>();
            Converter = ServiceProvider.GetRequiredService <IConverter <ProductDto, ProductModel> >();
        }