public async Task <OrganisationWithChildren> ReadOrganisationWithChildren(int id)
        {
            try
            {
                var result = new OrganisationWithChildren();
                result.Projects    = new List <ProjectModel>();
                result.Researchers = new List <ResearcherModel>();
                var parameter = new DynamicParameters();
                parameter.Add("@OrganisationId", id);

                var response = await _connection.QueryAsync <OrganisationWithChildren, ProjectModel, ResearcherModel, OrganisationWithChildren>
                                   ("USP_ReadOrganisationWithChildren @OrganisationId",
                                   (organisation, project, researcher) =>
                {
                    result.Id                 = organisation.Id;
                    result.Created            = organisation.Created;
                    result.OrganisationName   = organisation.OrganisationName;
                    result.Address            = organisation.Address;
                    result.MainOrganisationId = organisation.MainOrganisationId;
                    result.IsMainOrganisation = organisation.IsMainOrganisation;
                    result.EICColaboration    = organisation.EICColaboration;
                    result.ZipCode            = organisation.ZipCode;
                    result.City               = organisation.City;
                    result.Country            = organisation.Country;
                    result.Researchers        = result.Researchers ?? new List <ResearcherModel>();
                    result.Projects           = result.Projects ?? new List <ProjectModel>();

                    var lookupOrganisation = result;

                    if (project != null)
                    {
                        if (!lookupOrganisation.Projects.Any(x => x.ProjectId == project.ProjectId))
                        {
                            lookupOrganisation.Projects.Add(project);
                        }
                    }

                    if (researcher != null)
                    {
                        if (!lookupOrganisation.Researchers.Any(x => x.ResearcherId == researcher.ResearcherId))
                        {
                            lookupOrganisation.Researchers.Add(researcher);
                        }
                    }

                    return(null);
                }, splitOn : "ProjectId,ResearcherId", transaction : this._transaction, param : parameter);

                if (result == null)
                {
                    return(null);
                }

                return(result);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public async void CreateOrganisationCommand_OrganisationNameEmpty_Test()
        {
            OrganisationWithChildren model = new OrganisationWithChildren();

            model.Created          = DateTime.Now;
            model.OrganisationName = "";

            Assert.Throws <ArgumentNullException>(() => new CreateOrganisationCommand(model));
        }
        public async void CreateOrganisationCommand_MainOrganisationIdHigh_Test()
        {
            OrganisationWithChildren model = new OrganisationWithChildren();

            model.Created            = DateTime.Now;
            model.OrganisationName   = "asd";
            model.Address            = "asd";
            model.IsMainOrganisation = true;
            model.MainOrganisationId = 1;

            Assert.Throws <ArgumentOutOfRangeException>(() => new CreateOrganisationCommand(model));
        }
        public async void CreateOrganisationCommand_MainOrganisationIdLow_Test()
        {
            OrganisationWithChildren model = new OrganisationWithChildren();

            model.Created            = DateTime.Now;
            model.OrganisationName   = "asd";
            model.Address            = "asd";
            model.IsMainOrganisation = false;
            model.MainOrganisationId = -1;

            Assert.Throws <ArgumentNullException>(() => new CreateOrganisationCommand(model));
        }
Example #5
0
        public async void UpdateOrganisationCommand_CityNull_Test()
        {
            OrganisationWithChildren model = new OrganisationWithChildren();

            model.Created            = DateTime.Now;
            model.OrganisationName   = "asd";
            model.Address            = "asd";
            model.IsMainOrganisation = false;
            model.MainOrganisationId = 1;
            model.ZipCode            = "asd";
            model.City = "";

            Assert.Throws <ArgumentNullException>(() => new UpdateOrganisationCommand(model));
        }
        public async void Handle_Succes_Test()
        {
            OrganisationWithChildren resultpre = new OrganisationWithChildren();

            this._unitOfUnitMock
            .Setup(mock => mock.OrganisationRepository.ReadOrganisationWithChildren(It.IsAny <int>()))
            .Returns(Task.FromResult(resultpre));

            var command = new ReadOrganisationWithChildrenCommand(1);
            var handler = new ReadOrganisationWithChildrenHandler(this._unitOfUnitMock.Object);

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

            Assert.Equal(result, resultpre);
        }
        public async Task <IActionResult> UpdateOrganisation([FromBody] OrganisationWithChildren organisation)
        {
            if (organisation == null)
            {
                return(new BadRequestObjectResult("Invalid Model"));
            }

            var command = new UpdateOrganisationCommand(organisation);

            var result = await this._mediator.Send(command);

            if (result == null)
            {
                return(new BadRequestObjectResult("Something went wrong"));
            }

            return(new OkObjectResult(result));
        }
        public CreateOrganisationCommand(OrganisationWithChildren model)
        {
            if (model.Created == null)
            {
                throw new ArgumentNullException(nameof(model.Created));
            }
            if (String.IsNullOrWhiteSpace(model.OrganisationName))
            {
                throw new ArgumentNullException(nameof(model.OrganisationName));
            }
            if (String.IsNullOrWhiteSpace(model.Address))
            {
                throw new ArgumentNullException(nameof(model.Address));
            }
            if (!model.IsMainOrganisation && model.MainOrganisationId <= 0)
            {
                throw new ArgumentNullException(nameof(model.MainOrganisationId));
            }
            if (model.IsMainOrganisation && model.MainOrganisationId > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(model.MainOrganisationId));
            }
            if (String.IsNullOrWhiteSpace(model.ZipCode))
            {
                throw new ArgumentNullException(nameof(model.ZipCode));
            }
            if (String.IsNullOrWhiteSpace(model.City))
            {
                throw new ArgumentNullException(nameof(model.City));
            }
            if (String.IsNullOrWhiteSpace(model.Country))
            {
                throw new ArgumentNullException(nameof(model.Country));
            }

            this.Model = model;
        }
        public async void CreateOrganisationCommand_CreatedNull_Test()
        {
            OrganisationWithChildren model = new OrganisationWithChildren();

            Assert.Throws <ArgumentNullException>(() => new CreateOrganisationCommand(model));
        }