Example #1
0
        public async Task CreateDepartment_IsSuccessful()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newDepartment = new NodeDto
            {
                Id       = 2,
                Name     = "Service",
                Type     = "Department",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var result = await _treeService.CreateNodeAsync(newDepartment);

            var actualDepartment = (await _treeService.GetTreeAsync())[6];

            Assert.True(result.Succeeded);
            Assert.Equal(newDepartment.Id, actualDepartment.Id);
            Assert.Equal(newDepartment.Name, actualDepartment.Name);
            Assert.Equal(newDepartment.ParentId, actualDepartment.ParentId);
            Assert.Equal(newDepartment.Type, actualDepartment.Type);
        }
Example #2
0
        public static NodeDto BuildDto(IMemberGroup entity)
        {
            var dto = new NodeDto
            {
                CreateDate     = entity.CreateDate,
                NodeId         = entity.Id,
                Level          = 0,
                NodeObjectType = _nodeObjectTypeId,
                ParentId       = -1,
                Path           = "",
                SortOrder      = 0,
                Text           = entity.Name,
                Trashed        = false,
                UniqueId       = entity.Key,
                UserId         = entity.CreatorId
            };

            if (entity.HasIdentity)
            {
                dto.NodeId = entity.Id;
                dto.Path   = "-1," + entity.Id;
            }

            return(dto);
        }
        public int ReserveId(Guid key)
        {
            NodeDto node;

            Sql <ISqlContext> sql = SqlContext.Sql()
                                    .Select <NodeDto>()
                                    .From <NodeDto>()
                                    .Where <NodeDto>(x => x.UniqueId == key && x.NodeObjectType == Cms.Core.Constants.ObjectTypes.IdReservation);

            node = Database.SingleOrDefault <NodeDto>(sql);
            if (node != null)
            {
                throw new InvalidOperationException("An identifier has already been reserved for this Udi.");
            }

            node = new NodeDto
            {
                UniqueId       = key,
                Text           = "RESERVED.ID",
                NodeObjectType = Cms.Core.Constants.ObjectTypes.IdReservation,

                CreateDate = DateTime.Now,
                UserId     = null,
                ParentId   = -1,
                Level      = 1,
                Path       = "-1",
                SortOrder  = 0,
                Trashed    = false
            };
            Database.Insert(node);

            return(node.NodeId);
        }
Example #4
0
        public void GetEntityNotifications()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var repo = new NotificationsRepository((IScopeAccessor)provider);

                var node1 = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1
                };
                ScopeAccessor.AmbientScope.Database.Insert(node1);
                IEntity entity1 = Mock.Of <IEntity>(e => e.Id == node1.NodeId);
                var     node2   = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1
                };
                ScopeAccessor.AmbientScope.Database.Insert(node2);
                IEntity entity2 = Mock.Of <IEntity>(e => e.Id == node2.NodeId);

                for (int i = 0; i < 10; i++)
                {
                    var userDto = new UserDto {
                        Email = "test" + i, Login = "******" + i, Password = "******", UserName = "******" + i, UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now
                    };
                    ScopeAccessor.AmbientScope.Database.Insert(userDto);
                    IUser        userNew      = Mock.Of <IUser>(e => e.Id == userDto.Id);
                    Notification notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
                }

                IEnumerable <Notification> notifications = repo.GetEntityNotifications(entity1);

                Assert.AreEqual(5, notifications.Count());
            }
        }
        public void Delete_By_User()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repo = new NotificationsRepository(unitOfWork))
            {
                var userDto = new UserDto {
                    ContentStartId = -1, Email = "test", Login = "******", MediaStartId = -1, Password = "******", Type = 1, UserName = "******", UserLanguage = "en"
                };
                unitOfWork.Database.Insert(userDto);

                var userNew   = Mock.Of <IUser>(e => e.Id == userDto.Id);
                var userAdmin = Mock.Of <IUser>(e => e.Id == 0);

                for (var i = 0; i < 10; i++)
                {
                    var node = new NodeDto {
                        CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
                    };
                    var result       = unitOfWork.Database.Insert(node);
                    var entity       = Mock.Of <IEntity>(e => e.Id == node.NodeId);
                    var notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
                }

                var delCount = repo.DeleteNotifications(userAdmin);

                Assert.AreEqual(5, delCount);
            }
        }
        /// <summary>
        /// Updates the management node.
        /// </summary>
        /// <param name="host">Host.</param>
        /// <param name="serverDto">Server dto.</param>
        public void UpdateManagementNode(NodeDto host, ServerDto serverDto)
        {
            var server = new ServerDto
            {
                Server     = host.Name,
                Upn        = serverDto.Upn,
                UserName   = serverDto.UserName,
                Password   = serverDto.Password,
                DomainName = serverDto.DomainName
            };
            var dto = _service.GetManagementNodeDetails(server);

            dto.Name   = server.Server;
            dto.Domain = server.DomainName;
            var index = Hosts.FindIndex(x => x.Name == dto.Name);

            if (index < Hosts.Count)
            {
                Hosts[index] = dto;
            }
            if (OnCacheRefresh != null)
            {
                OnCacheRefresh(this, EventArgs.Empty);
            }
        }
