Example #1
0
        public void InfoBlockTraversesAppDomainsCorrectly()
        {
            NameValueCollection blockValues;
            var key   = "SomeKey";
            var value = "SomeValue";

            using (Relevant.Info(new NameValueCollection {
                { key, value }
            }))
            {
                var tempDomain = AppDomain.CreateDomain("tempDomain",
                                                        AppDomain.CurrentDomain.Evidence,
                                                        AppDomain.CurrentDomain.BaseDirectory,
                                                        AppDomain.CurrentDomain.RelativeSearchPath,
                                                        AppDomain.CurrentDomain.ShadowCopyFiles);

                blockValues = Relevant.Info();
            }

            Assert.IsNotNull(blockValues);
            Assert.AreEqual(1, blockValues.Count);
            Assert.AreEqual(key, blockValues.GetKey(0));

            var values = blockValues.GetValues(key);

            Assert.IsNotNull(values);
            Assert.AreEqual(1, values.Length);
            Assert.AreEqual(value, values[0]);
        }
        public List <Relevant> GetRelevanteLinksVoorDataset(int datasetID)
        {
            List <Relevant> links = new List <Relevant>();

            SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicatiePlattegrondConnectionString"].ToString());

            using (SqlCommand command = new SqlCommand("", connection))
            {
                connection.Open();
                command.CommandText = "SELECT * FROM Relevante_Link WHERE Dataset_ID = @Dataset_ID";

                command.Parameters.AddWithValue("@Dataset_ID", datasetID);

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Relevant link = new Relevant
                    {
                        Id        = (int)reader["ID"],
                        Naam      = reader["Naam"].ToString(),
                        Link      = reader["Link"].ToString(),
                        DatasetID = (int)reader["ID"]
                    };
                    links.Add(link);
                }

                connection.Close();
                return(links);
            }
        }
Example #3
0
        public async Task AggregateRelevantInfo()
        {
            // ARRANGE
            var innerException1 = new Exception("inner error 1");
            var innerException2 = new Exception("inner error 2");
            var topException    = new AggregateException(innerException1, innerException2);

            // ACT
            using (Relevant.Info("key1", "value1"))
            {
                innerException1.AttachRelevantInfo();
            }

            using (Relevant.Info("key2", "value2"))
            {
                innerException2.AttachRelevantInfo();
            }

            using (Relevant.Info("key3", "value3"))
            {
                topException.AttachRelevantInfo();
            }

            var actualRelevantInfo = topException.GetReleventInfo();

            // ASSERT
            Assert.IsNotNull(actualRelevantInfo, "should return a value");
            Assert.AreEqual(3, actualRelevantInfo.Count, $"should have 3 pairs");
            Assert.AreEqual("value1", actualRelevantInfo["key1"], "value 1 must match");
            Assert.AreEqual("value2", actualRelevantInfo["key2"], "value 2 must match");
            Assert.AreEqual("value3", actualRelevantInfo["key3"], "value 3 must match");
        }
Example #4
0
        public async Task InfoAutoAddedToExceptions()
        {
            // ARRANGE
            Relevant.InfoAutoAddedToExceptions();

            // ACT
            Exception caughtException;

            using (Relevant.Info("key1", "value1"))
            {
                try
                {
                    throw new Exception();
                }
                catch (Exception ex)
                {
                    caughtException = ex;
                }
            }

            var actualRelevantInfo = caughtException.GetReleventInfo();

            // ASSERT
            Assert.IsNotNull(actualRelevantInfo, "should return a value");
            Assert.AreEqual(1, actualRelevantInfo.Count, $"should have 1 pair");
            Assert.AreEqual("value1", actualRelevantInfo["key1"], "value must match");
        }
Example #5
0
        public async Task InnerExceptionConveysRelevantInfo()
        {
            // ARRANGE
            var innerException = new Exception("inner error");
            var topException   = new Exception("error", innerException);

            // ACT
            using (Relevant.Info("key1", "value1"))
            {
                innerException.AttachRelevantInfo();
            }

            using (Relevant.Info("key2", "value2"))
            {
                topException.AttachRelevantInfo();
            }

            var actualRelevantInfo = topException.GetReleventInfo();

            // ASSERT
            Assert.IsNotNull(actualRelevantInfo, "should return a value");
            Assert.AreEqual(2, actualRelevantInfo.Count, $"should have 2 pairs");
            Assert.AreEqual("value1", actualRelevantInfo["key1"], "value 1 must match");
            Assert.AreEqual("value2", actualRelevantInfo["key2"], "value 2 must match");
        }
