public void TestSetCountEmpty()
        {
            var errorGroupStats = new ErrorGroupStats
            {
                AffectedServices = new List <ServiceContext> {
                    new ServiceContext()
                },
                AffectedUsersCount  = 3,
                NumAffectedServices = 2,
                TimedCounts         = new List <TimedCount> {
                    new TimedCount()
                }
            };
            var objectUnderTest = new ErrorGroupItem(errorGroupStats, null);

            objectUnderTest.SetCountEmpty();

            Assert.AreEqual(0, objectUnderTest.ErrorCount);
            Assert.IsNull(objectUnderTest.SeenIn);
            Assert.AreEqual("-", objectUnderTest.AffectedUsersCount);
            Assert.IsNull(objectUnderTest.TimedCountList);
            Assert.AreEqual(0, objectUnderTest.ErrorGroup.Count);
            Assert.IsNull(objectUnderTest.ErrorGroup.NumAffectedServices);
            Assert.IsNull(objectUnderTest.ErrorGroup.AffectedUsersCount);
            Assert.IsNull(objectUnderTest.ErrorGroup.TimedCounts);
        }
        public async Task ErrorReportingTest()
        {
            Task <ErrorStatsServiceClient> clientTask = ErrorStatsServiceClient.CreateAsync();

            // Create a test server and make an http.
            using (TestServer server = TestServer.Create <ErrorReportingApplication>())
            {
                await server.HttpClient.GetAsync("");

                // Create a request that will filter on the TestId which is set to the service and version.
                ListGroupStatsRequest request = new ListGroupStatsRequest
                {
                    ProjectName   = new ProjectName(ProjectId).ToString(),
                    ServiceFilter = new ServiceContextFilter
                    {
                        Service = TestId,
                        Version = TestId
                    }
                };

                // Check that we have the proper results and the TestId shows up in the error.
                ErrorStatsServiceClient client = await clientTask;
                ErrorGroupStats         stats  = await client.ListGroupStatsAsync(request).FirstOrDefault();

                Assert.NotNull(stats);
                Assert.True(stats.Count > 0);
                Assert.Contains(TestId, stats.Representative.Message);
            }
        }
        public void TestPopulatedInitalConditions()
        {
            var          firstTime          = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Local);
            var          lastTime           = new DateTime(2011, 1, 1, 1, 1, 1, DateTimeKind.Local);
            const int    affectedUsersCount = 3;
            const int    count              = 10;
            const string testServiceName    = "TestService";
            const int    responseStatusCode = 200;
            const string testMessage        = "TestMessage";
            var          timedCounts        = new List <TimedCount> {
                new TimedCount()
            };
            var errorGroupStats = new ErrorGroupStats
            {
                AffectedServices = new List <ServiceContext> {
                    new ServiceContext {
                        Service = testServiceName
                    }
                },
                AffectedUsersCount = affectedUsersCount,
                Count               = count,
                FirstSeenTime       = firstTime,
                LastSeenTime        = lastTime,
                NumAffectedServices = 2,
                Representative      = new ErrorEvent
                {
                    Context = new ErrorContext {
                        HttpRequest = new HttpRequestContext {
                            ResponseStatusCode = responseStatusCode
                        }
                    },
                    Message = testMessage
                },
                Group       = new ErrorGroup(),
                TimedCounts = timedCounts
            };
            var timeRangeItem = new TimeRangeItem(
                "testTimeRangeCaption", "testTimedCountDuration",
                ProjectsResource.GroupStatsResource.ListRequest.TimeRangePeriodEnum.PERIOD1DAY,
                ProjectsResource.EventsResource.ListRequest.TimeRangePeriodEnum.PERIOD1DAY);

            var objectUnderTest = new ErrorGroupItem(errorGroupStats, timeRangeItem);

            Assert.IsNotNull(objectUnderTest.ParsedException);
            Assert.AreEqual(errorGroupStats, objectUnderTest.ErrorGroup);
            Assert.AreEqual(count, objectUnderTest.ErrorCount);
            Assert.AreEqual(testServiceName, objectUnderTest.SeenIn);
            Assert.AreEqual(responseStatusCode, objectUnderTest.Status);
            Assert.AreEqual(testMessage, objectUnderTest.ErrorMessage);
            Assert.IsNull(objectUnderTest.FirstStackFrameSummary);
            Assert.IsNull(objectUnderTest.FirstStackFrame);
            Assert.AreEqual(firstTime, DateTime.Parse(objectUnderTest.FirstSeenTime));
            Assert.AreEqual(lastTime, DateTime.Parse(objectUnderTest.LastSeenTime));
            Assert.AreEqual(timeRangeItem, objectUnderTest.GroupTimeRange);
            CollectionAssert.AreEquivalent(timedCounts, objectUnderTest.TimedCountList.ToList());
            Assert.AreEqual(testMessage, objectUnderTest.RawErrorMessage);
            Assert.AreEqual(affectedUsersCount.ToString(), objectUnderTest.AffectedUsersCount);
        }
