Exemple #1
0
        public void MultithreadedWriteOfLoggableMethodsDoesntCauseThreadingIssues_AtRepositoryLevel()
        {
            DeleteAllLoggedMethods();
            EnsureAllLoggableWeavedMethodsCanBeSavedIntoDbSuccessfully();

            var allLoggedMethods = GetLoggedMethods().ToArray();

            DeleteAllLoggedMethods();

            var config = new Config(new ErrorLogger());

            // several threads write the same chunk
            // (testing the situation when different applications create same classes/ call same methods and log them)
            Parallel.ForEach(
                Enumerable.Range(0, 4),
                i =>
            {
                var chunk = allLoggedMethods.Take(config.ChunkSize).ToArray();
                var repo  = new MethodLoggerRepository(config);
                Console.WriteLine("Writing " + i);
                repo.AddMethods(InvocationLogger.ComposeRows(chunk));
                Console.WriteLine("Finished " + i);
            });

            var loggedMethods = GetLoggedMethods().ToArray();

            Assert.That(loggedMethods.Count(), Is.EqualTo(config.ChunkSize));
        }
Exemple #2
0
        public void RepositoryThrows_WhenSavingDuplicateMethods()
        {
            DeleteAllLoggedMethods();

            var config = new Config(new ErrorLogger());
            var repo   = new MethodLoggerRepository(config);

            Assert.Throws <SqlException>(() => repo.AddMethods(InvocationLogger.ComposeRows(new[] { "Duplicate", "Duplicate" })));
        }
        public void EnsureAllLoggableWeavedMethodsCanBeSavedIntoDbSuccessfully()
        {
            DeleteAllLoggedMethods();

            // getting distinct since there are controls referenced in different projects. this can't be issue in runtime since duplicetes are not added to the dictioonary. see ColorPicker
            var  methods = GetWeavedMethods().WithoutCtors().Distinct().ToArray();
            var  config  = new Config(new ErrorLogger());
            var  repo    = new MethodLoggerRepository(config);
            bool error   = false;

            foreach (var partition in Partition(methods, config.ChunkSize))
            {
                try
                {
                    repo.AddMethods(InvocationLogger.ComposeRows(partition));
                }
                catch (Exception e)
                {
                    foreach (var method in partition)
                    {
                        try
                        {
                            repo.AddMethods(InvocationLogger.ComposeRows(new[] { method }));
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine("Problem saving method\r\n{0}\r\n{1}", method, exception);
                        }
                    }
                    Console.WriteLine("Problem saving method list\r\n{0}", e);
                    error = true;
                    throw;
                }
            }
            Assert.IsFalse(error);
        }