Пример #1
0
        public async Task PatchOrganisationUpdatesOrganisation()
        {
            var session = EntityHelpers.CreateSession("Admin");

            DatabaseContext.Sessions.Add(session);
            Client.DefaultRequestHeaders.Add("Cookie", $"access_token={session.Payload}");
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Organisations.Add(organisation);
            DatabaseContext.SaveChanges();
            var updOrganisation = new OrganisationRequest();

            updOrganisation.Name            = Randomm.Text();
            updOrganisation.ReviewerMessage = null; // we are assuming null means no change to the record
            var         organisationString = JsonConvert.SerializeObject(updOrganisation);
            HttpContent patchContent       = new StringContent(organisationString, Encoding.UTF8, "application/json");
            var         requestUri         = new Uri($"api/v1/organisations/{organisation.Id}", UriKind.Relative);
            var         response           = await Client.PatchAsync(requestUri, patchContent).ConfigureAwait(false);

            patchContent.Dispose();
            response.StatusCode.Should().Be(200);
            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <OrganisationResponse>(stringResponse);
            var organisationId   = deserializedBody.Id;
            var dbOrganisation   = DatabaseContext.Organisations.Find(organisationId);

            dbOrganisation.Should().NotBeNull();
            dbOrganisation.Name.Should().Be(organisation.Name);
            dbOrganisation.ReviewerMessage.Should().Be(organisation.ReviewerMessage);  //should not be set to null if not changed
        }
        public void GivenSearchParametersStatusFilterUpperCaseMatchingOrganisationsGetReturned()
        {
            var organisations = EntityHelpers.CreateOrganisations(10).ToList();
            var orgToFind     = EntityHelpers.CreateOrganisation();

            orgToFind.Status = "published";
            organisations.Add(orgToFind);
            DatabaseContext.AddRange(organisations);
            DatabaseContext.SaveChanges();
            var searchParams = new OrganisationSearchRequest();

            searchParams.Search    = orgToFind.Name;
            searchParams.Sort      = "Name";
            searchParams.Status    = "PUBLISHED";
            searchParams.Direction = SortDirection.Asc.ToString();
            var gatewayResult = _classUnderTest.SearchOrganisations(searchParams).Result;

            gatewayResult.Should().NotBeNull();
            gatewayResult.First().Should().BeEquivalentTo(orgToFind, options =>
            {
                options.Excluding(ex => ex.ReviewerU);
                options.Excluding(ex => ex.Services);
                options.Excluding(ex => ex.UserOrganisations);
                return(options);
            });
        }
Пример #3
0
 private Organisation CreateOrganisation()
 {
     _organisation       = EntityHelpers.CreateOrganisation();
     _organisationDomain = _organisationsGateway.CreateOrganisation(_organisation);
     _organisation       = _mapper.FromDomain(_organisationDomain);
     return(_organisation);
 }
