public async Task RetrieveAlertListTest() { try { this.SetupGetRequests(); AlertSearchParameters objParam = new AlertSearchParameters(); objParam.MaxResults = 50; objParam.PageNumber = 1; var alertList = new ListResult<Alert>(); alertList.Items.Add(new Alert { AlertId = "1" }); this.alertManager.Setup(mokeItem => mokeItem.ListAsync(It.IsNotNull<AlertSearchParameters>())).Returns(Task.FromResult(alertList)); var response = await this.alertController.Get(objParam); var result = await response.ExecuteAsync(new CancellationToken(false)); ListResult<Alert> alerts = null; Assert.IsTrue(result.IsSuccessStatusCode); Assert.IsTrue(result.TryGetContentValue(out alerts)); Assert.AreEqual(alertList.Items, alerts.Items); } finally { this.Dispose(); } }
/// <summary> /// Retrieves the alerts. /// </summary> /// <param name="operationResult">The operation result.</param> /// <param name="filter">The filter.</param> /// <returns> /// The Task /// </returns> private async Task GetAsync(OperationResult<ListResultWithMetadata<Alert>> operationResult, AlertSearchParameters filter) { var alerts = await this.alertManager.ListAsync(filter); operationResult.Content = new ListResultWithMetadata<Alert>(alerts, filter, this.Request.RequestUri); }
/// <summary> /// Retrieves the alerts. /// </summary> /// <param name="filter">The filter.</param> /// <returns> /// Alert task /// </returns> public async Task<ListResult<Alert>> ListAsync(AlertSearchParameters filter) { var alertSearch = new AlertListRequestSearchParameters { PageNumber = filter.PageNumber.RetrievePageNumber(), MaxResults = filter.MaxResults.RetrieveMaxResults(), AlertTypeIds = filter.AlertTypeIds, ApplicationId = string.IsNullOrWhiteSpace(filter.ApplicationId) ? Convert.ToString(this.applicationSettings.ApplicationId, CultureInfo.CurrentCulture) : filter.ApplicationId, OrderBy = filter.OrderBy, ShipId = filter.ShipId, PersonIds = filter.PersonIds, IsTemplate = !string.IsNullOrEmpty(filter.IsTemplate) ? Convert.ToBoolean(filter.IsTemplate, CultureInfo.CurrentCulture) : false, TypeIds = !string.IsNullOrEmpty(filter.TypeId) ? filter.TypeId : null, IsAlert = !string.IsNullOrEmpty(filter.IsAlert) ? Convert.ToBoolean(filter.IsAlert, CultureInfo.CurrentCulture) : (bool?)null, IsRecentAlert = !string.IsNullOrEmpty(filter.IsRecentAlert) ? Convert.ToBoolean(filter.IsRecentAlert, CultureInfo.CurrentCulture) : (bool?)null, IsMessage = !string.IsNullOrWhiteSpace(filter.IsMessage) ? Convert.ToBoolean(filter.IsMessage, CultureInfo.CurrentCulture) : (bool?)null, IsExpiredAlert = !string.IsNullOrWhiteSpace(filter.IsExpiredAlert) ? Convert.ToBoolean(filter.IsExpiredAlert, CultureInfo.CurrentCulture) : (bool?)null, AddedDate = filter.AddedDate }; if (string.IsNullOrWhiteSpace(filter.ShipTime)) { var shipTimeTask = await this.shipTimeRepository.GetByIdAsync(this.applicationSettings.ShipId, null); alertSearch.ShipTime = string.IsNullOrWhiteSpace(shipTimeTask) ? DateTime.Now : DateTime.UtcNow.AddMinutes(Convert.ToDouble(shipTimeTask)); } else { alertSearch.ShipTime = DateTime.Parse(filter.ShipTime, CultureInfo.InvariantCulture); } var alertData = await this.alertRepository.ListAsync(alertSearch); var result = new ListResult<Alert>(); var alerts = new AlertCollection(); foreach (var alertType in alertData.Items) { alerts.Add(MapAlertData(alertType, alertSearch.ShipTime)); } if (!alertSearch.IsExpiredAlert.GetValueOrDefault(false) && !alertSearch.IsTemplate) { var filteredAlerts = alerts.Where(alert => alert.IsActive).ToList(); result.AssignItems(filteredAlerts); result.TotalResults = filteredAlerts.Count; } else { result.AssignItems(alerts); result.TotalResults = alerts.Count; } return result; }
public async Task AlertDataListAsyncTest() { var searchFilter = new AlertSearchParameters { AlertTypeIds = "1", ApplicationId = "3", IsAlert = "true", IsExpiredAlert = "true", IsMessage = "true", IsRecentAlert = "true", IsTemplate = "true", PersonIds = "3", ShipId = "2", TypeId = "2", OrderBy = "AlertTypeIds", PageNumber = 2, ShipTime = "2015-07-10T12:12:12", Parts = "$all", MaxResults = 50 }; this.alertType.Items.Add(new Entities.AlertType { AddedBy = "Ryan", AddedDate = DateTime.Now, AlertTypeId = "1", AllowCheckIn = true, ApplicationId = "2", DepartmentId = "2", Description = "agree", DueDate = DateTime.Now, ExpiryDate = DateTime.Now, IsDenyAshore = true, IsDenyBoarding = true, IsMessage = true, IsOverride = true, IsSoundEnable = true, IsTemplate = true, MessageFrom = "trott", ModifiedBy = "jhone", OrderCode = "33", TemplateName = "edd", TypeId = "3" }); this.alertRepository.Setup(mockItem => mockItem.ListAsync(It.IsNotNull<AlertListRequestSearchParameters>())).Returns(Task.FromResult(this.alertType)); var alert = await this.alertData.ListAsync(searchFilter); var searchQueryString = searchFilter.ToQueryString(); Assert.IsNotNull(alert); Assert.IsTrue(searchQueryString.Contains("AlertTypeIds")); }
/// <summary> /// Retrieves the alerts. /// </summary> /// <param name="filter">The filter.</param> /// <returns> /// visitor task /// </returns> public async Task<ListResult<Alert>> ListAsync(AlertSearchParameters filter) { return await this.alertRepository.ListAsync(filter); }