public async Task GetOrganisationByIdReturnsOrganisation()
        {
            var session = EntityHelpers.CreateSession("Admin");

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

            var analyticsEvents = EntityHelpers.CreateAnalyticsEvents().ToList();
            var org             = analyticsEvents[0].Service.Organisation;

            analyticsEvents[1].Service.Organisation   = org;
            analyticsEvents[1].Service.OrganisationId = org.Id;
            DatabaseContext.AddRange(analyticsEvents);
            DatabaseContext.SaveChanges();

            var requestUri = new Uri($"api/v1/analytics-event/?organisationid={org.Id}", UriKind.Relative);
            var response   = await Client.GetAsync(requestUri).ConfigureAwait(true);

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

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

            deserializedBody.Should().NotBeNull();
        }
Пример #2
0
        public void GivenAnIdAndStartDateAllMatchingAnalyticsEventsGetReturned()
        {
            var analyticsEvents = EntityHelpers.CreateAnalyticsEvents().ToList();
            var org             = analyticsEvents[0].Service.Organisation;

            analyticsEvents[1].Service.Organisation   = org;
            analyticsEvents[1].Service.OrganisationId = org.Id;
            analyticsEvents[2].Service.Organisation   = org;
            analyticsEvents[2].Service.OrganisationId = org.Id;
            analyticsEvents[0].TimeStamp = new DateTime(2020, 4, 11, 11, 0, 0);
            analyticsEvents[1].TimeStamp = new DateTime(2020, 4, 11, 11, 0, 0);
            analyticsEvents[2].TimeStamp = new DateTime(2020, 1, 11, 11, 0, 0);
            var startDate = new DateTime(2020, 4, 11, 10, 0, 0);

            DatabaseContext.AddRange(analyticsEvents);
            DatabaseContext.SaveChanges();
            var analyticsEventQuery = new AnalyticsEventQuery
            {
                OrganisationId = org.Id,
                StartDateTime  = startDate
            };
            var gatewayResult  = _classUnderTest.GetAnalyticsEvents(analyticsEventQuery);
            var expectedResult = DatabaseContext.AnalyticsEvents
                                 .Where(x => x.Service.OrganisationId == analyticsEventQuery.OrganisationId)
                                 .Where(x => x.TimeStamp >= analyticsEventQuery.StartDateTime);

            gatewayResult.Should().NotBeNull();
            gatewayResult.Should().BeEquivalentTo(expectedResult, options =>
            {
                options.Excluding(ex => ex.Service);
                return(options);
            });
            gatewayResult.Count.Should().Be(2);
        }
        public async Task GetanalyticsEventWithExpiredSessionReturnsNotAuthorised()
        {
            var session = EntityHelpers.CreateSession("Admin");

            session.LastAccessAt = DateTime.Today.AddDays(-2);
            DatabaseContext.Sessions.Add(session);
            Client.DefaultRequestHeaders.Add("Cookie", $"access_token={session.Payload}");
            var analyticsEvents = EntityHelpers.CreateAnalyticsEvents().ToList();
            var org             = analyticsEvents[0].Service.Organisation;

            analyticsEvents[1].Service.Organisation   = org;
            analyticsEvents[1].Service.OrganisationId = org.Id;
            DatabaseContext.AddRange(analyticsEvents);
            DatabaseContext.SaveChanges();

            var requestUri = new Uri($"api/v1/analytics-event/?{org.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);
        }