public void AllMetrics_SampleData_Recorded()
        {
            const int NumberOfItems = 42;
            var errors = new KeyValuePair<string, Exception>[]
            {
                new KeyValuePair<string, Exception>("1", new Exception()),
                new KeyValuePair<string, Exception>("2", new ArgumentException()),
                new KeyValuePair<string, Exception>("3", new KeyNotFoundException())
            };

            var statistics = new InMemoryTransferStatistics(ErrorDetailsProviderMock.Instance);

            statistics.Start();

            for (var index = 0; index < NumberOfItems; ++index)
                statistics.AddTransferred();

            foreach (var error in errors)
                statistics.AddError(error.Key, error.Value);

            statistics.Stop();

            var result = statistics.GetSnapshot();

            Assert.IsNotNull(result, TestResources.NullStatisticsSnapshot);
            Assert.AreNotEqual(TimeSpan.Zero, result.ElapsedTime, TestResources.StatisticsElapsedTimeIsEmpty);
            Assert.AreEqual(NumberOfItems, result.Transferred, TestResources.StatisticsInvalidTransferredCount);
            Assert.AreEqual(errors.Length, result.Failed, TestResources.StatisticsInvalidFailedCount);
            CollectionAssert.AreEquivalent(errors.ToDictionary(e => e.Key, e => ErrorDetailsProviderMock.Instance.Get(e.Value)), result.GetErrors().ToArray(),
                TestResources.StatisticsInvalidErrors);
        } 
Example #2
0
 private void AssertIndexes(KeyValuePair<int, string>[] data, int[] indexes)
 {
     var dic = data.ToDictionary(k => k.Key);
     Assert.AreEqual(indexes.Length, data.Length, "Found wrong amount");
     for (int i = 0; i < data.Length; ++i)
     {
         Assert.AreEqual(indexes[i], dic[indexes[i]].Key, "Wrong index found at position " + i);
     }
 }
Example #3
0
 public IDictionary<string, string> ToDictionary(KeyValuePair<string, string>[] v)
 {
     return v.ToDictionary();
 }