Esempio n. 4
0
 public ErrorGroupItem(ErrorGroupStats errorGroup, TimeRangeItem timeRange)
 {
     if (errorGroup == null)
     {
         throw new ErrorReportingException(new ArgumentNullException(nameof(errorGroup)));
     }
     ErrorGroup = errorGroup;
     if (ErrorGroup.Representative?.Message != null)
     {
         ParsedException = new ParsedException(ErrorGroup.Representative?.Message);
     }
     GroupTimeRange = timeRange;
 }
        /// <summary>
        /// Gets a page of <seealso cref="ErrorEvent"/> for an error group.
        /// The result is divided into pages when the result set is too large.
        /// This call get one page of results.
        /// </summary>
        /// <param name="errorGroup">An error group. <seealso cref="ErrorGroupStats"/>.</param>
        /// <param name="period">
        /// The time period for the query.
        /// Optional, defaults to 30 days.
        /// </param>
        /// <param name="nextPageToken">optional, A next page token provided by a previous response.</param>
        /// <returns>
        /// A task with <seealso cref="ListEventsResponse"/> as result.
        /// </returns>
        public Task <ListEventsResponse> GetPageOfEventsAsync(
            ErrorGroupStats errorGroup,
            EventTimeRange period = EventTimeRange.PERIOD30DAYS,
            string nextPageToken  = null)
        {
            var request = Service.Projects.Events.List(ProjectResourceName);

            request.TimeRangePeriod = period;
            request.PageToken       = nextPageToken;
            request.GroupId         = errorGroup.Group.GroupId;
            try
            {
                return(request.ExecuteAsync());
            }
            catch (GoogleApiException ex)
            {
                Debug.WriteLine($"Failed to get ErrorEvents: {ex.Message}");
                throw new DataSourceException(ex.Message, ex);
            }
        }
        public void TestInitalConditions()
        {
            var errorGroupStats = new ErrorGroupStats();

            var objectUnderTest = new ErrorGroupItem(errorGroupStats, null);

            Assert.IsNull(objectUnderTest.ParsedException);
            Assert.AreEqual(errorGroupStats, objectUnderTest.ErrorGroup);
            Assert.AreEqual(0, objectUnderTest.ErrorCount);
            Assert.IsNull(objectUnderTest.SeenIn);
            Assert.IsNull(objectUnderTest.Status);
            Assert.IsNull(objectUnderTest.ErrorMessage);
            Assert.IsNull(objectUnderTest.FirstStackFrameSummary);
            Assert.IsNull(objectUnderTest.FirstStackFrame);
            Assert.AreEqual(DateTime.MinValue, DateTime.Parse(objectUnderTest.FirstSeenTime));
            Assert.AreEqual(DateTime.MinValue, DateTime.Parse(objectUnderTest.LastSeenTime));
            Assert.IsNull(objectUnderTest.GroupTimeRange);
            Assert.IsNull(objectUnderTest.TimedCountList);
            Assert.IsNull(objectUnderTest.RawErrorMessage);
            Assert.AreEqual("-", objectUnderTest.AffectedUsersCount);
        }