public async Task DeleteProduct_Deletes_Product_Correctly()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            Product newProduct1 = new Product
            {
                DeliveryPrice = 20,
                Description   = "Test Desc",
                Name          = "Test Product",
                Price         = 1000
            };

            await sqliteProductRepository.CreateProduct(newProduct1);

            var products = await sqliteProductRepository.GetAllProducts();

            //Act
            await sqliteProductRepository.DeleteProduct(products[0].Id);

            var result = await sqliteProductRepository.GetAllProducts();

            //Assert
            Assert.Empty(result);
        }
        public async Task GetProductById_Returns_Correct_Product()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            Product newProduct1 = new Product
            {
                DeliveryPrice = 20,
                Description   = "Test Desc",
                Name          = "Test Product",
                Price         = 1000
            };

            await sqliteProductRepository.CreateProduct(newProduct1);

            var products = await sqliteProductRepository.GetAllProducts();

            //Act
            var result = await sqliteProductRepository.GetProductById(products[0].Id);

            //Assert
            Assert.Equal(newProduct1.Name, result.Name);
            Assert.Equal(newProduct1.Description, result.Description);
            Assert.Equal(newProduct1.Price, result.Price);
            Assert.Equal(newProduct1.DeliveryPrice, result.DeliveryPrice);
        }
        public async Task DeleteProductOption_Deletes_ProductOption_Correctly()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            ProductOption productOption1 = new ProductOption
            {
                Name        = "Mac Red",
                Description = "This is a Mac red",
                ProductId   = Guid.Parse("01234567-89ab-cdef-0123-456789abcdef")
            };

            await sqliteProductRepository.CreateProductOption(productOption1);

            var productOptions = await sqliteProductRepository.GetProductOptionsByProductId(Guid.Parse("01234567-89ab-cdef-0123-456789abcdef"));

            //Act
            await sqliteProductRepository.DeleteProductOption(productOptions[0].Id);

            var result = await sqliteProductRepository.GetProductOptionsByProductId(Guid.Parse("01234567-89ab-cdef-0123-456789abcdef"));

            //Assert
            Assert.Empty(result);
        }
        public async Task GetProductOptionsByProductIdAndOptionsId_Returns_ProductOption_Correctly()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            ProductOption productOption1 = new ProductOption
            {
                Name        = "Mac Red",
                Description = "This is a Mac red",
                ProductId   = Guid.Parse("01234567-89ab-cdef-0123-456789abcdef")
            };

            ProductOption productOption2 = new ProductOption
            {
                Name        = "Mac Blue",
                Description = "This is a Mac blue",
                ProductId   = Guid.Parse("01234567-89ab-cdef-0123-456789abcdef")
            };

            await sqliteProductRepository.CreateProductOption(productOption1);

            await sqliteProductRepository.CreateProductOption(productOption2);

            var productOptions = await sqliteProductRepository.GetProductOptionsByProductId(Guid.Parse("01234567-89ab-cdef-0123-456789abcdef"));

            //Act
            var result = await sqliteProductRepository.GetProductOptionsByProductIdAndOptionsId(Guid.Parse("01234567-89ab-cdef-0123-456789abcdef"), productOptions[0].Id);

            //Assert
            Assert.Equal(productOption1.ProductId, result.ProductId);
            Assert.Equal(productOption1.Name, result.Name);
            Assert.Equal(productOption1.Description, result.Description);
        }
        public void Dispose()
        {
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            sqliteProductRepository.DeleteAllData().Wait();
        }
コード例 #6
0
        public void GetProductsByName_ReturnsNoMatchingProducts_WhenNoProductWithTheGivenNameExists()
        {
            //Arrange
            var repo = new SqliteProductRepository(SetupDb());

            //Act
            var actual = repo.GetProductsByName("NO PRODUCT").ToList();

            //Assert
            Assert.IsTrue(actual.Count == 0);
        }
コード例 #7
0
        public void GetAllProducts_ReturnsAllProducts()
        {
            //Arrange
            var repo     = new SqliteProductRepository(SetupDb());
            var expected = productList.OrderBy(e => e.Id).ToList();

            //Act
            var actual = repo.GetAllProducts().OrderBy(e => e.Id).ToList();

            //Assert
            Assert.IsTrue(productList.IsDeepEqual(actual));
        }