Example #7
0
        public async Task CreateDepartment_DepartmentAlreadyExist_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newDepartment = new NodeDto
            {
                Id       = 2,
                Name     = "Kitchen",
                Type     = "Department",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.CreateNodeAsync(newDepartment);

            var expectResult = new ServiceResult($"Department with name: {newDepartment.Name} - already exist.");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(6, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #8
0
        public async Task CreateFamily_BusinessNotFound_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newFamily = new NodeDto
            {
                Id       = 2,
                Name     = "Fast food",
                Type     = "Family",
                ParentId = 2
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.CreateNodeAsync(newFamily);

            var expectResult = new ServiceResult($"Business with id: {newFamily.ParentId} - not found.");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(6, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #9
0
        public RestTemplate GetMinOfRight([FromBody] NodeDto root)
        {
            BSTree     tree   = new BSTree();
            List <int> turnTo = new List <int>();

            InterceptableNodeFactory.getInstance().setNodeInterceptor(new NodeInterceptorImpl(turnTo));
            tree.setNodeFactory(InterceptableNodeFactory.getInstance());
            tree.root = toEntity(root, InterceptableNodeFactory.getInstance());

            int minOfRight = tree.minimumOfRightChild();

            if (turnTo.Count == 0)
            {
                return(new RestTemplate((int)HttpStatusCode.Conflict, null, "This tree has no right child"));
            }

            if (turnTo.Count > 0)
            {
                turnTo.RemoveAt(turnTo.Count - 1);
            }

            turnTo.Insert(0, 1);

            Dictionary <string, Object> dict = new Dictionary <string, object>();

            dict.Add("turnTo", turnTo);
            dict.Add("minOfRight", minOfRight);

            return(new RestTemplate((int)HttpStatusCode.OK, dict, ""));
        }
Example #10
0
        public async Task CreateDepartment_WrongNodeType_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newDepartment = new NodeDto
            {
                Id       = 2,
                Name     = "Service",
                Type     = "Home",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.CreateNodeAsync(newDepartment);

            var expectResult = new ServiceResult($"Not found such type as: {newDepartment.Type}");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(6, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #11
0
        /// <inheritdoc />
        public int ReserveId(Guid key)
        {
            NodeDto node;

            using (var scope = UowProvider.ScopeProvider.CreateScope())
            {
                var sql = new Sql("SELECT * FROM umbracoNode WHERE uniqueID=@0 AND nodeObjectType=@1", key, Constants.ObjectTypes.IdReservationGuid);
                node = scope.Database.SingleOrDefault <NodeDto>(sql);
                if (node != null)
                {
                    throw new InvalidOperationException("An identifier has already been reserved for this Udi.");
                }
                node = new NodeDto
                {
                    UniqueId       = key,
                    Text           = "RESERVED.ID",
                    NodeObjectType = Constants.ObjectTypes.IdReservationGuid,

                    CreateDate = DateTime.Now,
                    UserId     = 0,
                    ParentId   = -1,
                    Level      = 1,
                    Path       = "-1",
                    SortOrder  = 0,
                    Trashed    = false
                };
                scope.Database.Insert(node);
                scope.Complete();
            }
            return(node.NodeId);
        }
Example #12
0
        private void UpdateManagementNode(NodeDto host, ServerDto serverDto)
        {
            var message = string.Format("Method: UpdateManagementNode refresh cache cycle start for Server: {0}", host.Name);
            var logger  = PscHighAvailabilityAppEnvironment.Instance.Logger;

            logger.Log(message, LogLevel.Info);
            var service = PscHighAvailabilityAppEnvironment.Instance.Service;
            var server  = new ServerDto
            {
                Server     = host.Name,
                Upn        = serverDto.Upn,
                UserName   = serverDto.UserName,
                Password   = serverDto.Password,
                DomainName = serverDto.DomainName
            };
            var dto = service.GetManagementNodeDetails(server);

            dto.Name   = server.Server;
            dto.Domain = server.DomainName;
            message    = string.Format("Method: UpdateManagementNode - for Server: {0}", host.Name);
            logger.Log(message, LogLevel.Info);
            var index = Hosts.FindIndex(x => x.Name == dto.Name);

            if (index > -1 && index < Hosts.Count)
            {
                Hosts[index] = dto;

                message = string.Format("Method: UpdateManagementNode updated VC Server: {0}", host.Name);
                logger.Log(message, LogLevel.Info);
            }
            message = string.Format("Method: UpdateManagementNode refresh cache cycle end for Server: {0}", host.Name);
            logger.Log(message, LogLevel.Info);
        }
Example #13
0
        public async Task UpdateOffering_OfferingAlreadyExist_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newOffering = new NodeDto
            {
                Id       = 1,
                Name     = "Multfilms",
                Type     = "Offering",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.UpdateNodeAsync(newOffering);

            var expectResult = new ServiceResult($"Offering with name: {newOffering.Name} - already exist.");

            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #14
0
        public async Task UpdateFamily_FamilyAlreadyExist_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newFamily = new NodeDto
            {
                Id       = 1,
                Name     = "Cinema",
                Type     = "Family",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.UpdateNodeAsync(newFamily);

            var expectResult = new ServiceResult($"Family with name: {newFamily.Name} - already exist.");

            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #15
0
        public async Task UpdateOrganization_OrganizationAlreadyExist_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newOrganization = new NodeDto
            {
                Id         = 1,
                Name       = "Organization2",
                Type       = "Organization",
                Properties = new NodePropertiesDto
                {
                    Code              = "5678",
                    OrganizationType  = OrganizationType.GeneralPartnership,
                    OrganizationOwner = "Mr. Paul"
                },
                ParentId = 0
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.UpdateNodeAsync(newOrganization);

            var expectResult = new ServiceResult($"Organization with code: {newOrganization.Properties.Code} - already exist.");

            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #16
0
        public async Task UpdateOffering_OfferingNotFound_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newOffering = new NodeDto
            {
                Id       = 0,
                Name     = "Pizza",
                Type     = "Offering",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.UpdateNodeAsync(newOffering);

            var expectResult = new ServiceResult($"Offering with id: {newOffering.Id} - not found.");

            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #17
0
        public RestTemplate Traverse([FromBody] NodeDto root, string type)
        {
            BSTree     tree   = new BSTree(toEntity(root, NodeFactoryImpl.getInstance()));
            List <int> turnTo = new List <int>();

            BSTTraversal    traversal = null;
            TraversalAction action    = new TraversalActionImpl(turnTo);

            if (type.Equals("preOrder"))
            {
                traversal = new PreOrderTraversal(action);
            }
            else if (type.Equals("inOrder"))
            {
                traversal = new InOrderTraversal(action);
            }
            else if (type.Equals("postOrder"))
            {
                traversal = new PostOrderTraversal(action);
            }
            else
            {
                return(new RestTemplate((int)HttpStatusCode.BadRequest, null, "preOrder or inOrder or postOrder is required for type"));
            }

            tree.traverse(traversal);

            return(new RestTemplate((int)HttpStatusCode.OK, turnTo, ""));
        }
Example #18
0
        public async Task CreateOrganization_IsSuccessful()
        {
            _treeService = GetTreeService();

            var newOrganization = new NodeDto
            {
                Id         = 1,
                Name       = "Organization1",
                Type       = "Organization",
                Properties = new NodePropertiesDto
                {
                    Code              = "1234",
                    OrganizationType  = OrganizationType.LimitedLiabilityCompany,
                    OrganizationOwner = "Mr. Bin"
                },
                ParentId = 0
            };

            var result = await _treeService.CreateNodeAsync(newOrganization);

            var actualOrganization = (await _treeService.GetTreeAsync())[0];

            Assert.True(result.Succeeded);
            Assert.Equal(newOrganization.Id, actualOrganization.Id);
            Assert.Equal(newOrganization.Name, actualOrganization.Name);
            Assert.Equal(newOrganization.ParentId, actualOrganization.ParentId);
            Assert.Equal(newOrganization.Type, actualOrganization.Type);
            Assert.Equal(newOrganization.Properties.Code, actualOrganization.Properties.Code);
            Assert.Equal(newOrganization.Properties.OrganizationType, actualOrganization.Properties.OrganizationType);
            Assert.Equal(newOrganization.Properties.OrganizationOwner, actualOrganization.Properties.OrganizationOwner);
        }
Example #19
0
        public RestTemplate GetTreeInfo([FromBody] NodeDto root)
        {
            BSTree tree = new BSTree(toEntity(root, NodeFactoryImpl.getInstance()));

            TreeInfo treeInfo = new TreeInfo();

            treeInfo.NumberOfLeaves = tree.numberOfLeaves();

            NumberOfNodesWrapper wrapper = new NumberOfNodesWrapper();

            wrapper.All                     = tree.numberOfNodes(NodeState.ALL);
            wrapper.HavingOneChild          = tree.numberOfNodes(NodeState.HAVING_ONLY_ONE_CHILD);
            wrapper.HavingOnlyOneLeftChild  = tree.numberOfNodes(NodeState.HAVING_ONLY_LEFT_CHILD);
            wrapper.HavingOnlyOneRightChild = tree.numberOfNodes(NodeState.HAVING_ONLY_RIGHT_CHILD);
            wrapper.HavingBothChildren      = tree.numberOfNodes(NodeState.HAVING_BOTH_CHILDREN);

            treeInfo.NumberOfNodes = wrapper;

            int[] LevelAndNodeCount = new int[tree.findHeight()];
            for (int i = 0; i < tree.findHeight(); i++)
            {
                LevelAndNodeCount[i] = tree.numberOfNodesAtLevel(i);
            }
            treeInfo.AtLevel         = LevelAndNodeCount;
            treeInfo.Height          = tree.findHeight();
            treeInfo.Min             = tree.minimum();
            treeInfo.Max             = tree.maximum();
            treeInfo.MinOfRightChild = tree.minimumOfRightChild();
            treeInfo.MaxOfLeftChild  = tree.maximumOfLeftChild();

            return(new RestTemplate((int)HttpStatusCode.OK, treeInfo, ""));
        }
Example #20
0
        public async Task CreateCountry_CountryAlreadyExist_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newCountry = new NodeDto
            {
                Id         = 2,
                Name       = "USA",
                Type       = "Country",
                Properties = new NodePropertiesDto
                {
                    Code = "1111"
                },
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.CreateNodeAsync(newCountry);

            var expectResult = new ServiceResult($"Country with code: {newCountry.Properties.Code} - already exist.");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(6, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #21
0
    public void SelfReference_Test()
    {
        var parentNodeDto = new NodeDto
        {
            Name = "parentNode",
        };

        parentNodeDto.SetProperty("node", "parent-value");

        var nodeDto = new NodeDto
        {
            Name   = "node",
            Parent = parentNodeDto
        };

        nodeDto.SetProperty("node", "node-value");

        var json = _jsonSerializer.Serialize(nodeDto);

        nodeDto = _jsonSerializer.Deserialize <NodeDto>(json);
        nodeDto.ShouldNotBeNull();
        nodeDto.Name.ShouldBe("node");
        nodeDto.GetProperty("node").ShouldBe("node-value");

        nodeDto.Parent.ShouldNotBeNull();
        nodeDto.Parent.Name.ShouldBe("parentNode");
        nodeDto.Parent.GetProperty("node").ShouldBe("parent-value");
    }
Example #22
0
        public async Task CreateCountry_OrganizationNotFound_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newCountry = new NodeDto
            {
                Id         = 2,
                Name       = "Canada",
                Type       = "Country",
                Properties = new NodePropertiesDto
                {
                    Code = "1234"
                },
                ParentId = 2
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.CreateNodeAsync(newCountry);

            var expectResult = new ServiceResult($"Organization with id: {newCountry.ParentId} - not found.");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(6, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #23
0
        public async Task CreateBusiness_IsSuccessful()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newBusiness = new NodeDto
            {
                Id       = 2,
                Name     = "Internet",
                Type     = "Business",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var result = await _treeService.CreateNodeAsync(newBusiness);

            var actualBusiness = (await _treeService.GetTreeAsync())[3];

            Assert.True(result.Succeeded);
            Assert.Equal(newBusiness.Id, actualBusiness.Id);
            Assert.Equal(newBusiness.Name, actualBusiness.Name);
            Assert.Equal(newBusiness.ParentId, actualBusiness.ParentId);
            Assert.Equal(newBusiness.Type, actualBusiness.Type);
        }
Example #24
0
        public async Task CreateDepartment_OfferingNotFound_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newDepartment = new NodeDto
            {
                Id       = 2,
                Name     = "Service",
                Type     = "Department",
                ParentId = 2
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.CreateNodeAsync(newDepartment);

            var expectResult = new ServiceResult($"Offering with id: {newDepartment.ParentId} - not found.");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(6, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #25
0
        public async Task CreateFamily_IsSuccessful()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newFamily = new NodeDto
            {
                Id       = 2,
                Name     = "Fast food",
                Type     = "Family",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var result = await _treeService.CreateNodeAsync(newFamily);

            var actualFamily = (await _treeService.GetTreeAsync())[4];

            Assert.True(result.Succeeded);
            Assert.Equal(newFamily.Id, actualFamily.Id);
            Assert.Equal(newFamily.Name, actualFamily.Name);
            Assert.Equal(newFamily.ParentId, actualFamily.ParentId);
            Assert.Equal(newFamily.Type, actualFamily.Type);
        }
        public void GetEntityNotifications()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repo = new NotificationsRepository(unitOfWork))
            {
                var node1 = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
                };
                unitOfWork.Database.Insert(node1);
                var entity1 = Mock.Of <IEntity>(e => e.Id == node1.NodeId);
                var node2   = new NodeDto {
                    CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0
                };
                unitOfWork.Database.Insert(node2);
                var entity2 = Mock.Of <IEntity>(e => e.Id == node2.NodeId);

                for (var i = 0; i < 10; i++)
                {
                    var userDto = new UserDto {
                        ContentStartId = -1, Email = "test" + i, Login = "******" + i, MediaStartId = -1, Password = "******", Type = 1, UserName = "******" + i, UserLanguage = "en"
                    };
                    unitOfWork.Database.Insert(userDto);
                    var userNew      = Mock.Of <IUser>(e => e.Id == userDto.Id);
                    var notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
                }

                var notifications = repo.GetEntityNotifications(entity1);

                Assert.AreEqual(5, notifications.Count());
            }
        }
Example #27
0
        public async Task CreateOffering_IsSuccessful()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var newOffering = new NodeDto
            {
                Id       = 2,
                Name     = "Pizza",
                Type     = "Offering",
                ParentId = 1
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var result = await _treeService.CreateNodeAsync(newOffering);

            var actualOffering = (await _treeService.GetTreeAsync())[5];

            Assert.True(result.Succeeded);
            Assert.Equal(newOffering.Id, actualOffering.Id);
            Assert.Equal(newOffering.Name, actualOffering.Name);
            Assert.Equal(newOffering.ParentId, actualOffering.ParentId);
            Assert.Equal(newOffering.Type, actualOffering.Type);
        }
Example #28
0
    /// <summary>
    ///     Does a quick check on the entity's set path to ensure that it's valid and consistent
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    public static void ValidatePathWithException(this NodeDto entity)
    {
        // don't validate if it's empty and it has no id
        if (entity.NodeId == default && entity.Path.IsNullOrWhiteSpace())
        {
            return;
        }

        if (entity.Path.IsNullOrWhiteSpace())
        {
            throw new InvalidDataException(
                      $"The content item {entity.NodeId} has an empty path: {entity.Path} with parentID: {entity.ParentId}");
        }

        var pathParts = entity.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries);

        if (pathParts.Length < 2)
        {
            // a path cannot be less than 2 parts, at a minimum it must be root (-1) and it's own id
            throw new InvalidDataException(
                      $"The content item {entity.NodeId} has an invalid path: {entity.Path} with parentID: {entity.ParentId}");
        }

        if (entity.ParentId != default && pathParts[^ 2] != entity.ParentId.ToInvariantString())
        {
            // the 2nd last id in the path must be it's parent id
            throw new InvalidDataException(
                      $"The content item {entity.NodeId} has an invalid path: {entity.Path} with parentID: {entity.ParentId}");
        }
    }
Example #29
0
        public void Delete_By_User()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                var repo = new NotificationsRepository((IScopeAccessor)provider);

                var userDto = new UserDto {
                    Email = "test", Login = "******", Password = "******", UserName = "******", UserLanguage = "en", CreateDate = DateTime.Now, UpdateDate = DateTime.Now
                };
                ScopeAccessor.AmbientScope.Database.Insert(userDto);

                IUser userNew   = Mock.Of <IUser>(e => e.Id == userDto.Id);
                IUser userAdmin = Mock.Of <IUser>(e => e.Id == Constants.Security.SuperUserId);

                for (int i = 0; i < 10; i++)
                {
                    var node = new NodeDto {
                        CreateDate = DateTime.Now, Level = 1, NodeObjectType = Constants.ObjectTypes.ContentItem, ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = -1
                    };
                    object       result       = ScopeAccessor.AmbientScope.Database.Insert(node);
                    IEntity      entity       = Mock.Of <IEntity>(e => e.Id == node.NodeId);
                    Notification notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
                }

                int delCount = repo.DeleteNotifications(userAdmin);

                Assert.AreEqual(5, delCount);
            }
        }
Example #30
0
        public async Task CreateOrganization_WrongNodeType_IsFailed()
        {
            _treeService = GetTreeService();

            var newOrganization = new NodeDto
            {
                Id         = 1,
                Name       = "Organization1",
                Type       = "Home",
                Properties = new NodePropertiesDto
                {
                    Code              = "1234",
                    OrganizationType  = OrganizationType.LimitedLiabilityCompany,
                    OrganizationOwner = "Mr. Bin"
                },
                ParentId = 0
            };

            var actualResult = await _treeService.CreateNodeAsync(newOrganization);

            var expectResult = new ServiceResult($"Not found such type as: {newOrganization.Type}");

            var actualListOfNodes = await _treeService.GetTreeAsync();

            Assert.Equal(0, actualListOfNodes.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Example #31
0
 /// <summary>
 /// Inserts node over node contract client.
 /// </summary>
 /// <param name="dto">Node dto which has to be inserted.</param>
 public void InsertNode(NodeDto dto)
 {
     _ncc.InsertNode(dto);
 }
Example #32
0
 /// <summary>
 /// Deletes node over node contract client.
 /// </summary>
 /// <param name="dto">Node dto which has to be deleted.</param>
 public void DeleteNode(NodeDto dto)
 {
     _ncc.DeleteNode(dto);
 }
Example #33
0
 /// <summary>
 /// Updates node over node contract client.
 /// </summary>
 /// <param name="dto">Node dto which has to be updated.</param>
 public void UpdateNode(NodeDto dto)
 {
     _ncc.UpdateNode(dto);
 }