Esempio n. 1
0
        public async Task Get()
        {
            var parent = _parent.Select(
                vertex => (GeographicRegion) new Subdivision(
                    vertex.ToString(),
                    vertex.ToString(),
                    null,
                    null,
                    null));

            var geographicRegionHierarchy = new GeographicRegionHierarchy(parent);

            using (var scope = _container.BeginLifetimeScope())
            {
                var session = scope.Resolve <ISession>();
                await session.SaveAsync(geographicRegionHierarchy);

                await geographicRegionHierarchy.VisitAsync(
                    async geographicRegionHierarchyMember =>
                {
                    await session.SaveAsync(geographicRegionHierarchyMember.Member);
                    await session.SaveAsync(geographicRegionHierarchyMember);
                },
                    null);

                await session.FlushAsync();
            }

            GeographicRegionHierarchy retrieved = null;

            using (var scope = _container.BeginLifetimeScope())
                retrieved = await scope.Resolve <IDomainObjectService <Guid, GeographicRegionHierarchy> >().GetAsync(geographicRegionHierarchy.Id);

            Assert.That(retrieved, Is.Not.Null);
            Assert.That(retrieved, Is.EqualTo(geographicRegionHierarchy));
            Assert.That(retrieved.Members.ToHashSet().SetEquals(geographicRegionHierarchy.Members));

            var map = geographicRegionHierarchy.Members.ToDictionary(classificationSchemeClassifier => classificationSchemeClassifier.Id);

            foreach (var retrievedGeographicRegionHierarchyMember in retrieved.Members)
            {
                var classificationSchemeClassifier = map[retrievedGeographicRegionHierarchyMember.Id];
                Assert.That(retrievedGeographicRegionHierarchyMember, Is.EqualTo(classificationSchemeClassifier));
                Assert.That(retrievedGeographicRegionHierarchyMember.Member, Is.EqualTo(classificationSchemeClassifier.Member));
                Assert.That(retrievedGeographicRegionHierarchyMember.Parent, Is.EqualTo(classificationSchemeClassifier.Parent));
                Assert.That(retrievedGeographicRegionHierarchyMember.Children.ToHashSet().SetEquals(classificationSchemeClassifier.Children));
            }
        }
Esempio n. 2
0
        public void NewClassificationScheme()
        {
            var parent = _parent.Select(
                vertex => (GeographicRegion) new Subdivision(
                    vertex.ToString(),
                    vertex.ToString(),
                    null,
                    null,
                    null));
            var child = parent.Transpose();

            var geographicRegionHierarchy = new GeographicRegionHierarchy(parent);

            Assert.That(geographicRegionHierarchy.Members.Count, Is.EqualTo(parent.Count));

            Func <GeographicRegion, GeographicRegionHierarchyMember> map        = geographicRegion => geographicRegionHierarchy[geographicRegion];
            Func <GeographicRegionHierarchyMember, GeographicRegion> inverseMap =
                geographicRegionHierarchyMember => geographicRegionHierarchyMember != null ? geographicRegionHierarchyMember.Member : default;

            Assert.That(parent.Keys.All(
                            gr =>
                            map.PreservesStructure(
                                geographicRegion => parent[geographicRegion].FirstOrDefault(),
                                geographicRegionHierarchyMember => geographicRegionHierarchyMember.Parent,
                                gr) &&
                            map.PreservesStructure(
                                geographicRegion => child[geographicRegion],
                                geographicRegionHierarchyMember => geographicRegionHierarchyMember.Children,
                                gr)), Is.True);

            Assert.That(geographicRegionHierarchy.Members.All(
                            grhm =>
                            inverseMap.PreservesStructure(
                                geographicRegionHierarchyMember => geographicRegionHierarchyMember.Parent,
                                geographicRegion => parent[geographicRegion].FirstOrDefault(),
                                grhm) &&
                            inverseMap.PreservesStructure(
                                geographicRegionHierarchyMember => geographicRegionHierarchyMember.Children,
                                geographicRegion => child[geographicRegion],
                                grhm)), Is.True);

            Assert.That(geographicRegionHierarchy.Members
                        .Where(geographicRegionMember => geographicRegionMember.Parent != null)
                        .All(geographicRegionMember => geographicRegionMember.Parent.Contains(geographicRegionMember)));
        }