Example #6
0
        public static void Testing()
        {
            Console.WriteLine("Generating Random Intergers...");
            int[] array = Relevant.GenerateRandomIntergers(300_000_000, 0, 1_000_000);

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("ParallelVersion start:");
            sw.Start();

            GetMaxValueThenPlaceToEnd(array);
            _lengthRequireNewThread = array.Length / 256;
            Task mainTask = null;

            mainTask = new Task(() => Sort_Continuation(array, 0, array.Length - 1, mainTask));
            mainTask.Start();
            while (true)
            {
                Thread.Sleep(500);
                if (_partitionCounter == _finishCounter - 1)
                {
                    break;
                }
            }

            sw.Stop();
            Console.WriteLine($"Total second of Algorithm: {sw.Elapsed}");
            bool result = Relevant.VerifySequence(array);

            Console.WriteLine($"Verification: {result}");
        }
Example #7
0
        public void MultipleDisposalThrows()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            NameValueCollection actualValuesAfterLevelTwo = null;
            Action clean = () => { };

            // ACT
            Action act = () =>
            {
                var levelOne = Relevant.Info(expectedValuesLevelOne);

                actualValuesLevelOne = Relevant.Info();

                var levelTwo = Relevant.Info(valuesLevelTwo);

                actualValuesLevelTwo = Relevant.Info();

                clean = () =>
                {
                    // Proper REMAINING disposal order. For use if we see an exception, so we don't pollute other tests.
                    levelOne.Dispose();
                };

                levelTwo.Dispose();

                // Duplicate disposal
                levelTwo.Dispose();

                actualValuesAfterLevelTwo = Relevant.Info();

                levelOne.Dispose();
            };

            // ASSERT
            Assert.ThrowsException <ObjectDisposedException>(act);

            // CLEAN
            clean();
        }
Example #8
0
        public void DisposingOutOfOrderThrows()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            NameValueCollection actualValuesAfterLevelTwo;
            Action clean = () => { };

            // ACT
            Action act = () =>
            {
                var levelOne = Relevant.Info(expectedValuesLevelOne);

                actualValuesLevelOne = Relevant.Info();

                var levelTwo = Relevant.Info(valuesLevelTwo);

                actualValuesLevelTwo = Relevant.Info();

                clean = () =>
                {
                    // Proper disposal order. For use after we see exception, so we don't pollute other tests.
                    levelTwo.Dispose();
                    levelOne.Dispose();
                };

                // Out of order disposal.
                levelOne.Dispose();

                actualValuesAfterLevelTwo = Relevant.Info();

                levelTwo.Dispose();
            };

            // ASSERT
            Assert.ThrowsException <OutOfOrderInfoBlockDisposalException>(act);

            // CLEAN
            clean();
        }
 public async Task <IActionResult> Index(CancellationToken token)
 {
     using (Relevant.Info(new NameValueCollection {
         ["Route"] = nameof(Index)
     }))
     {
         return(await GetViewAsync(token));
     }
 }
Example #10
0
        public void AwaitingACallInsideADifferentNestedBlockReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            Task <NameValueCollection> levelOneTask;
            Task <NameValueCollection> levelTwoTask;

            // ACT
            using (Relevant.Info(expectedValuesLevelOne))
            {
                levelOneTask = TaskWithInfo();

                using (Relevant.Info(valuesLevelTwo))
                {
                    levelTwoTask = TaskWithInfo();
                }
            }

            using (Relevant.Info(new NameValueCollection {
                ["Key1"] = "IncorrectValue"
            }))
            {
                actualValuesLevelOne = levelOneTask.Result;
                actualValuesLevelTwo = levelTwoTask.Result;
            }

            // ASSERT
            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOne, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOne.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOne["Key1"], "should have same value");

            Assert.IsNotNull(actualValuesLevelTwo, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelTwo, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelTwo.Count, actualValuesLevelTwo.Count, $"should have {expectedValuesLevelTwo.Count} pair");
            Assert.AreEqual(expectedValuesLevelTwo["Key1"], actualValuesLevelTwo["Key1"], "should have same value");
            Assert.AreEqual(expectedValuesLevelTwo["Key2"], actualValuesLevelTwo["Key2"], "should have same value");
        }
        public async Task AwaitingWhenAllNestedCallsOutsideANestedBlockReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            Task <NameValueCollection> levelOneTask;
            Task <NameValueCollection> levelTwoTask;

            // ACT
            using (Relevant.Info(expectedValuesLevelOne))
            {
                levelOneTask = AwaitedTaskWithInfo();

                using (Relevant.Info(valuesLevelTwo))
                {
                    levelTwoTask = AwaitedTaskWithInfo();
                }
            }

            await Task.WhenAll(levelOneTask, levelTwoTask);

            actualValuesLevelOne = levelOneTask.Result;
            actualValuesLevelTwo = levelTwoTask.Result;

            // ASSERT
            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOne, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOne.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOne["Key1"], "should have same value");

            Assert.IsNotNull(actualValuesLevelTwo, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelTwo, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelTwo.Count, actualValuesLevelTwo.Count, $"should have {expectedValuesLevelTwo.Count} pair");
            Assert.AreEqual(expectedValuesLevelTwo["Key1"], actualValuesLevelTwo["Key1"], "should have same value");
            Assert.AreEqual(expectedValuesLevelTwo["Key2"], actualValuesLevelTwo["Key2"], "should have same value");
        }
