コード例 #1
0
        public void AddRangeGetAllReturnsAll2Items()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var products = context.Product.ToList();
                products.Count().ShouldEqual(2);
            }
        }
コード例 #2
0
        public void GetProductOptionNotFoundError()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);
                Assert.Throws <KeyNotFoundException>(() => repository.GetProductOption(new Guid(), new Guid()));
            }
        }
コード例 #3
0
        public void DeleteProductSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);
                repository.DeleteProduct(ProductMocks.ProductSamsungGalaxyS7).ShouldBeTrue();
            }
        }
コード例 #4
0
        public void AddProductDuplicateKeyError()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);
                Assert.Throws <InvalidOperationException>(() => repository.AddProduct(ProductMocks.ProductSamsungGalaxyS7));
            }
        }
コード例 #5
0
        public void GetProductOptionsSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger         = new Mock <ILogger <ProductsRepository> >();
                var repository     = new ProductsRepository(context, logger.Object);
                var productOptions = repository.GetProductOptions(ProductMocks.ProductSamsungGalaxyS7.Id);
                productOptions.Count().ShouldEqual(ProductMocks.ProductSamsungGalaxyS7.ProductOptions.Count());
            }
        }
コード例 #6
0
        public void GetProductByNameReturnsEmpty()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);

                var matches = repository.SearchByName("Microsoft");
                matches.Count().ShouldEqual(0);
            }
        }
コード例 #7
0
        public void GetProductByIdReturnsSucessAndWithOptions()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger       = new Mock <ILogger <ProductsRepository> >();
                var repository   = new ProductsRepository(context, logger.Object);
                var product      = repository.GetProduct(ProductMocks.ProductSamsungGalaxyS7.Id);
                var compareLogic = new CompareLogic();

                var result = compareLogic.Compare(product, ProductMocks.ProductSamsungGalaxyS7);
                result.AreEqual.ShouldBeTrue();
                product.ProductOptions.Count().ShouldEqual(2);
            }
        }
コード例 #8
0
        public void GetProductByNameReturnsSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);

                var matches = repository.SearchByName("Samsung");
                matches.Count().ShouldEqual(1);

                var product = matches.First();
                product.Name.ShouldEqual(ProductMocks.ProductSamsungGalaxyS7.Name);
            }
        }
コード例 #9
0
        public void GetProductOptionSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var targetOption = ProductMocks.ProductSamsungGalaxyS7.ProductOptions.First();
                var logger       = new Mock <ILogger <ProductsRepository> >();
                var repository   = new ProductsRepository(context, logger.Object);
                var sourceOption = repository.GetProductOption(targetOption.ProductId, targetOption.Id);
                var compareLogic = new CompareLogic();

                var result = compareLogic.Compare(targetOption, sourceOption);
                result.AreEqual.ShouldBeTrue();
            }
        }
コード例 #10
0
        public void UpdateProductSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);
                var logger     = new Mock <ILogger <ProductsRepository> >();
                var repository = new ProductsRepository(context, logger.Object);
                var product    = ProductMocks.ProductSamsungGalaxyS7;
                product.Description = "TestDescription";
                product.Name        = "TestName";
                repository.UpdateProduct(product);
                var updatedProduct = repository.GetProduct(product.Id);
                updatedProduct.Name.ShouldBeSameAs(product.Name);
                updatedProduct.Description.ShouldBeSameAs(product.Description);
            }
        }
コード例 #11
0
        public void UpdateProductOptionSuccess()
        {
            var options = EfInMemory.CreateOptions <ProductsContext>();

            using (var context = new ProductsContext(options))
            {
                var option       = ProductMocks.ProductSamsungGalaxyS7.ProductOptions.First();
                var logger       = new Mock <ILogger <ProductsRepository> >();
                var repository   = new ProductsRepository(context, logger.Object);
                var compareLogic = new CompareLogic();
                context.FeedDataContext(ProductMocks.ProductsBaseDataset);

                option.Name        = "UpdatedName";
                option.Description = "UpdatedDescription";
                repository.UpdateProductOption(option);
                var updatedOption = repository.GetProductOption(option.ProductId, option.Id);
                var result        = compareLogic.Compare(option, updatedOption);
                result.AreEqual.ShouldBeTrue();
            }
        }