public async Task TestInitialize_AssemblyParameter()
        {
            ITelimena telimena;

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(this.TestTelemetryKey, Helpers.TeliUri)
                    {
                        MainAssembly = this.GetType().Assembly
                    });
                }
                else
                {
                    telimena = Telimena.Construct(new TelimenaStartupInfo(this.TestTelemetryKey, Helpers.TeliUri)
                    {
                        MainAssembly = this.GetType().Assembly
                    });
                }

                Assert.AreEqual(this.TestTelemetryKey, telimena.Properties.TelemetryKey);
                Assert.AreEqual("Telimena.Client.Tests", telimena.Properties.StaticProgramInfo.Name);
                Assert.AreEqual("Telimena.Client.Tests", telimena.Properties.StaticProgramInfo.PrimaryAssembly.Name);
                Assert.IsNotNull(telimena.Properties.StaticProgramInfo.PrimaryAssembly.VersionData.AssemblyVersion);
                Assert.IsNotNull(telimena.Properties.StaticProgramInfo.PrimaryAssembly.VersionData.FileVersion);
                await this.CheckIfUserIdIsGuid(telimena);
            }
        }
Example #2
0
        public static ITelimena GetCrackedTelimena(ICollection <ITelemetry> sentTelemetry, Guid telemetryKey, string userName, bool excludeStartingEvent = false)
        {
            var startupInfo = new TelimenaStartupInfo(telemetryKey, Helpers.TeliUri)
            {
                UserInfo = new TelimenaClient.Model.UserInfo()
                {
                    UserIdentifier = userName
                }
            };
            var telimena = TelimenaFactory.Construct(startupInfo);
            StubTelemetryChannel channel = new StubTelemetryChannel
            {
                OnSend = t =>
                {
                    EventTelemetry ev = t as EventTelemetry;
                    if (excludeStartingEvent && ev?.Name == "TelimenaSessionStarted")
                    {
                        return;
                    }
                    sentTelemetry.Add(t);
                }
            };
            TelemetryModule module = telimena.GetFieldValue <TelemetryModule>("telemetryModule");

            SetStaticFieldValue(module, "isSessionStartedEventSent", false);

            TelemetryClient client = module.GetPropertyValue <TelemetryClient>("TelemetryClient");
            var             config = client.GetPropertyValue <TelemetryConfiguration>("TelemetryConfiguration");

            config.SetPropertyValue("TelemetryChannel", channel);


            return(telimena);
        }