Example #12
0
        public void AccessingInfoWithoutABlockReturnsEmptyCollection()
        {
            // ARRANGE

            // ACT
            var info = Relevant.Info();

            // ASSERT
            Assert.IsNotNull(info, "should have a value");
            Assert.IsInstanceOfType(info, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(0, info.Count, "should have no pairs");
        }
Example #13
0
        public void AccessingNamedInfoWithinDifferentNestedBlocksReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;
            NameValueCollection actualValuesLevelOneInner;

            // ACT
            using (Relevant.Info(expectedValuesLevelOne))
            {
                actualValuesLevelOne = Relevant.Info();

                using (Relevant.Info(valuesLevelTwo, "test"))
                {
                    actualValuesLevelTwo      = Relevant.Info("test");
                    actualValuesLevelOneInner = Relevant.Info();
                }
            }

            // ASSERT
            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOne, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOne.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOne["Key1"], "should have same value");

            Assert.IsNotNull(actualValuesLevelTwo, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelTwo, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(valuesLevelTwo.Count, actualValuesLevelTwo.Count, $"should have {valuesLevelTwo.Count} pair");
            Assert.AreEqual(valuesLevelTwo["Key2"], actualValuesLevelTwo["Key2"], "should have same value");

            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOneInner, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOneInner.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOneInner["Key1"], "should have same value");
        }
Example #14
0
        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            var ourLocalContext = new NameValueCollection {
                ["Route"] = nameof(Contact)
            };

            using (Relevant.Info(ourLocalContext))
            {
                var data = DataRepository.GetSomeData();

                return(GetViewAsync(CancellationToken.None).Result);
            }
        }
Example #15
0
        public void AccessingInfoWithinNestedBlocksReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            // ACT
            var levelOne = Relevant.Info(expectedValuesLevelOne);

            actualValuesLevelOne = Relevant.Info();

            var levelTwo = Relevant.Info(valuesLevelTwo);

            actualValuesLevelTwo = Relevant.Info();

            levelTwo.Dispose();
            levelOne.Dispose();


            // ASSERT
            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOne, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOne.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOne["Key1"], "should have same value");

            Assert.IsNotNull(actualValuesLevelTwo, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelTwo, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelTwo.Count, actualValuesLevelTwo.Count, $"should have {expectedValuesLevelTwo.Count} pair");
            Assert.AreEqual(expectedValuesLevelTwo["Key1"], actualValuesLevelTwo["Key1"], "should have same value");
            Assert.AreEqual(expectedValuesLevelTwo["Key2"], actualValuesLevelTwo["Key2"], "should have same value");
        }
Example #16
0
        public static void Main(string[] args)
        {
            using (Relevant.Info(new NameValueCollection
            {
                ["ExecutingDirectory"] = Directory.GetCurrentDirectory()
            }))
            {
                var host = new WebHostBuilder()
                           .UseKestrel()
                           .UseContentRoot(Directory.GetCurrentDirectory())
                           .UseIISIntegration()
                           .UseStartup <Startup>()
                           .Build();

                host.Run();
            }
        }
