示例#1
0
        public async void handle_Exception_test()
        {
            Project             returnn = new Project();
            OrganisationProject op      = new OrganisationProject();
            ProjectCategory     pc      = new ProjectCategory();
            ProjectResearcher   pr      = new ProjectResearcher();

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Update(It.IsAny <Project>())).Returns(returnn);
            this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteProjectOrganisation(It.IsAny <int>()))
            .Returns(true);
            this._unitOfUnitMock.Setup(mock =>
                                       mock.RelationsRepository.CreateOrganisationProject(It.IsAny <OrganisationProject>())).Returns(op);
            this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteCategoriesProject(It.IsAny <int>()))
            .Returns(true);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.DeleteProjectResearcherWithProjectId(It.IsAny <int>()))
            .Returns(true);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectResearcher(It.IsAny <ProjectResearcher>()))
            .Throws(new Exception());

            UpdateProjectCommand command = new UpdateProjectCommand(new CreateProjectModel()
            {
                ProjectName = "test",
                Categories  = new List <Category>()
                {
                    new Category()
                    {
                        CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1
                    }
                },
                ResearcherCategories = new List <ResearcherCategory>()
                {
                    new ResearcherCategory()
                    {
                        Researcher = new Researcher()
                        {
                            Id = 1
                        }, Category = new Category()
                        {
                            Id = 1
                        }
                    }
                },
                Organisations = new List <Organisation>()
                {
                    new Organisation()
                    {
                        Id = 1,
                    }
                }
            });
            UpdateProjectHandler handler = new UpdateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Null(result);
        }
        public async void handle_Succes_test()
        {
            Project project = new Project()
            {
                Id = 1
            };
            ProjectCategory     pc = new ProjectCategory();
            ProjectResearcher   pr = new ProjectResearcher();
            OrganisationProject op = new OrganisationProject();

            this._unitOfUnitMock.Setup(mock => mock.ProjectRepository.Create(It.IsAny <Project>())).Returns(project);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectCategory(It.IsAny <ProjectCategory>())).Returns(pc);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateProjectResearcher(It.IsAny <ProjectResearcher>()))
            .Returns(pr);
            this._unitOfUnitMock.Setup(mock =>
                                       mock.RelationsRepository.CreateOrganisationProject(It.IsAny <OrganisationProject>())).Returns(op);

            CreateProjectCommand command = new CreateProjectCommand(
                new CreateProjectModel()
            {
                ProjectName = "test",
                Categories  = new List <Category>()
                {
                    new Category()
                    {
                        CategoryId = 1, CategoryName = "test", Created = DateTime.Now, Id = 1
                    }
                },
                ResearcherCategories = new List <ResearcherCategory>()
                {
                    new ResearcherCategory()
                    {
                        Researcher = new Researcher()
                        {
                            Id = 1
                        }, Category = new Category()
                        {
                            Id = 1
                        }
                    }
                },
                Organisations = new List <Organisation>()
                {
                    new Organisation()
                    {
                        Id = 1,
                    }
                }
            });
            CreateProjectHandler handler = new CreateProjectHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.Equal(result, project);
        }
示例#3
0
        public async void Handle_FSucces_Test()
        {
            Organisation organisationNull = new Organisation();

            this._unitOfUnitMock.Setup(mock => mock.OrganisationRepository.Update(It.IsAny <Organisation>()))
            .Returns(organisationNull);
            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.DeleteAllOrganisationResearchers(It.IsAny <int>()))
            .Returns(true);

            OrganisationResearcher nullItem = new OrganisationResearcher();

            this._unitOfUnitMock.Setup(mock =>
                                       mock.RelationsRepository.CreateOrganisationResearcher(It.IsAny <OrganisationResearcher>()))
            .Returns(nullItem);

            this._unitOfUnitMock.Setup(mock => mock.RelationsRepository.DeleteAllOrganisationsProjects(It.IsAny <int>()))
            .Returns(true);

            OrganisationProject nullProejct = new OrganisationProject();

            this._unitOfUnitMock
            .Setup(mock => mock.RelationsRepository.CreateOrganisationProject(It.IsAny <OrganisationProject>()))
            .Returns(nullProejct);

            UpdateOrganisationCommand command = new UpdateOrganisationCommand(new OrganisationWithChildren()
            {
                Created            = DateTime.Now,
                OrganisationName   = "s",
                Address            = "s",
                MainOrganisationId = 1,
                ZipCode            = "6700",
                City        = "es",
                Country     = "sad",
                Researchers = new List <ResearcherModel>()
                {
                    new ResearcherModel()
                },
                Projects = new List <ProjectModel>()
                {
                    new ProjectModel()
                }
            });

            var handler = new UpdateOrganisationHandler(this._unitOfUnitMock.Object);

            var result = await handler.Handle(command, new CancellationTokenSource().Token);

            Assert.True((bool)result);
        }
