public async Task TestAuthUserId()
        {
            //prepare context
            TelemetryUnitOfWork unit = new TelemetryUnitOfWork(this.TelemetryContext, this.PortalContext, new AssemblyStreamVersionReader());
            await Helpers.SeedInitialPrograms(this.PortalContext, this.TelemetryContext, 4, "TestApp", new string[0]);

            Helpers.GetProgramAndUser(unit, "TestApp3", "Jim Beam", out TelemetryRootObject prg, out ClientAppUser usr);
            Assert.IsTrue(prg.ProgramId > 0);

            //prepare requests
            TelemetryItem telemetryItem = new TelemetryItem()

            {
                EntryKey          = Helpers.GetName("SomeView"),
                TelemetryItemType = TelemetryItemTypes.View,
                Sequence          = "aaa:1",
                VersionData       = new VersionData("1.2.3.4", "2.0.0.0"),
                Timestamp         = new DateTimeOffset(DateTime.UtcNow),
                Properties        = new Dictionary <string, string> {
                    { "AKey", "AValue" }, { "AKey2", "AValue2" }
                },
                AuthenticatedUserIdentifier = Helpers.GetName("Jim Beam")
            };

            //send
            List <TelemetrySummary> response = await TelemetryControllerHelpers.InsertData(unit, (new[] { telemetryItem }).ToList(), prg, "127.1.1.1");

            View view = prg.Views.FirstOrDefault(x => x.Name == Helpers.GetName("SomeView"));

            Assert.AreEqual(1, view.TelemetrySummaries.Count);
            ViewTelemetrySummary summary = view.TelemetrySummaries.SingleOrDefault(x => x.ClientAppUser.AuthenticatedUserIdentifier == Helpers.GetName("Jim Beam"));

            Assert.AreEqual(1, summary.SummaryCount);
            Assert.AreEqual("", summary.ClientAppUser.UserIdentifier);
            Assert.IsTrue(response.Single().ClientAppUserId > 0);
        }
