Beispiel #1
0
        public void ReturnsCorrectResponseWhenEverythingIsWorking()
        {
            var token = "token";

            var usageReportResponse = new UsageReportResponse
            {
                StartDate             = "2020-08-01",
                EndDate               = "2020-08-31",
                UniqueAnonymousUsers  = 1,
                TotalAnonymousLogins  = 2,
                UniqueCSSOUsers       = 3,
                TotalCSSOLogins       = 4,
                NewCSSOLinkedAccounts = 5,
                TotalLogins           = 6
            };

            var usageReportRequest = new UsageReportRequest
            {
                StartDate = Convert.ToDateTime("2020-08-01"),
                EndDate   = Convert.ToDateTime("2020-08-31")
            };

            _mockCrmTokenGateway.Setup(x => x.GetCRMToken()).ReturnsAsync(token);
            _mockCrmGateway.Setup(x => x.GetUniqueAnonymousUsers(usageReportRequest, token)).ReturnsAsync(1);
            _mockCrmGateway.Setup(x => x.GetTotalAnonymousLogins(usageReportRequest)).ReturnsAsync(2);
            _mockCrmGateway.Setup(x => x.GetUniqueCSSOUsers(usageReportRequest)).ReturnsAsync(3);
            _mockCrmGateway.Setup(x => x.GetTotalCSSOLogins(usageReportRequest)).ReturnsAsync(4);
            _mockCrmGateway.Setup(x => x.GetNewCSSOLinkedAccounts(usageReportRequest)).ReturnsAsync(5);
            _mockCrmGateway.Setup(x => x.GetTotalLogins(usageReportRequest)).ReturnsAsync(6);

            var response = _classUnderTest.Execute(usageReportRequest);

            response.Should().NotBeNull();
            response.Result.Should().BeEquivalentTo(usageReportResponse);
        }
        public async Task <UsageReportResponse> Execute(UsageReportRequest usageReportRequest)
        {
            if (!CRMFactory.ValidateUsageReportRequest(usageReportRequest))
            {
                throw new UsageReportRequestException("Start date must be before end date");
            }
            var token = await _crmTokenGateway.GetCRMToken();

            var uniqueAnonymousUsers = await _crmGateway.GetUniqueAnonymousUsers(usageReportRequest, token);

            var totalAnonymousLogins = await _crmGateway.GetTotalAnonymousLogins(usageReportRequest);

            var uniqueCSSOUsers = await _crmGateway.GetUniqueCSSOUsers(usageReportRequest);

            var totalCSSOLogins = await _crmGateway.GetTotalCSSOLogins(usageReportRequest);

            var newCSSOLinkedAccounts = await _crmGateway.GetNewCSSOLinkedAccounts(usageReportRequest);

            var totalLogins = await _crmGateway.GetTotalLogins(usageReportRequest);

            return(new UsageReportResponse
            {
                StartDate = usageReportRequest.StartDate.ToString("yyyy-MM-dd"),
                EndDate = usageReportRequest.EndDate.ToString("yyyy-MM-dd"),
                UniqueAnonymousUsers = uniqueAnonymousUsers,
                TotalAnonymousLogins = totalAnonymousLogins,
                UniqueCSSOUsers = uniqueCSSOUsers,
                TotalCSSOLogins = totalCSSOLogins,
                NewCSSOLinkedAccounts = newCSSOLinkedAccounts,
                TotalLogins = totalLogins
            });
        }