示例#4
0
        public OrganisationProject CreateOrganisationProject(OrganisationProject entity)
        {
            try
            {
                string createOrganisationProjectQuery = "INSERT INTO EIC.dbo.PROJECTORGANISATION (Created, ProjectId,                                               OrganisationId) " +
                                                        "VALUES (@Created, @ProjectId, @OrganisationId); " +
                                                        "SELECT SCOPE_IDENTITY();";

                var result =
                    this._connection.ExecuteScalar <int>(createOrganisationProjectQuery, entity, this._transaction);
                if (result <= 0)
                {
                    return(null);
                }

                entity.Id = result;
                return(entity);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#5
0
        public async Task <object> Handle(CreateProjectCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Project project = new Project();

                project.Created     = DateTime.Now;
                project.ProjectName = request.Model.ProjectName;
                project.StartDate   = request.Model.StartDate; // Check if date is valid
                project.EndDate     = request.Model.EndDate;

                var projectResult = this._projectRepository.Create(project);
                if (projectResult == null)
                {
                    this._unitOfWork.Rollback();
                    return(false);
                }

                foreach (var cat in request.Model.Categories)
                {
                    ProjectCategory projectCategory = new ProjectCategory();
                    projectCategory.Created    = DateTime.Now;
                    projectCategory.CategoryId = cat.Id;
                    projectCategory.ProjectId  = projectResult.Id;

                    var catResult = this._relationsRepository.CreateProjectCategory(projectCategory);
                    if (catResult == null)
                    {
                        this._unitOfWork.Rollback();
                        return(false);
                    }
                }

                foreach (var researcherCategory in request.Model.ResearcherCategories)
                {
                    ProjectResearcher projectResearcher = new ProjectResearcher();
                    projectResearcher.Created      = DateTime.Now;
                    projectResearcher.ResearcherId = researcherCategory.Researcher.Id;
                    projectResearcher.ProjectId    = projectResult.Id;
                    projectResearcher.CategoryId   = researcherCategory.Category.Id;
                    projectResearcher.TitleId      = 1;

                    var researcherResult = this._relationsRepository.CreateProjectResearcher(projectResearcher);
                    if (researcherResult == null)
                    {
                        this._unitOfWork.Rollback();
                        return(false);
                    }
                }

                foreach (var organisation in request.Model.Organisations)
                {
                    OrganisationProject organisationProject = new OrganisationProject();
                    organisationProject.Created        = DateTime.Now;
                    organisationProject.OrganisationId = organisation.Id;
                    organisationProject.ProjectId      = projectResult.Id;

                    var orgaResult = this._relationsRepository.CreateOrganisationProject(organisationProject);
                    if (orgaResult == null)
                    {
                        this._unitOfWork.Rollback();
                        return(false);
                    }
                }

                this._unitOfWork.Commit();
                this._unitOfWork.Dispose();
                this._unitOfWork.QueueUserActivityLogItem(ActivityTypes.Activities.ProjectCreated, projectResult.Id);
                return(projectResult);
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                this._unitOfWork.QueueErrorLogItem(
                    ActivityTypes.Activities.ProjectCreated,
                    ActivityTypes.Areas.CreateProjectHandler,
                    e.Message);
                return(null);
            }
        }
        public async Task <object> Handle(CreateOrganisationCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var organisation = new Organisation();
                organisation.Created          = DateTime.Now;
                organisation.OrganisationName = request.Model.OrganisationName;
                organisation.Address          = request.Model.Address;
                if (request.Model.MainOrganisationId != -1)
                {
                    organisation.MainOrganisationId = request.Model.MainOrganisationId;
                }
                organisation.IsMainOrganisation = request.Model.IsMainOrganisation;
                organisation.EICColaboration    = request.Model.EICColaboration;
                organisation.ZipCode            = request.Model.ZipCode;
                organisation.City    = request.Model.City;
                organisation.Country = request.Model.Country;

                var result = this._organisationRepository.Create(organisation);
                if (result == null)
                {
                    this._unitOfWork.Rollback();
                    return(null);
                }

                if (request.Model.Researchers != null && request.Model.Researchers.Any())
                {
                    foreach (var item in request.Model.Researchers)
                    {
                        var relation = new OrganisationResearcher();
                        relation.Created        = DateTime.Now;
                        relation.OrganisationId = result.Id;
                        relation.ResearcherId   = item.ResearcherId;

                        var result1 = this._relationsRepository.CreateOrganisationResearcher(relation);
                        if (result1 == null)
                        {
                            this._unitOfWork.Rollback();
                            return(null);
                        }
                    }
                }

                if (request.Model.Projects != null && request.Model.Projects.Any())
                {
                    foreach (var item in request.Model.Projects)
                    {
                        var relation = new OrganisationProject();
                        relation.Created        = DateTime.Now;
                        relation.OrganisationId = result.Id;
                        relation.ProjectId      = item.ProjectId;

                        var result2 = this._relationsRepository.CreateOrganisationProject(relation);
                        if (result2 == null)
                        {
                            this._unitOfWork.Rollback();
                            return(null);
                        }
                    }
                }

                this._unitOfWork.Commit();
                this._unitOfWork.Dispose();
                this._unitOfWork.QueueUserActivityLogItem(ActivityTypes.Activities.OrganisationCreated, result.Id);
                return(true);
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                this._unitOfWork.QueueErrorLogItem(
                    ActivityTypes.Activities.OrganisationCreated,
                    ActivityTypes.Areas.CreateOrganisationHandler,
                    e.Message);
                return(null);
            }
        }