Beispiel #2
0
        public void TestGetDailySumary()
        {
            var viewTelemetrySummary  = new ViewTelemetrySummary();
            var viewTelemetrySummary2 = new ViewTelemetrySummary();

            List <ViewTelemetryDetail> data = new List <ViewTelemetryDetail>();

            data.Add(new ViewTelemetryDetail(this.id_1)
            {
                Timestamp = new DateTime(2000, 01, 01), UserIdentifier = "AAA", EntryKey = "ZZZ", FileVersion = "2.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_2)
            {
                Timestamp = new DateTime(2000, 01, 02), UserIdentifier = "BBB", EntryKey = "ZZZ", FileVersion = "6.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_3)
            {
                Timestamp = new DateTime(2000, 01, 03), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_3)
            {
                Timestamp = new DateTime(2000, 01, 03), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_3)
            {
                Timestamp = new DateTime(2000, 01, 03), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_4)
            {
                Timestamp = new DateTime(2000, 01, 04), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_6)
            {
                Timestamp = new DateTime(2000, 01, 06), UserIdentifier = "AAA", EntryKey = "YYY", FileVersion = "2.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_7)
            {
                Timestamp = new DateTime(2000, 01, 07), UserIdentifier = "BBB", EntryKey = "YYY", FileVersion = "9.0"
            });
            data.Add(new ViewTelemetryDetail(this.id_8)
            {
                Timestamp = new DateTime(2000, 01, 08), UserIdentifier = "BBB", EntryKey = "XXX", FileVersion = "1.0"
            });

            ((List <ViewTelemetryDetail>)viewTelemetrySummary.TelemetryDetails).AddRange(data);

            ((List <ViewTelemetryDetail>)viewTelemetrySummary2.TelemetryDetails).Add(new ViewTelemetryDetail(this.id_3)
            {
                Timestamp = new DateTime(2000, 01, 03), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });

            var ets = new EventTelemetrySummary();

            ((List <EventTelemetryDetail>)ets.TelemetryDetails).Add(new EventTelemetryDetail(this.id_3)
            {
                Timestamp = new DateTime(2000, 01, 03), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });
            ((List <EventTelemetryDetail>)ets.TelemetryDetails).Add(new EventTelemetryDetail(this.id_3)
            {
                Timestamp = new DateTime(2000, 01, 05), UserIdentifier = "CCC", EntryKey = "ZZZ", FileVersion = "4.0"
            });


            var exceptions = new List <ExceptionInfo>();

            exceptions.Add(new ExceptionInfo()
            {
                Timestamp = new DateTime(2000, 01, 7)
            });
            exceptions.Add(new ExceptionInfo()
            {
                Timestamp = new DateTime(2000, 01, 7)
            });
            exceptions.Add(new ExceptionInfo()
            {
                Timestamp = new DateTime(2000, 01, 7)
            });
            exceptions.Add(new ExceptionInfo()
            {
                Timestamp = new DateTime(2000, 01, 7)
            });

            var dataTable = ProgramsDashboardUnitOfWork.PrepareDailyActivityScoreTable(
                new DateTime(2000, 01, 03)
                , new DateTime(2000, 01, 07),
                new List <EventTelemetrySummary>()
            {
                ets
            }
                , new List <ViewTelemetrySummary>()
            {
                viewTelemetrySummary, viewTelemetrySummary2
            },
                exceptions);

            Assert.AreEqual(ProgramsDashboardUnitOfWork.ToDashboardDateString(new DateTime(2000, 01, 03)), dataTable.Rows[0]["Date"]);
            Assert.AreEqual(ProgramsDashboardUnitOfWork.ToDashboardDateString(new DateTime(2000, 01, 07)), dataTable.Rows[dataTable.Rows.Count - 1]["Date"]);
            Assert.AreEqual(5, dataTable.Rows.Count);

            //03.01
            Assert.AreEqual(4, dataTable.Rows[0]["Views"]);
            Assert.AreEqual(0, dataTable.Rows[0]["Errors"]);
            Assert.AreEqual(1, dataTable.Rows[0]["Events"]);

            //04.01
            Assert.AreEqual(1, dataTable.Rows[1]["Views"]);
            Assert.AreEqual(0, dataTable.Rows[1]["Errors"]);
            Assert.AreEqual(0, dataTable.Rows[1]["Events"]);

            //05.01
            Assert.AreEqual(0, dataTable.Rows[2]["Views"]);
            Assert.AreEqual(0, dataTable.Rows[2]["Errors"]);
            Assert.AreEqual(1, dataTable.Rows[2]["Events"]);

            //07.01
            Assert.AreEqual(1, dataTable.Rows[4]["Views"]);
            Assert.AreEqual(4, dataTable.Rows[4]["Errors"]);
            Assert.AreEqual(0, dataTable.Rows[4]["Events"]);
        }
        public async Task TestUpdateAction()
        {
            //prepare context
            TelemetryUnitOfWork unit = new TelemetryUnitOfWork(this.TelemetryContext, this.PortalContext, new AssemblyStreamVersionReader());
            await Helpers.SeedInitialPrograms(this.PortalContext, this.TelemetryContext, 4, "TestApp", new[] { "Johnny Walker", "Jim Beam", "Eric Cartman" });

            Helpers.GetProgramAndUser(unit, "TestApp3", "Jim Beam", out TelemetryRootObject prg, out ClientAppUser usr);
            Assert.IsTrue(prg.ProgramId > 0 && usr.Id > 0);

            //prepare requests
            TelemetryItem telemetryItem = new TelemetryItem()

            {
                EntryKey          = Helpers.GetName("SomeView"),
                TelemetryItemType = TelemetryItemTypes.View,
                Sequence          = "aaa:1",
                VersionData       = new VersionData("1.2.3.4", "2.0.0.0"),
                Timestamp         = new DateTimeOffset(DateTime.UtcNow),
                Properties        = new Dictionary <string, string> {
                    { "AKey", "AValue" }, { "AKey2", "AValue2" }
                },
                UserIdentifier = usr.UserIdentifier
            };

            //send
            List <TelemetrySummary> response = await TelemetryControllerHelpers.InsertData(unit, (new[] { telemetryItem }).ToList(), prg, "127.1.1.1");

            Helpers.AssertUpdateResponse(response, prg, usr, 1, Helpers.GetName("SomeView"));
            View view = prg.Views.FirstOrDefault(x => x.Name == Helpers.GetName("SomeView"));

            Assert.AreEqual(1, view.TelemetrySummaries.Count);
            ViewTelemetrySummary summary = view.TelemetrySummaries.SingleOrDefault(x => x.ClientAppUser.UserIdentifier == Helpers.GetName("Jim Beam"));

            Assert.AreEqual(1, summary.SummaryCount);
            Assert.IsNull(summary.ClientAppUser.AuthenticatedUserIdentifier);
            Assert.AreEqual(summary.GetTelemetryDetails().Last().AssemblyVersion, "1.2.3.4");
            Assert.AreEqual(summary.GetTelemetryDetails().Last().FileVersion, "2.0.0.0");

            //run again
            telemetryItem = new TelemetryItem()

            {
                EntryKey          = Helpers.GetName("SomeView"),
                TelemetryItemType = TelemetryItemTypes.View,
                Sequence          = "aaa:1",
                VersionData       = new VersionData("1.2.3.4", "2.0.0.0"),
                Timestamp         = new DateTimeOffset(DateTime.UtcNow),
                Properties        = new Dictionary <string, string> {
                    { "AKey", "AValue" }, { "AKey2", "AValue2" }
                },
                UserIdentifier = usr.UserIdentifier
            };
            response = await TelemetryControllerHelpers.InsertData(unit, (new[] { telemetryItem }).ToList(), prg, "127.1.1.1");

            Helpers.GetProgramAndUser(unit, "TestApp3", "Jim Beam", out prg, out usr);
            Helpers.AssertUpdateResponse(response, prg, usr, 1, Helpers.GetName("SomeView"));
            Assert.AreEqual(2, response.Single().SummaryCount);
            view = prg.Views.FirstOrDefault(x => x.Name == Helpers.GetName("SomeView"));

            Assert.AreEqual(1, view.TelemetrySummaries.Count);

            Assert.AreEqual(2, view.GetTelemetrySummary(response.First().ClientAppUser.Id).SummaryCount);
            Assert.AreEqual(2, view.TelemetrySummaries.Single(x => x.ClientAppUser.UserIdentifier == Helpers.GetName("Jim Beam")).SummaryCount);

            Assert.AreEqual(2, view.GetTelemetryDetails(response.First().ClientAppUser.Id).Count);
            Assert.AreEqual(summary.GetTelemetryDetails().Last().AssemblyVersion, telemetryItem.VersionData.AssemblyVersion);
            Assert.AreEqual(summary.GetTelemetryDetails().Last().FileVersion, telemetryItem.VersionData.FileVersion);
        }
Beispiel #4
0
 public void AddUsage(ViewTelemetrySummary objectToAdd)
 {
     this.TelimenaPortalContext.ViewTelemetrySummaries.Add(objectToAdd);
 }