Example #3
0
        private async void hammer_StartButton_Click(object sender, EventArgs e)
        {
            this.hammer?.Stop();
            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                Properties.Settings.Default.telemetryKey = this.apiKeyTextBox.Text;
                Properties.Settings.Default.Save();
                this.Telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(key
                                                                                  , telemetryApiBaseUrl: new Uri(this.apiUrlTextBox.Text))) as Telimena;
            }
            else
            {
                MessageBox.Show("Api key missing, cannot run hammer");
                return;
            }

            this.hammer = new TelimenaHammer(key, this.apiUrlTextBox.Text
                                             , Convert.ToInt32(this.hammer_AppNumberSeedBox.Text)
                                             , Convert.ToInt32(this.hammer_numberOfApps_TextBox.Text)
                                             , Convert.ToInt32(this.hammer_numberOfFuncs_TextBox.Text)
                                             , Convert.ToInt32(this.hammer_numberOfUsers_TextBox.Text)
                                             , Convert.ToInt32(this.hammer_delayMinTextBox.Text), Convert.ToInt32(this.hammer_delayMaxTextBox.Text)
                                             , Convert.ToInt32(this.hammer_DurationTextBox.Text), this.UpdateText);

            await this.hammer.Hit().ConfigureAwait(true);
        }
        public void Test_OnlyUpdaterUpdates()
        {
            ITelimena sut = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.NewGuid(), Helpers.TeliUri)
            {
                SuppressAllErrors = false
            });


            UpdateResponse latestVersionResponse = new UpdateResponse
            {
                UpdatePackages = new List <UpdatePackageData> {
                    new UpdatePackageData {
                        FileName = DefaultToolkitNames.UpdaterFileName, Version = "1.2"
                    }
                }
            };

            Helpers.SetupMockHttpClient(sut, this.GetMockClientForCheckForUpdates(sut.Properties.TelemetryKey, new UpdateResponse(), latestVersionResponse));

            UpdateCheckResult response = sut.Update.CheckForUpdatesAsync().GetAwaiter().GetResult();

            Assert.IsFalse(response.IsUpdateAvailable);
            Assert.AreEqual(0, response.ProgramUpdatesToInstall.Count);
            Assert.AreEqual("1.2", response.UpdaterUpdate.Version);
            Assert.IsNull(response.Exception);
        }
        public async Task TestInitialize_ProgramInfo()
        {
            ProgramInfo pi = new ProgramInfo {
                Name = "An App!", PrimaryAssembly = new Model.AssemblyInfo(typeof(Mock).Assembly)
            };

            ITelimena telimena;

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.Empty, Helpers.TeliUri)
                    {
                        ProgramInfo = pi
                    });
                }
                else
                {
                    telimena = Telimena.Construct(new TelimenaStartupInfo(Guid.Empty, Helpers.TeliUri)
                    {
                        ProgramInfo = pi
                    });
                }
                Assert.AreEqual("An App!", telimena.Properties.StaticProgramInfo.Name);
                Assert.AreEqual("Moq", telimena.Properties.StaticProgramInfo.PrimaryAssembly.Name);
                Assert.IsTrue(telimena.Properties.StaticProgramInfo.PrimaryAssemblyPath.EndsWith(@"\Moq.dll"));
                Assert.IsNotNull(telimena.Properties.StaticProgramInfo.PrimaryAssembly.VersionData.AssemblyVersion);
                Assert.IsNotNull(telimena.Properties.StaticProgramInfo.PrimaryAssembly.VersionData.FileVersion);
                Assert.IsNotNull(telimena.Properties.UserInfo);
                await this.CheckIfUserIdIsGuid(telimena);
            }
        }
        public async Task TestInitialize_UserInfo()
        {
            UserInfo user = new UserInfo {
                UserIdentifier = "John Doe"
            };

            ITelimena telimena;

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.Empty, Helpers.TeliUri)
                    {
                        UserInfo = user
                    });
                }
                else
                {
                    telimena = Telimena.Construct(new TelimenaStartupInfo(Guid.Empty, Helpers.TeliUri)
                    {
                        UserInfo = user
                    });
                }
                await Task.Delay(4000);

                if (telimena.Properties.UserInfo.UserIdentifier == "NOT YET COMPUTED")
                {
                    await Task.Delay(4000);
                }
                Assert.AreEqual("John Doe", telimena.Properties.UserInfo?.UserIdentifier, $"Approach {i + 1}");
            }
        }
Example #7
0
        public Form1()
        {
            this.InitializeComponent();

            Random rnd = new Random();
            var    randomName = new [] { "Jess", "Anastasia", "Bobby", "Steven", "Bonawentura" }.OrderBy(a => rnd.NextDouble()).First();

            this.userNameTextBox.Text = randomName;
            this.apiUrlTextBox.Text   = string.IsNullOrEmpty(Properties.Settings.Default.baseUri)
                ? "http://localhost:7757/"
                : Properties.Settings.Default.baseUri;
            this.apiKeyTextBox.Text = string.IsNullOrEmpty(Properties.Settings.Default.telemetryKey)
                ? ""
                : Properties.Settings.Default.telemetryKey;
            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                this.Telimena =
                    TelimenaFactory.Construct(new TelimenaStartupInfo(key, new Uri(this.apiUrlTextBox.Text))
                {
                    UserInfo = new UserInfo()
                    {
                        UserIdentifier = this.userNameTextBox.Text
                    }
                }) as Telimena;
            }

            this.Text = $"Sandbox v. {TelimenaVersionReader.Read(this.GetType(), VersionTypes.FileVersion)}";
        }
