Example #1
0
        public async Task Can_Index_Products()
        {
            AggregateFactory.Configure();

            var repository = new ProductRepository(new AggregateFactory());

            var product = new ProductDTO();

            product.Id = Guid.NewGuid().ToString();

            var variant = new ProductDTO();

            variant.Id    = "my id";
            variant.Title = "my title";

            variant.Details.CustomField1 = "a string value";
            variant.Details.CustomField2 = 42;

            product.Variants = new List <Product>
            {
                variant
            };

            await repository.IndexAsync(product);

            var result = await repository.GetSummaryAsync(product.Id);

            Assert.Equal(product.Title, result.Title);
        }
Example #2
0
        public void Has_Summary()
        {
            AggregateFactory.Configure();

            string summary = "My summary";
            var    product = new ProductBuilder().WithSummary(summary).AsAggregate <ProductSummaryAggregate>(new AggregateFactory());

            Assert.Equal(product.Summary, summary);
        }
Example #3
0
        public void Has_Description()
        {
            AggregateFactory.Configure();

            string desc    = "My description";
            var    product = new ProductBuilder().WithDescription(desc).AsAggregate <ProductDetailsAggregate>(new AggregateFactory());

            Assert.Equal(product.Description, desc);
        }
Example #4
0
        public void Has_Categories()
        {
            AggregateFactory.Configure();

            var product = new ProductBuilder()
                          .WithCategories(
                new Category(),
                new Category()
                )
                          .AsAggregate <ProductDetailsAggregate>(new AggregateFactory());

            Assert.Equal(product.Categories.Count(), 2);
        }
Example #5
0
        public void Has_Variants()
        {
            AggregateFactory.Configure();

            var product = new ProductBuilder()
                          .WithVariants(
                new Product(),
                new Product()
                )
                          .AsAggregate <ProductVariantsAggregate>(new AggregateFactory());

            Assert.Equal(product.Variants.Count(), 2);
        }
Example #6
0
        public async Task Can_Index_Recursive_Variants()
        {
            AggregateFactory.Configure();

            var repository = new ProductRepository(new AggregateFactory());

            //Create a product
            var product = new ProductDTO();

            product.Id = Guid.NewGuid().ToString();

            //Create a variant
            var variant = new ProductDTO();

            variant.Id    = "my id";
            variant.Title = "my title";

            variant.Details.CustomField1 = "a string value";
            variant.Details.CustomField2 = 42;

            //Create a nested variant
            var nestedVariant = new ProductDTO();

            nestedVariant.Id    = "my nested id";
            nestedVariant.Title = "my nested title";

            nestedVariant.Details.CustomField3 = DateTime.Now;

            variant.Variants = new List <Product>
            {
                nestedVariant
            };

            product.Variants = new List <Product>
            {
                variant
            };

            Console.WriteLine("Indexing as " + product.Id);

            await repository.IndexAsync(product);

            Task.Delay(500).Wait();

            var result = await repository.GetVariantsAsync(product.Id);

            Assert.Equal(1, result.Variants.Count());
        }
Example #7
0
        public void Can_Set_Variants()
        {
            AggregateFactory.Configure();

            var dto = new ProductDTO();

            dto.Variants = new List <Product>
            {
                new ProductDTO(),
                new ProductDTO()
            };

            var model = dto.AsAggregate <ProductVariantsAggregate>(new AggregateFactory());

            Assert.Equal(2, model.Variants.Count());
        }
Example #8
0
        public async Task Can_Partially_Update_Product_Variants()
        {
            AggregateFactory.Configure();

            var repository = new ProductRepository(new AggregateFactory());

            //Create a product
            var product = new ProductDTO();

            product.Id = Guid.NewGuid().ToString();

            //Create a variant
            var variant1 = new ProductDTO();

            variant1.Id    = "1";
            variant1.Title = "my title 1";

            variant1.Details.CustomField1 = "a string value";
            variant1.Details.CustomField2 = 42;

            //Create another variant
            var variant2 = new ProductDTO();

            variant2.Id    = "2";
            variant2.Title = "my title 2";

            product.Variants = new List <Product>
            {
                variant1,
                variant2
            };

            Console.WriteLine("Indexing as " + product.Id);

            await repository.IndexAsync(product);

            await Task.Delay(500);

            //Create a 'copy' of the product, and reindex with just the second variant
            //Should update the second variant, but leave the first untouched

            var newProduct = new ProductDTO();

            newProduct.Id = product.Id;

            variant2.Title = "my new title 2";

            newProduct.Variants = new List <Product>
            {
                variant2
            };

            Console.WriteLine("Reindexing as " + product.Id);

            //TODO: Make this method work as expected
            await repository.IndexAsync(newProduct);

            var finalProduct = await repository.GetVariantsAsync(product.Id);

            throw new NotImplementedException();
        }