Exemplo n.º 1
0
        public void GetReportsShouldReturnAllReports()
        {
            var reportRepo = new Mock <IRepository <Report> >();

            reportRepo.Setup(r => r.All()).Returns(new List <Report>
            {
                new Report
                {
                    Reporter     = new User(),
                    ReportedUser = new User(),
                },
                new Report
                {
                    Reporter     = new User(),
                    ReportedUser = new User(),
                },
                new Report
                {
                    Reporter = new User()
                    {
                        UserName = "******"
                    },
                    ReportedUser = new User(),
                },
            }.AsQueryable());

            var service = new ReportsService(reportRepo.Object, null);
            var reports = service.GetReports();

            Assert.Equal(3, reports.Count);
            reportRepo.Verify(r => r.All(), Times.Once);
        }
Exemplo n.º 2
0
        private async void GetTTReports()
        {
            IsRefreshing = true;
            Device.BeginInvokeOnMainThread(async() =>
            {
                await Alerts.ShowLoadingPageAsync("Obteniendo reportes");
            });

            Response response = await ReportsService.GetReports(App.CurrentUser.UserID);

            if (response.Result != Result.NETWORK_UNAVAILABLE)
            {
                if (response.Result == Result.ERROR_GETTING_DATA)
                {
                    await Alerts.HideLoadingPageAsync();

                    Alerts.ShowAlert(string.Empty, "Error al obtener datos del servidor");
                }
                else if (response.Result == Result.SERVICE_EXCEPTION)
                {
                    await Alerts.HideLoadingPageAsync();

                    Alerts.ShowAlert(string.Empty, "Error al obtener datos del dispositivo (SE)");
                }
                else if (response.Result == Result.OK)
                {
                    if (response.Data != null)
                    {
                        APIAvailableItems = JsonConvert.DeserializeObject <List <WSReport> >(response.Data);
                        Items             = new ObservableCollection <WSReport>(APIAvailableItems);
                        PrefilteredItems  = APIAvailableItems;

                        GroupIDs = APIAvailableItems.Where(a => !string.IsNullOrEmpty(a.GroupID)).Select(b => b.GroupID).ToList();

                        await Alerts.HideLoadingPageAsync();
                    }
                    else
                    {
                        await Alerts.HideLoadingPageAsync();

                        Alerts.ShowAlert(string.Empty, "Error al parsear los datos");
                    }
                }
            }
            else
            {
                await Alerts.HideLoadingPageAsync();

                Alerts.ShowNetworkError();
            }



            IsRefreshing = false;
        }
Exemplo n.º 3
0
        public void GetReportsShouldReturnAllReportsOrderedDescendingByDate()
        {
            var reportRepo = new Mock <IRepository <Report> >();

            reportRepo.Setup(r => r.All()).Returns(new List <Report>
            {
                new Report
                {
                    Reporter       = new User(),
                    ReportedUser   = new User(),
                    DateOfCreation = DateTime.Now.AddDays(1),
                    Details        = "3"
                },
                new Report
                {
                    Reporter       = new User(),
                    ReportedUser   = new User(),
                    DateOfCreation = DateTime.Now.AddDays(3),
                    Details        = "1"
                },
                new Report
                {
                    Reporter = new User()
                    {
                        UserName = "******"
                    },
                    ReportedUser   = new User(),
                    DateOfCreation = DateTime.Now.AddDays(2),
                    Details        = "2"
                },
            }.AsQueryable());

            var service = new ReportsService(reportRepo.Object, null);
            var reports = service.GetReports().ToList();

            Assert.Equal(3, reports.Count);
            reportRepo.Verify(r => r.All(), Times.Once);

            Assert.Equal("1", reports.First().Details);
            Assert.Equal("2", reports[1].Details);
            Assert.Equal("3", reports.Last().Details);
        }