Example #8
0
        private void setAppButton_Click(object sender, EventArgs e)
        {
            var si = new TelimenaStartupInfo(Guid.Empty, telemetryApiBaseUrl: new Uri(this.apiUrlTextBox.Text))
            {
                InstrumentationKey = "1a14064b-d326-4ce3-939e-8cba4d08c255"
            };

            if (!string.IsNullOrEmpty(this.userNameTextBox.Text))
            {
                si.UserInfo = new UserInfo {
                    UserIdentifier = this.userNameTextBox.Text
                };
            }



            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                si.TelemetryKey = key;
                Properties.Settings.Default.telemetryKey = this.apiKeyTextBox.Text;
                Properties.Settings.Default.Save();
                this.Telimena = TelimenaFactory.Construct(si) as Telimena;
                ;
            }
            else
            {
                MessageBox.Show("Api key missing, cannot run teli");
            }
            Properties.Settings.Default.baseUri = this.apiUrlTextBox.Text;
            Properties.Settings.Default.Save();
        }
Example #9
0
        public void TestInitialize_NoParameters()
        {
            ITelimena telimena;

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(this.TestTelemetryKey));
                }
                else
                {
                    telimena = Telimena.Construct(new TelimenaStartupInfo(this.TestTelemetryKey));
                }

                Assert.AreEqual("Telimena.Client.Tests", telimena.Properties.StaticProgramInfo.Name);
                Assert.AreEqual("Telimena.Client.Tests", telimena.Properties.StaticProgramInfo.PrimaryAssembly.Name);
                Assert.IsTrue(
                    telimena.Properties.StaticProgramInfo.PrimaryAssemblyPath.EndsWith(@"\Telimena.Client.Tests.dll"));
                Assert.IsNotNull(telimena.Properties.StaticProgramInfo.PrimaryAssembly.VersionData.AssemblyVersion);
                Assert.IsNotNull(telimena.Properties.StaticProgramInfo.PrimaryAssembly.VersionData.FileVersion);
                Assert.IsNotNull(telimena.Properties.UserInfo.UserIdentifier);
                Assert.IsNotNull(telimena.Properties.UserInfo.MachineName);
            }
        }
Example #10
0
        public void Test_RegisterRequestCreation()
        {
            Telimena telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(this.testTelemetryKey, Helpers.TeliUri)) as Telimena;

            telimena.Properties.SuppressAllErrors = false;
            Helpers.SetupMockHttpClient(telimena, Helpers.GetMockClient());
            this.Test_RegistrationFunc(telimena, () => telimena.Initialize().GetAwaiter().GetResult(), false);
        }
        public void TestNullObject_AssertItDoesNotExplode()
        {
            var teli = Telimena.Construct(new ExplodingITelimenaStartupInfo());

            this.ValidateFaultyTeli(teli);

            teli = TelimenaFactory.Construct(new ExplodingITelimenaStartupInfo());
            this.ValidateFaultyTeli(teli);
        }
Example #12
0
        private async Task StartReporting(UserInfo userInfo)
        {
            Random random = new Random();

            while (this.timeoutStopwatch.IsRunning && this.timeoutStopwatch.ElapsedMilliseconds < this.duration.TotalMilliseconds)
            {
                ProgramInfo prg  = this.apps[random.Next(0, this.apps.Count)];
                ITelimena   teli = (Telimena)TelimenaFactory.Construct(new TelimenaStartupInfo(this.telemetryKey, new Uri(this.url))
                {
                    ProgramInfo = prg,
                    UserInfo    = userInfo
                });
                int operation = random.Next(6);
                if (operation == 1)
                {
                    teli.Track.Event("SomeEvent");
                    this.progressReport("Done");
                }
                else if (operation == 2)
                {
                    var result = await(teli as Telimena).Initialize().ConfigureAwait(false);
                    this.progressReport(this.PresentResponse(result));
                }
                else if (operation == 3)
                {
                    teli.Track.Log(LogLevel.Critical, "Log messagess");
                }
                else if (operation == 4)
                {
                    teli.Track.Exception(new InvalidCastException("BOO"));
                }
                else
                {
                    if (random.Next(2) == 1)
                    {
                        teli.Track.View(this.funcs[random.Next(0, this.funcs.Count)]);
                        this.progressReport("Done");
                    }
                    else
                    {
                        teli.Track.View(this.funcs[random.Next(0, this.funcs.Count)], this.GetRandomData());
                        this.progressReport("Done");
                    }
                }

                await Task.Delay(random.Next(this.delayMin, this.delayMax)).ConfigureAwait(false);
            }
        }
        public void Test_NoUpdates()
        {
            ITelimena sut = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.NewGuid(), Helpers.TeliUri)
            {
                SuppressAllErrors = false
            });

            Helpers.SetupMockHttpClient(sut, this.GetMockClientForCheckForUpdates(sut.Properties.TelemetryKey, new UpdateResponse(), new UpdateResponse()));

            UpdateCheckResult response = sut.Update.CheckForUpdatesAsync().GetAwaiter().GetResult();

            Assert.IsFalse(response.IsUpdateAvailable);
            Assert.AreEqual(0, response.ProgramUpdatesToInstall.Count);
            Assert.IsNull(response.UpdaterUpdate);
            Assert.IsNull(response.Exception);
        }