Пример #4
0
 public void GivenInvalidOrganisationIdOnCreateExceptionWillBeThrown()
 {
     _organisation    = EntityHelpers.CreateOrganisation();
     _organisation.Id = 999999999;
     _classUnderTest.Invoking(c => c.LinkUserToOrganisation(_organisation.Id, CreateUser().Id))
     .Should()
     .Throw <Exception>();
 }
        public void GivenAnIdAMatchingOrganisationGetsDeleted()
        {
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Add(organisation);
            DatabaseContext.SaveChanges();
            _classUnderTest.DeleteOrganisation(organisation.Id);
            var expectedResult = DatabaseContext.Organisations.Find(organisation.Id);

            expectedResult.Should().BeNull();
        }
        public void GivenOrganisationDomainObjectOrganisationGetsCreated()
        {
            var organisation   = EntityHelpers.CreateOrganisation();
            var gatewayResult  = _classUnderTest.CreateOrganisation(organisation);
            var expectedResult = DatabaseContext.Organisations.Where(x => x.Name == organisation.Name).FirstOrDefault();

            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(expectedResult, options =>
            {
                options.Excluding(ex => ex.ReviewerU);
                options.Excluding(ex => ex.Services);
                options.Excluding(ex => ex.UserOrganisations);
                return(options);
            });
        }
        public async Task GetOrganisationWithExpiredSessionReturnsNotAuthorised()
        {
            var session = EntityHelpers.CreateSession("Admin");

            session.LastAccessAt = DateTime.Today.AddDays(-2);
            DatabaseContext.Sessions.Add(session);
            Client.DefaultRequestHeaders.Add("Cookie", $"access_token={session.Payload}");
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Organisations.Add(organisation);
            DatabaseContext.SaveChanges();
            var requestUri = new Uri($"api/v1/organisations/{organisation.Id}", UriKind.Relative);
            var response   = await Client.GetAsync(requestUri).ConfigureAwait(false);

            response.StatusCode.Should().Be(401);
            DatabaseContext.Sessions.Count(s => s.UserId == session.UserId).Should().Be(0);
        }
        public void GivenAnIdAMatchingOrganisationGetsReturned()
        {
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Add(organisation);
            DatabaseContext.SaveChanges();
            var gatewayResult  = _classUnderTest.GetOrganisation(organisation.Id);
            var expectedResult = DatabaseContext.Organisations.Find(organisation.Id);

            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(expectedResult, options =>
            {
                options.Excluding(ex => ex.ReviewerU);
                options.Excluding(ex => ex.Services);
                options.Excluding(ex => ex.UserOrganisations);
                return(options);
            });
        }
        public void GivenSearchParametersStatusFilterNoMatchingOrganisationsGetReturned()
        {
            var organisations = EntityHelpers.CreateOrganisations(10).ToList();
            var orgToFind     = EntityHelpers.CreateOrganisation();

            orgToFind.Status = "published";
            organisations.Add(orgToFind);
            DatabaseContext.AddRange(organisations);
            DatabaseContext.SaveChanges();
            var searchParams = new OrganisationSearchRequest();

            searchParams.Search    = orgToFind.Name;
            searchParams.Sort      = "Name";
            searchParams.Status    = "rejected";
            searchParams.Direction = SortDirection.Asc.ToString();
            var gatewayResult = _classUnderTest.SearchOrganisations(searchParams).Result;

            gatewayResult.Should().NotBeNull();
            gatewayResult.Count.Should().Be(0);
        }
        public void GivenAnOrganisationAMatchingOrganisationGetsUpdated()
        {
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Add(organisation);
            DatabaseContext.SaveChanges();
            var organisationDomain = _mapper.ToDomain(organisation);

            organisationDomain.Name = Randomm.Text();
            _classUnderTest.PatchOrganisation(organisationDomain);
            var expectedResult = DatabaseContext.Organisations.Find(organisation.Id);

            expectedResult.Should().BeEquivalentTo(organisationDomain, options =>
            {
                options.Excluding(ex => ex.ReviewerU);
                options.Excluding(ex => ex.Services);
                options.Excluding(ex => ex.UserOrganisations);
                options.Excluding(ex => ex.StatusMessage);
                return(options);
            });
        }
        public async Task GetOrganisationByIdReturnsOrganisation()
        {
            var session = EntityHelpers.CreateSession("Admin");

            DatabaseContext.Sessions.Add(session);
            Client.DefaultRequestHeaders.Add("Cookie", $"access_token={session.Payload}");
            var organisation = EntityHelpers.CreateOrganisation();

            DatabaseContext.Organisations.Add(organisation);
            DatabaseContext.SaveChanges();
            var requestUri = new Uri($"api/v1/organisations/{organisation.Id}", UriKind.Relative);
            var response   = await Client.GetAsync(requestUri).ConfigureAwait(false);

            response.StatusCode.Should().Be(200);
            var content        = response.Content;
            var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true);

            var deserializedBody = JsonConvert.DeserializeObject <OrganisationResponse>(stringResponse);

            deserializedBody.Should().NotBeNull();
        }