コード例 #8
0
        public void GetProductsByName_ReturnsTwoMatchingProducts_WhenOneProductWithTheGivenNameExists()
        {
            //Arrange
            var repo     = new SqliteProductRepository(SetupDb());
            var expected = productList.Where(e => e.Name.Contains("Shirt")).OrderBy(e => e.Id).ToList();

            //Act
            var actual = repo.GetProductsByName("Shirt").OrderBy(e => e.Id).ToList();

            //Assert
            Assert.IsTrue(actual.Count == 2);
            Assert.IsTrue(expected.IsDeepEqual(actual));
        }
コード例 #9
0
        public void GetProductsByName_ReturnsOneMatchingProduct_WhenOneProductWithTheGivenNameExists()
        {
            //Arrange
            var repo     = new SqliteProductRepository(SetupDb());
            var expected = productList.First(e => e.Name == "Red Shirt");

            //Act
            var actual = repo.GetProductsByName("Red Shirt").ToList();

            //Assert
            Assert.IsTrue(actual.Count == 1);
            Assert.IsTrue(expected.IsDeepEqual(actual.First()));
        }
        public async Task UpdateProduct_Updates_Product_Correctly()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            Product newProduct1 = new Product
            {
                DeliveryPrice = 20,
                Description   = "Test Desc",
                Name          = "Test Product",
                Price         = 1000
            };

            await sqliteProductRepository.CreateProduct(newProduct1);

            var products = await sqliteProductRepository.GetAllProducts();

            Product updatedProduct = new Product
            {
                Id            = products[0].Id,
                DeliveryPrice = 200,
                Description   = "Test Desc 1",
                Name          = "Test Product 1",
                Price         = 3000
            };

            //Act
            await sqliteProductRepository.UpdateProduct(updatedProduct);

            var result = await sqliteProductRepository.GetProductById(updatedProduct.Id);

            //Assert
            Assert.Equal(updatedProduct.Id, result.Id);
            Assert.Equal(updatedProduct.Name, result.Name);
            Assert.Equal(updatedProduct.Description, result.Description);
            Assert.Equal(updatedProduct.Price, result.Price);
            Assert.Equal(updatedProduct.DeliveryPrice, result.DeliveryPrice);
        }
        public async Task GetProductsLikeName_Returns_Correct_Product()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            Product newProduct1 = new Product
            {
                DeliveryPrice = 20,
                Description   = "Test Desc",
                Name          = "Macbook",
                Price         = 1000
            };

            Product newProduct2 = new Product
            {
                DeliveryPrice = 50,
                Description   = "Test Desc 2",
                Name          = "Samsung",
                Price         = 300
            };

            await sqliteProductRepository.CreateProduct(newProduct1);

            await sqliteProductRepository.CreateProduct(newProduct2);

            //Act
            var result = await sqliteProductRepository.GetProductsLikeName("Sam");

            //Assert
            Assert.Equal(newProduct2.Name, result[0].Name);
            Assert.Equal(newProduct2.Description, result[0].Description);
            Assert.Equal(newProduct2.Price, result[0].Price);
            Assert.Equal(newProduct2.DeliveryPrice, result[0].DeliveryPrice);
        }
        public async Task UpdateProductOption_Updates_ProductOption_Correctly()
        {
            //Arrange
            Mock <ILogger <SqliteProductRepository> > mockLogger = new Mock <ILogger <SqliteProductRepository> >();

            SqliteProductRepository sqliteProductRepository = new SqliteProductRepository(BuildConfiguration(), mockLogger.Object);

            ProductOption productOption1 = new ProductOption
            {
                Name        = "Mac Red",
                Description = "This is a Mac red",
                ProductId   = Guid.Parse("01234567-89ab-cdef-0123-456789abcdef")
            };

            await sqliteProductRepository.CreateProductOption(productOption1);

            var productOptions = await sqliteProductRepository.GetProductOptionsByProductId(Guid.Parse("01234567-89ab-cdef-0123-456789abcdef"));

            ProductOption updatedProductOption = new ProductOption
            {
                Id          = productOptions[0].Id,
                Name        = "Updated red",
                Description = "Updated desc",
                ProductId   = Guid.Parse("01234567-89ab-cdef-0123-456789abcdef")
            };

            //Act
            await sqliteProductRepository.UpdateProductOption(updatedProductOption);

            var result = await sqliteProductRepository.GetProductOptionsByProductId(Guid.Parse("01234567-89ab-cdef-0123-456789abcdef"));

            //Assert
            Assert.Equal(updatedProductOption.ProductId, result[0].ProductId);
            Assert.Equal(updatedProductOption.Name, result[0].Name);
            Assert.Equal(updatedProductOption.Description, result[0].Description);
        }