Example #14
0
        private void useCurrentAppButton_Click(object sender, EventArgs e)
        {
            if (Guid.TryParse(this.apiKeyTextBox.Text, out Guid key))
            {
                Properties.Settings.Default.telemetryKey = this.apiKeyTextBox.Text;
                Properties.Settings.Default.Save();
                this.Telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(key
                                                                                  , telemetryApiBaseUrl: new Uri(this.apiUrlTextBox.Text))) as Telimena;
            }
            else
            {
                MessageBox.Show("Api key missing, cannot run teli");
            }

            Properties.Settings.Default.baseUri = this.apiUrlTextBox.Text;
            Properties.Settings.Default.Save();
        }
Example #15
0
        public void Test_RegisterRequestCreation_EmptyKey()
        {
            Telimena telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(Guid.Empty, Helpers.TeliUri)) as Telimena;

            telimena.Properties.SuppressAllErrors = false;
            Helpers.SetupMockHttpClient(telimena, Helpers.GetMockClient());

            try
            {
                telimena.Initialize().GetAwaiter().GetResult();
                Assert.Fail("Error expected");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.InnerException.Message.Contains("Tracking key is an empty guid."));
            }
        }
Example #16
0
        private void Initialize()
        {
            Random rnd = new Random();

            this.users = new List <UserInfo>();
            for (int i = 0; i < this.numberOfUsers; i++)
            {
                UserInfo user = new UserInfo
                {
                    Email          = this.GetRandomName("Email@", i),
                    UserIdentifier = this.GetRandomName("User", i),
                    MachineName    = this.GetRandomName("Machine", i)
                };
                this.users.Add(user);
            }

            this.apps = new List <ProgramInfo>();
            for (int i = this.appIndexSeed; i < this.numberOfApps + this.appIndexSeed; i++)
            {
                ProgramInfo programInfo = new ProgramInfo
                {
                    Name = "Program_" + i
                    ,
                    PrimaryAssembly = new AssemblyInfo
                    {
                        Name = "PrimaryAssembly_Program_" + i
                        ,
                        VersionData = new VersionData($"{1}.{DateTime.UtcNow.Month}.{DateTime.UtcNow.Day}.{rnd.Next(10)}"
                                                      , $"{1 + 1}.{DateTime.UtcNow.Month}.{DateTime.UtcNow.Day}.{rnd.Next(10)}")
                    }
                };
                this.apps.Add(programInfo);
                _ = TelimenaFactory.Construct(new TelimenaStartupInfo(this.telemetryKey, new Uri(this.url))
                {
                    ProgramInfo = programInfo
                });
            }

            this.funcs = new List <string>();

            for (int i = 0; i < this.numberOfFuncs; i++)
            {
                this.funcs.Add(this.GetRandomName("View", i));
            }
        }
        public static void Work(Arguments arguments)
        {
            Console.WriteLine("Starting update handling...");
            ITelimena teli = TelimenaFactory.Construct(new TelimenaStartupInfo(arguments.TelemetryKey, new Uri(arguments.ApiUrl)));

            teli.Properties.UpdatePromptingMode = UpdatePromptingModes.PromptBeforeDownload;
            Console.WriteLine("Telimena created... Handling updates");
            UpdateInstallationResult result = teli.Update.HandleUpdates(false);

            Console.WriteLine("Finished update handling");
            JsonSerializerSettings settings = new JsonSerializerSettings {
                ContractResolver = new MyJsonContractResolver()
            };

            Console.WriteLine(JsonConvert.SerializeObject(result, settings));

            Console.WriteLine("All done");
        }
        public void Test_CheckForUpdates_Program_AndUpdater()
        {
            var si = new TelimenaStartupInfo(Guid.NewGuid(), Helpers.TeliUri)
            {
                SuppressAllErrors = false
            };

            ITelimena sut = TelimenaFactory.Construct(si);

            Assert.AreEqual("Telimena.Client.Tests", sut.Properties.StaticProgramInfo.PrimaryAssembly.Name);
            UpdateResponse latestVersionResponse = new UpdateResponse
            {
                UpdatePackages = new List <UpdatePackageData>
                {
                    new UpdatePackageData {
                        FileSizeBytes = 666, PublicId = Guid.NewGuid(), IsBeta = true, Version = "3.1.0.0"
                    }
                }
            };
            UpdateResponse updaterResponse = new UpdateResponse
            {
                UpdatePackages = new List <UpdatePackageData> {
                    new UpdatePackageData {
                        FileName = DefaultToolkitNames.UpdaterFileName, Version = "1.2"
                    }
                }
            };

            Helpers.SetupMockHttpClient(sut, this.GetMockClientForCheckForUpdates(sut.Properties.TelemetryKey, latestVersionResponse, updaterResponse));

            UpdateCheckResult response = sut.Update.CheckForUpdatesAsync().GetAwaiter().GetResult();

            Assert.IsTrue(response.IsUpdateAvailable);
            Assert.AreEqual(1, response.ProgramUpdatesToInstall.Count);
            Assert.IsNotNull(response.ProgramUpdatesToInstall.SingleOrDefault(x => x.Version == "3.1.0.0" && x.IsBeta));
            Assert.AreEqual("1.2", response.UpdaterUpdate.Version);
            Assert.IsNull(response.Exception);
        }