Example #17
0
        public void AwaitingNestedCallsWithinANestedBlockReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            // ACT
            using (Relevant.Info(expectedValuesLevelOne))
            {
                actualValuesLevelOne = AwaitedTaskWithInfo().Result;

                using (Relevant.Info(valuesLevelTwo))
                {
                    actualValuesLevelTwo = AwaitedTaskWithInfo().Result;
                }
            }

            // ASSERT
            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOne, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOne.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOne["Key1"], "should have same value");

            Assert.IsNotNull(actualValuesLevelTwo, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelTwo, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelTwo.Count, actualValuesLevelTwo.Count, $"should have {expectedValuesLevelTwo.Count} pair");
            Assert.AreEqual(expectedValuesLevelTwo["Key1"], actualValuesLevelTwo["Key1"], "should have same value");
            Assert.AreEqual(expectedValuesLevelTwo["Key2"], actualValuesLevelTwo["Key2"], "should have same value");
        }
Example #18
0
        public async Task ExceptionConveysRelevantInfo()
        {
            // ARRANGE
            var exception = new Exception();

            // ACT
            using (Relevant.Info("key1", "value1"))
            {
                exception.AttachRelevantInfo();
            }

            var actualRelevantInfo = exception.GetReleventInfo();

            // ASSERT
            Assert.IsNotNull(actualRelevantInfo, "should return a value");
            Assert.AreEqual(1, actualRelevantInfo.Count, $"should have 1 pair");
            Assert.AreEqual("value1", actualRelevantInfo["key1"], "value must match");
        }
Example #19
0
        public static void Testing()
        {
            Console.WriteLine("Generating Random Intergers...");
            int[] array = Relevant.GenerateRandomIntergers(300_000_000, 0, 1_000_000);
            array[array.Length - 1] = int.MaxValue;

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Non_ParallelVersion start:");
            sw.Start();
            GetMaxValueThenPlaceToEnd(array);
            Sort(array, 0, array.Length - 1);
            sw.Stop();
            Console.WriteLine($"Total second of Algorithm: {sw.Elapsed}");
            bool result = Relevant.VerifySequence(array);

            Console.WriteLine($"Verification: {result}");
        }
        public int InsertRelevanteLink(Relevant link)
        {
            SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicatiePlattegrondConnectionString"].ToString());

            using (SqlCommand command = new SqlCommand("", connection))
            {
                connection.Open();
                command.CommandText = "INSERT INTO Relevante_Link (Naam, Link, Dataset_ID) VALUES (@Naam, @Link, @Dataset_ID);";

                command.Parameters.AddWithValue("@Naam", link.Naam);
                command.Parameters.AddWithValue("@Link", link.Link);
                command.Parameters.AddWithValue("@Dataset_ID", link.DatasetID);

                int rowsAffected = command.ExecuteNonQuery();
                connection.Close();

                return(rowsAffected);
            }
        }
        public int UpdateRelevanteLink(Relevant link)
        {
            SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ApplicatiePlattegrondConnectionString"].ToString());

            using (SqlCommand command = new SqlCommand("", connection))
            {
                connection.Open();
                command.CommandText = "UPDATE Relevante_Link SET Naam = @Naam, Link = @Link WHERE ID = @ID";

                command.Parameters.AddWithValue("@Naam", link.Naam);
                command.Parameters.AddWithValue("@Link", link.Link);
                command.Parameters.AddWithValue("@ID", link.Id);

                int rowsAffected = command.ExecuteNonQuery();
                connection.Close();

                return(rowsAffected);
            }
        }
Example #22
0
        public void AwaitingNestedCallsAfterASingleBlockReturnsEmptyCollection()
        {
            // ARRANGE
            NameValueCollection actual;

            // ACT
            using (Relevant.Info(new NameValueCollection {
                ["Key1"] = "Value1"
            }))
            {
                var unusedValues = AwaitedTaskWithInfo().Result;
            }

            actual = AwaitedTaskWithInfo().Result;

            // ASSERT
            Assert.IsNotNull(actual, "should have a value");
            Assert.IsInstanceOfType(actual, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(0, actual.Count, "should have no pairs");
        }
Example #23
0
        public void AccessingInfoAfterASingleBlockReturnsEmptyCollection()
        {
            // ARRANGE
            NameValueCollection actual;

            // ACT
            var infoBlock = Relevant.Info(new NameValueCollection {
                ["Key1"] = "Value1"
            });

            var unusedValues = Relevant.Info();

            infoBlock.Dispose();

            actual = Relevant.Info();

            // ASSERT
            Assert.IsNotNull(actual, "should have a value");
            Assert.IsInstanceOfType(actual, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(0, actual.Count, "should have no pairs");
        }
Example #24
0
        public void AwaitingNestedCallsWithinASingleBlockReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValues = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            NameValueCollection actualValues;

            // ACT
            using (Relevant.Info(expectedValues))
            {
                actualValues = AwaitedTaskWithInfo().Result;
            }

            // ASSERT
            Assert.IsNotNull(actualValues, "should have a value");
            Assert.IsInstanceOfType(actualValues, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValues.Count, actualValues.Count, $"should have {expectedValues.Count} pair");
            Assert.AreEqual(expectedValues["Key1"], actualValues["Key1"], "should have same value");
        }
Example #25
0
        public void AccessingInfoWithinASingleBlockReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValues = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            NameValueCollection actualValues;

            // ACT
            var infoBlock = Relevant.Info(expectedValues);

            actualValues = Relevant.Info();

            infoBlock.Dispose();

            // ASSERT
            Assert.IsNotNull(actualValues, "should have a value");
            Assert.IsInstanceOfType(actualValues, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValues.Count, actualValues.Count, $"should have {expectedValues.Count} pair");
            Assert.AreEqual(expectedValues["Key1"], actualValues["Key1"], "should have same value");
        }
