public SessionsSummary GetDaySummary(string application, DateTime date, int timeslices) { SessionsSummary summary = new SessionsSummary(); CountResult[] results = eaepMonitorClient.Count( string.Format("{0}:{1}", EAEPMessage.FIELD_APPLICATION, application), date.Date, date.Date.AddDays(1), timeslices, EAEPMessage.PARAM_USER ); // construct framework array List<int[]> xycoord = new List<int[]>(); for (int i = 0; i < timeslices; i++) { xycoord.Add(new int[] { i, 0 }); } // populate with values // in this case we're just counting the instances of each // separate user name in each time slice foreach (CountResult result in results) { xycoord[result.TimeSlice][1]++; } summary.data = xycoord.ToArray() ; return summary; }
public void GetDaySummaryTest() { // Arrange int[] expectedResult = new int[96]; CountResult[] countResult = new CountResult[] { new CountResult() {TimeSlice = 2, FieldValue = "user1", Count = 2}, new CountResult() {TimeSlice = 2, FieldValue = "user2", Count = 4}, new CountResult() {TimeSlice = 3, FieldValue = "user1", Count = 2}, new CountResult() {TimeSlice = 3, FieldValue = "user3", Count = 2}, new CountResult() {TimeSlice = 3, FieldValue = "user2", Count = 2}, new CountResult() {TimeSlice = 4, FieldValue = "user2", Count = 2}, new CountResult() {TimeSlice = 5, FieldValue = "user3", Count = 2}, new CountResult() {TimeSlice = 5, FieldValue = "user1", Count = 2}, }; expectedResult[2] = 2; expectedResult[3] = 3; expectedResult[4] = 1; expectedResult[5] = 2; SessionsSummary expected = new SessionsSummary(); expected.data = expectedResult; string applicationName = "awebapp"; DateTime day = DateTime.Now; var eaepClient = new Mock<IEAEPMonitorClient>(); eaepClient .Setup(x => x.Count("app:awebapp", day.Date, day.Date.AddDays(1), expectedResult.Length, EAEPMessage.PARAM_USER)) .Returns(countResult); SessionsService target = new SessionsService(eaepClient.Object); // Act SessionsSummary actual = target.GetDaySummary(applicationName, day, expectedResult.Length); // Assert object[] actualResult = (object[])actual.data; Assert.AreEqual(expectedResult.Length, actualResult.Length); for (int i = 0; i < expectedResult.Length; i++) { Assert.AreEqual(expectedResult[i], ((int[])actualResult[i])[1]); } }