Esempio n. 1
0
        public void GetAllProductsTest()
        {
            // Arrange - We're mocking our dbSet & dbContext
            var options = new DbContextOptionsBuilder <ProteusContext>()
                          .UseInMemoryDatabase(databaseName: "Proteus")
                          .Options;

            //insert seed data into db
            using (var context = new ProteusContext(options))
            {
                context.Products.Add(new Product()
                {
                    ProductName = "IPhone", CategoryId = 1, UnitPrice = 19.5M, UnitsInStock = 10, QuantityPerUnit = "2", UnitsOnOrder = 1, ReorderLevel = 1, Discontinued = false
                });
                context.Products.Add(new Product()
                {
                    ProductName = "Samsung", CategoryId = 1, UnitPrice = 33.5M, UnitsInStock = 10, QuantityPerUnit = "2", UnitsOnOrder = 1, ReorderLevel = 1, Discontinued = false
                });
                context.Products.Add(new Product()
                {
                    ProductName = "LG TV", CategoryId = 2, UnitPrice = 33.5M, UnitsInStock = 10, QuantityPerUnit = "2", UnitsOnOrder = 1, ReorderLevel = 1, Discontinued = false
                });
                context.SaveChanges();
            }

            // Act - fetch data
            var            dbContext      = new ProteusContext(options);
            List <Product> acutaldResults = dbContext.Products.ToList();

            //Assert
            Assert.AreEqual(expected: 3, actual: acutaldResults.Count);
        }
Esempio n. 2
0
        public CategoryServiceTests()
        {
            //create in memory db
            var options = new DbContextOptionsBuilder <ProteusContext>()
                          .UseInMemoryDatabase(databaseName: "Proteus")
                          .Options;

            //insert seed data into db
            using (var context = new ProteusContext(options))
            {
                context.Categories.Add(new Category()
                {
                    CategoryName = "Phone"
                });
                context.Categories.Add(new Category()
                {
                    CategoryName = "TV"
                });
                context.SaveChanges();
            }
            var dbContext = new ProteusContext(options);

            _categoryRepoMock = new CategoryRepository(dbContext);

            _sut = new CategoryService(_categoryRepoMock, _loggerMock.Object);
        }
Esempio n. 3
0
        [SetUp]//like a constructor
        public void SetUp()
        {
            // Arrange - We're mocking our dbSet & dbContext
            var options = new DbContextOptionsBuilder <ProteusContext>()
                          .UseInMemoryDatabase(databaseName: "Proteus")
                          .Options;

            //insert seed data into db
            using (var context = new ProteusContext(options))
            {
                context.Categories.Add(new Category()
                {
                    CategoryName = "Phone"
                });
                context.Categories.Add(new Category()
                {
                    CategoryName = "TV"
                });
                context.SaveChanges();
            }

            _dbContext = new ProteusContext(options);
        }