Example #26
0
        public async Task TopExceptionOverridesRelevantInfo()
        {
            // ARRANGE
            var innerException = new Exception("inner error");
            var topException   = new Exception("error", innerException);

            // ACT
            using (Relevant.Info("key", "value to be overriden"))
            {
                innerException.AttachRelevantInfo();
            }

            using (Relevant.Info("key", "value"))
            {
                topException.AttachRelevantInfo();
            }

            var actualRelevantInfo = topException.GetReleventInfo();

            // ASSERT
            Assert.IsNotNull(actualRelevantInfo, "should return a value");
            Assert.AreEqual(1, actualRelevantInfo.Count, $"should have 1 pair");
            Assert.AreEqual("value", actualRelevantInfo["key"], "value must match");
        }
Example #27
0
        public async Task AwaitingACallInsideADifferentNestedBlockUsingAStartedThreadReturnsExpectedValues()
        {
            // ARRANGE
            var expectedValuesLevelOne = new NameValueCollection
            {
                ["Key1"] = "Value1"
            };

            var expectedValuesLevelTwo = new NameValueCollection
            {
                ["Key1"] = "Value1",
                ["Key2"] = "Value2"
            };

            var valuesLevelTwo = new NameValueCollection
            {
                ["Key2"] = "Value2"
            };

            NameValueCollection actualValuesLevelOne;
            NameValueCollection actualValuesLevelTwo;

            Task <NameValueCollection> levelOneTask = null;
            Task <NameValueCollection> levelTwoTask = null;
            Thread assignerThread;

            // ACT

            using (Relevant.Info(expectedValuesLevelOne))
            {
                assignerThread = new Thread(new ThreadStart(() => levelOneTask = TaskWithInfo()));

                assignerThread.Start();

                assignerThread.Join();

                using (Relevant.Info(valuesLevelTwo))
                {
                    levelTwoTask = TaskWithInfo();
                }
            }

            using (Relevant.Info(new NameValueCollection {
                ["Key1"] = "IncorrectValue"
            }))
            {
                actualValuesLevelOne = await levelOneTask;
                actualValuesLevelTwo = await levelTwoTask;
            }

            // ASSERT
            Assert.IsNotNull(actualValuesLevelOne, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelOne, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelOne.Count, actualValuesLevelOne.Count, $"should have {expectedValuesLevelOne.Count} pair");
            Assert.AreEqual(expectedValuesLevelOne["Key1"], actualValuesLevelOne["Key1"], "should have same value");

            Assert.IsNotNull(actualValuesLevelTwo, "should have a value");
            Assert.IsInstanceOfType(actualValuesLevelTwo, typeof(NameValueCollection), "should be a NameValueCollection");
            Assert.AreEqual(expectedValuesLevelTwo.Count, actualValuesLevelTwo.Count, $"should have {expectedValuesLevelTwo.Count} pair");
            Assert.AreEqual(expectedValuesLevelTwo["Key1"], actualValuesLevelTwo["Key1"], "should have same value");
            Assert.AreEqual(expectedValuesLevelTwo["Key2"], actualValuesLevelTwo["Key2"], "should have same value");
        }
Example #28
0
 private static Task <NameValueCollection> TaskWithInfo()
 {
     return(Task.FromResult(Relevant.Info()));
 }