Example #19
0
        private ITelimena GetTelimena(Guid argumentsTelemetryKey)
        {
            ITelimena telimena;

            if (this.arguments.ProgramInfo != null)
            {
                TelimenaStartupInfo si = new TelimenaStartupInfo(argumentsTelemetryKey, new Uri(this.arguments.ApiUrl))
                {
                    ProgramInfo        = this.arguments.ProgramInfo
                    , DeliveryInterval = TimeSpan.FromSeconds(3)
                };
                telimena = TelimenaFactory.Construct(si);
            }
            else
            {
                telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(argumentsTelemetryKey, new Uri(this.arguments.ApiUrl))
                {
                    DeliveryInterval = TimeSpan.FromSeconds(3)
                });
            }

            return(telimena);
        }
Example #20
0
        private ITelimena GetTelimena(Guid argumentsTelemetryKey)
        {
            ITelimena telimena;

            if (this.arguments.ProgramInfo != null)
            {
                TelimenaStartupInfo si = new TelimenaStartupInfo(argumentsTelemetryKey, new Uri(this.arguments.ApiUrl))
                {
                    ProgramInfo        = this.arguments.ProgramInfo
                    , DeliveryInterval = TimeSpan.FromSeconds(3)
                };
                telimena = TelimenaFactory.Construct(si);
            }
            else
            {
                telimena = TelimenaFactory.Construct(new TelimenaStartupInfo(argumentsTelemetryKey, new Uri(this.arguments.ApiUrl))
                {
                    DeliveryInterval = TimeSpan.FromSeconds(3)
                });
            }
            Console.WriteLine($"Initalized [{telimena?.GetType().FullName}].");

            return(telimena);
        }