示例#7
0
        public async Task <object> Handle(UpdateProjectCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var project = new Project();
                project.Created     = DateTime.Now;
                project.StartDate   = request.Model.StartDate;
                project.EndDate     = request.Model.EndDate;
                project.ProjectName = request.Model.ProjectName;
                project.Id          = request.Model.Id;


                var result = this._projectRepository.Update(project);
                if (result == null)
                {
                    this._unitOfWork.Rollback();
                    return(null);
                }

                // OrganisationProject
                var result1 = this._relationsRepository.DeleteProjectOrganisation(result.Id);
                if (result1 == false)
                {
                    this._unitOfWork.Rollback();
                    return(null);
                }
                foreach (var organisation in request.Model.Organisations)
                {
                    OrganisationProject organisationProject = new OrganisationProject();
                    organisationProject.Created        = DateTime.Now;
                    organisationProject.OrganisationId = organisation.OrganisationId;
                    organisationProject.ProjectId      = result.Id;

                    var orgaResult = this._relationsRepository.CreateOrganisationProject(organisationProject);
                    if (orgaResult == null)
                    {
                        this._unitOfWork.Rollback();
                        return(false);
                    }
                }
                // CategoriesProject
                var result2 = this._relationsRepository.DeleteCategoriesProject(result.Id);
                if (result2 == false)
                {
                    this._unitOfWork.Rollback();
                    return(null);
                }
                foreach (var cat in request.Model.Categories)
                {
                    ProjectCategory projectCategory = new ProjectCategory();
                    projectCategory.Created    = DateTime.Now;
                    projectCategory.CategoryId = cat.CategoryId;
                    projectCategory.ProjectId  = result.Id;

                    var catResult = this._relationsRepository.CreateProjectCategory(projectCategory);
                    if (catResult == null)
                    {
                        this._unitOfWork.Rollback();
                        return(false);
                    }
                }

                var result3 = this._relationsRepository.DeleteProjectResearcherWithProjectId(result.Id);
                if (result3 == false)
                {
                    this._unitOfWork.Rollback();
                    return(null);
                }
                foreach (var researcherCategory in request.Model.ResearcherCategories)
                {
                    ProjectResearcher projectResearcher = new ProjectResearcher();
                    projectResearcher.Created      = DateTime.Now;
                    projectResearcher.ResearcherId = researcherCategory.Researcher.Id;
                    projectResearcher.ProjectId    = result.Id;
                    projectResearcher.CategoryId   = researcherCategory.Category.Id;
                    projectResearcher.TitleId      = 1;

                    var researcherResult = this._relationsRepository.CreateProjectResearcher(projectResearcher);
                    if (researcherResult == null)
                    {
                        this._unitOfWork.Rollback();
                        return(false);
                    }
                }

                this._unitOfWork.Commit();
                this._unitOfWork.Dispose();
                return(true);
            }
            catch (Exception e)
            {
                this._unitOfWork.Rollback();
                return(null);
            }
        }