Beispiel #3
0
 public static bool ValidateUsageReportRequest(UsageReportRequest usageReportRequest)
 {
     if (usageReportRequest.StartDate > usageReportRequest.EndDate)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #4
0
        public void CheckUsageReportRequestInValidDateCheck()
        {
            var usageReportRequest = new UsageReportRequest
            {
                StartDate = Convert.ToDateTime("2020-09-01"),
                EndDate   = Convert.ToDateTime("2020-08-31")
            };

            var response = CRMFactory.ValidateUsageReportRequest(usageReportRequest);

            response.Should().Be(false);
        }
Beispiel #5
0
        public static string BuildLinkedAccountReportFetchXML(UsageReportRequest usageReportRequest)
        {
            var fetchXML = $@"<fetch aggregate='true' >
                  <entity name='hackney_csso_linked_rent_account' >
                    <attribute name='hackney_csso_linked_rent_accountid' alias='recordcount' aggregate='count' />
                    <filter>
                            <condition attribute='createdon' operator='on-or-after' value='{usageReportRequest.StartDate:yyyy-MM-dd}' />
                            <condition attribute='createdon' operator='on-or-before' value='{usageReportRequest.EndDate:yyyy-MM-dd}' />
                    </filter>
                  </entity>
                </fetch>";

            return(BuildDictionaryString(fetchXML));
        }
        public async Task <int?> GetTotalLogins(UsageReportRequest usageReportRequest)
        {
            var fetchXML = FetchXMLBuilder.BuildResidentAuditFetchXML(true, "", usageReportRequest);
            var builder  = new UriBuilder()
            {
                Query = fetchXML
            };

            var response = await _client.GetAsync(new Uri("hackney_housingaccountaudits" + builder.Query, UriKind.Relative)).ConfigureAwait(true);

            var content = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

            var jsonResponse = JsonConvert.DeserializeObject <JObject>(await response.Content.ReadAsStringAsync());

            if (jsonResponse["value"].HasValues)
            {
                var accountId = jsonResponse["value"].FirstOrDefault()["recordcount"].ToString();
                return(Int32.Parse(accountId));
            }
            return(null);
        }
        public async Task <int?> GetUniqueAnonymousUsers(UsageReportRequest usageReportRequest, string token)
        {
            var fetchXML = FetchXMLBuilder.BuildResidentAuditFetchXML(true, "Anonymous", usageReportRequest);
            var builder  = new UriBuilder()
            {
                Query = fetchXML
            };

            _client.DefaultRequestHeaders.Add("Authorization", token);

            var response = await _client.GetAsync(new Uri("hackney_housingaccountaudits" + builder.Query, UriKind.Relative)).ConfigureAwait(true);

            var content = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

            var jsonResponse = JsonConvert.DeserializeObject <JObject>(await response.Content.ReadAsStringAsync());

            if (jsonResponse["value"].HasValues)
            {
                var recordCount = jsonResponse["value"].FirstOrDefault()["recordcount"].ToString();
                return(Int32.Parse(recordCount));
            }
            return(null);
        }
        public async Task <IActionResult> RunUsageReport([FromQuery] UsageReportRequest usageReportRequest)
        {
            try
            {
                var response = await _usageReportingUseCase.Execute(usageReportRequest);

                return(Ok(response));
            }
            catch (UsageReportRequestException ex)
            {
                LambdaLogger.Log(ex.Message);
                return(BadRequest(ex.Message));
            }
            catch (MissingQueryParameterException e)
            {
                LambdaLogger.Log(e.Message);
                return(BadRequest(e.Message));
            }
            catch (Exception ex)
            {
                LambdaLogger.Log(ex.Message);
                return(StatusCode(500, "An error has occured"));
            }
        }
Beispiel #9
0
        public static string BuildResidentAuditFetchXML(bool isDistinct, string queryValue, UsageReportRequest usageReportRequest)
        {
            var fetchXML = $@"<fetch aggregate='true' >
                  <entity name='hackney_housingaccountaudit' >
                    <attribute name='hackney_accountnumber' alias='recordcount' {(isDistinct ? "aggregate='countcolumn'  distinct='true'" : "aggregate='count'")}  />
                    <filter>
                            <condition attribute='createdon' operator='on-or-after' value='{usageReportRequest.StartDate:yyyy-MM-dd}' />
                            <condition attribute='createdon' operator='on-or-before' value='{usageReportRequest.EndDate:yyyy-MM-dd}' />
                      {(!string.IsNullOrEmpty(queryValue) ? $"<condition attribute='hackney_name' operator='like' value='{queryValue}%' />" : "")}
                    </filter>
                  </entity>
                </fetch>";

            return(BuildDictionaryString(fetchXML));
        }