public void Children_FacetHasASingleChild_ReturnsThatChild()
        {
            var context             = FacetContext;
            var facetTypeRepository = new Repository <FacetType, EFacetType>(context);
            var parentGroup         = FacetGroupFactory.Fake(27218);
            var childGroup          = FacetGroupFactory.Fake(175);

            var discreteType = facetTypeRepository.Get(EFacetType.Discrete);

            var facets = new List <Facet>()
            {
                FakeFacet("parent", discreteType, parentGroup, is_applicable: false),
                FakeFacet("child 1", discreteType, childGroup),
                FakeFacet("child 2", discreteType, childGroup)
            };

            var relations = new List <FacetChild>()
            {
                new FacetChild {
                    FacetCode      = facets[0].FacetCode,
                    ChildFacetCode = facets[1].FacetCode,
                }
            };

            context.FacetGroups.Add(parentGroup);
            context.FacetGroups.Add(childGroup);
            context.Facets.AddRange(facets);
            context.FacetChildren.AddRange(relations);

            context.SaveChanges();

            var repository = new FacetRepository(context);

            var parent = repository.GetByCode("parent");

            Assert.NotNull(parent);

            var children = repository.Children(parent.FacetCode);

            Assert.NotNull(children);
            Assert.Single(children);
            Assert.Same(facets[1], children.FirstOrDefault());
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MongoDbPersistence.Configure();

            ConnectionOptions options = new ConnectionOptions
            {
                Url      = "mongodb://127.0.0.1:27017/?connectTimeoutMS=10000&socketTimeoutMS=10000",
                Database = "test-db"
            };

            MongoDbContext mongoDbContext = new MongoDbContext(options);

            var facetRepository   = new FacetRepository(mongoDbContext);
            var productRepository = new ProductRepository(mongoDbContext);

            var insertedEntity = productRepository.Insert(new Product
            {
                Name     = "Product-Test-1",
                TenantId = "Tenant-Test"
            });

            Console.WriteLine("Hello World!");
        }