Esempio n. 3
0
        public void Contains(
            char lhs,
            char rhs,
            bool contains
            )
        {
            var map = _parent.Keys.ToDictionary(
                vertex => vertex,
                vertex => (GeographicRegion) new Subdivision(
                    vertex.ToString(),
                    vertex.ToString(),
                    null,
                    null,
                    null));
            var geographicRegionHierarchy = new GeographicRegionHierarchy(_parent.Select(c => map[c]));

            Assert.That(geographicRegionHierarchy[map[lhs]].Contains(geographicRegionHierarchy[map[rhs]]), Is.EqualTo(contains));
        }
Esempio n. 4
0
        public async Task Get()
        {
            var parent = _parent.Select(
                vertex => (GeographicRegion) new Subdivision(
                    vertex.ToString(),
                    vertex.ToString(),
                    null,
                    null,
                    null));

            var geographicRegionHierarchy = new GeographicRegionHierarchy(parent);

            using (var scope = _container.BeginLifetimeScope())
            {
                var session = scope.Resolve <ISession>();
                await session.SaveAsync(geographicRegionHierarchy);

                await geographicRegionHierarchy.VisitAsync(
                    async geographicRegionHierarchyMember =>
                {
                    await session.SaveAsync(geographicRegionHierarchyMember.Member);
                    await session.SaveAsync(geographicRegionHierarchyMember);
                },
                    null);

                await session.FlushAsync();
            }

            Web.Model.GeographicRegionHierarchy geographicRegionHierarchyModel = null;
            using (var scope = _container.BeginLifetimeScope())
            {
                var controller   = scope.Resolve <GeographicRegionHierarchyController>();
                var actionResult = await controller.GetAsync(geographicRegionHierarchy.Id);

                Assert.That(actionResult, Is.Not.Null);
                Assert.That(actionResult, Is.InstanceOf <OkObjectResult>());
                var okObjectResult = (OkObjectResult)actionResult;
                Assert.That(okObjectResult.Value, Is.InstanceOf <Web.Model.GeographicRegionHierarchy>());
                geographicRegionHierarchyModel = (Web.Model.GeographicRegionHierarchy)okObjectResult.Value;
                Assert.That(geographicRegionHierarchyModel.Id, Is.EqualTo(geographicRegionHierarchy.Id));
            }

            var geographicRegionHierarchyMemberMap = (
                from domainObject in geographicRegionHierarchy.Members
                join domainObjectModel in geographicRegionHierarchyModel.Members
                on domainObject.Id equals domainObjectModel.Id
                select
                (
                    domainObject,
                    domainObjectModel
                )).ToDictionary(
                tuple => tuple.domainObject,
                tuple => tuple.domainObjectModel);

            var geographicRegionMap = (
                from domainObject in geographicRegionHierarchy.Members.Select(geographicRegionHierarchyMember => geographicRegionHierarchyMember.Member)
                join domainObjectModel in geographicRegionHierarchyModel.Members.Select(geographicRegionHierarchyMember => geographicRegionHierarchyMember.Member)
                on domainObject.Id equals domainObjectModel.Id
                select
                (
                    domainObject,
                    domainObjectModel
                )).ToDictionary(
                tuple => tuple.domainObject,
                tuple => tuple.domainObjectModel);

            foreach (var geographicRegionHierarchyMember in geographicRegionHierarchy.Members)
            {
                var geographicRegionHierarchyMemberModel = geographicRegionHierarchyMemberMap[geographicRegionHierarchyMember];
                Assert.That(
                    geographicRegionHierarchyMemberModel.Member, Is.EqualTo(geographicRegionMap[geographicRegionHierarchyMember.Member]));
                Assert.That(geographicRegionHierarchyMemberModel.Parent != null, Is.EqualTo(geographicRegionHierarchyMember.Parent != null));
                if (geographicRegionHierarchyMemberModel.Parent != null)
                {
                    Assert.That(geographicRegionHierarchyMemberModel.Parent,
                                Is.EqualTo(geographicRegionHierarchyMemberMap[geographicRegionHierarchyMember.Parent]));
                }
                Assert.That(geographicRegionHierarchyMemberModel.Children.ToHashSet().SetEquals(
                                geographicRegionHierarchyMember.Children.Select(child => geographicRegionHierarchyMemberMap[child])), Is.True);
            }
        }