Exemplo n.º 1
0
        private bool TryCompose(TestBundle testBundle, IEnumerable <TestBundle> partials, out TestBundle composition)
        {
            var scope = _logger.BeginScope().AttachElapsed();

            try
            {
                composition             = _componentContext.Resolve <TestBundle>();
                composition.FullName    = testBundle.FullName;
                composition.Variables   = Merge(testBundle, partials, bundle => bundle.Variables).ToList();
                composition.DataSources = Merge(testBundle, partials, bundle => bundle.DataSources).ToList();
                composition.Tests       = Merge(testBundle, partials, bundle => bundle.Tests).ToList();
                composition.Messages    = Merge(testBundle, partials, bundle => bundle.Messages).ToList();
                composition.Reports     = Merge(testBundle, partials, bundle => bundle.Reports).ToList();

                composition.ValidateWith(TestBundleBouncer).Assert();

                _logger.Log(Abstraction.Layer.Infrastructure().Routine(nameof(TryCompose)).Completed(), testBundle.FileName.ToString());

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Log(Abstraction.Layer.Infrastructure().Routine(nameof(TryCompose)).Faulted(), testBundle.FileName.ToString(), ex);
                composition = default;
                return(false);
            }
            finally
            {
                scope.Dispose();
            }
        }
Exemplo n.º 2
0
        public static void RegisterBundles(BundleCollection bundles)
        {
            var frontpageAll = new ScriptBundle("~/bundles/js");

            frontpageAll.Include("~/Scripts/lib/jquery-{version}.js")
            .Include(
                "~/Scripts/lib/jquery.ui.core.js",
                "~/Scripts/lib/jquery.ui.widget.js",
                "~/Scripts/lib/jquery.ui.position.js",
                "~/Scripts/lib/jquery.ui.dialog.js",
                "~/Scripts/lib/jquery.ui.mouse.js",
                "~/Scripts/lib/jquery.ui.sortable.js",
                "~/Scripts/handlebars.js")
            .Include("~/Scripts/bootstrap.js")
            .IncludeDirectory("~/Scripts/frontpage", "*.js");


            var frontpage     = new NontestBundle("~/bundles/frontpage", frontpageAll);
            var frontpageTest = new TestBundle("~/bundles/frontpage-test", frontpageAll);

            bundles.Add(frontpage);
            bundles.Add(frontpageTest);

            var southStreetTheme = new StyleBundle("~/Content/themes/south-street/all.css")
                                   .IncludeDirectory("~/Content/themes/south-street/", "*.css")
                                   .Include("~/Content/bootstrap.css");

            bundles.Add(southStreetTheme);
        }
Exemplo n.º 3
0
        private IEnumerable <T> Merge <T>(TestBundle testBundle, IEnumerable <TestBundle> partials, Func <TestBundle, IEnumerable <T> > selectMergeables) where T : class, IMergeable
        {
            var mergeables = selectMergeables(testBundle);

            foreach (var mergeable in mergeables)
            {
                if (mergeable.Merge is null)
                {
                    yield return(mergeable);

                    continue;
                }

                var merge           = mergeable.Merge;
                var otherTestBundle = partials.SingleOrDefault(p => p.Name == merge.OtherFileName) ?? throw DynamicException.Create("OtherTestBundleNotFound", $"Could not find test bundle '{merge.OtherFileName}'.");
                var otherMergeables = selectMergeables(otherTestBundle).SingleOrDefault(x => x.Id == merge.OtherId) ?? throw DynamicException.Create("OtherMergeableNotFound", $"Could not find mergeable '{merge.OtherId}'.");

                var(first, second) = (mergeable, otherMergeables);

                var merged = (IMergeable)_componentContext.Resolve(mergeable.GetType());
                merged.Id    = mergeable.Id;
                merged.Merge = mergeable.Merge;

                var mergeableProperties = merged.GetType().GetProperties().Where(p => p.IsDefined(typeof(MergableAttribute)));

                foreach (var property in mergeableProperties)
                {
                    var firstValue = property.GetValue(first);
                    var newValue   = property.GetValue(second);
                    switch (firstValue)
                    {
                    case IEnumerable <SoftString> x when newValue is IEnumerable <SoftString> y:
                        newValue = x.Union(y).ToList();
                        break;

                    case IEnumerable <KeyValuePair <SoftString, object> > x when newValue is IEnumerable <KeyValuePair <SoftString, object> > y:
                        newValue = x.Union(y).ToDictionary(p => p.Key, p => p.Value);
                        break;
                    }

                    if (property.GetCustomAttribute <MergableAttribute>().Required&& newValue is null)
                    {
                        throw DynamicException.Create(
                                  "MissingValue",
                                  $"You need to specify a value for '{property.Name}' in '{testBundle.FileName}'. Either directly or via a merge."
                                  );
                    }

                    property.SetValue(merged, newValue);
                }

                yield return((T)merged);
            }
        }
Exemplo n.º 4
0
        public void In_Use_With_Description_Does_Request()
        {
            var bundle = new TestBundle
                {
                    RequriesBackgroundLocation = false,
                    InUseLocationReason = "reason"
                };

            var manager = new VerfyAuthorizeLocationManager();
            manager.RequestAuthorization(bundle);
            Assert.Equal(CLAuthorizationStatus.AuthorizedWhenInUse, manager.RequestedStatus);
        }
Exemplo n.º 5
0
        public void Background_With_Description_Does_Not_Throw()
        {
            var bundle = new TestBundle
                {
                    RequriesBackgroundLocation = true,
                    BackgroundLocationReason = "reason"
                };

            var manager = new VerfyAuthorizeLocationManager();
            manager.RequestAuthorization(bundle);
            Assert.Equal(CLAuthorizationStatus.AuthorizedAlways, manager.RequestedStatus);
        }
Exemplo n.º 6
0
        public void In_Use_With_Description_Does_Request()
        {
            var bundle = new TestBundle
            {
                RequriesBackgroundLocation = false,
                InUseLocationReason        = "reason"
            };

            var manager = new VerfyAuthorizeLocationManager();

            manager.RequestAuthorization(bundle);
            Assert.Equal(CLAuthorizationStatus.AuthorizedWhenInUse, manager.RequestedStatus);
        }
Exemplo n.º 7
0
        public void Background_With_Description_Does_Not_Throw()
        {
            var bundle = new TestBundle
            {
                RequriesBackgroundLocation = true,
                BackgroundLocationReason   = "reason"
            };

            var manager = new VerfyAuthorizeLocationManager();

            manager.RequestAuthorization(bundle);
            Assert.Equal(CLAuthorizationStatus.AuthorizedAlways, manager.RequestedStatus);
        }
Exemplo n.º 8
0
        public void In_Use_With_No_Description_Throws()
        {
            var bundle = new TestBundle
                {
                    RequriesBackgroundLocation = false
                };

            var manager = new VerfyAuthorizeLocationManager();
            Assert.Throws<InvalidOperationException>(() =>
                manager.RequestAuthorization(bundle)
            );
            Assert.Equal(CLAuthorizationStatus.NotDetermined, manager.RequestedStatus);
        }
Exemplo n.º 9
0
        public void In_Use_With_No_Description_Throws()
        {
            var bundle = new TestBundle
            {
                RequriesBackgroundLocation = false
            };

            var manager = new VerfyAuthorizeLocationManager();

            Assert.Throws <InvalidOperationException>(() =>
                                                      manager.RequestAuthorization(bundle)
                                                      );
            Assert.Equal(CLAuthorizationStatus.NotDetermined, manager.RequestedStatus);
        }
Exemplo n.º 10
0
        public static bool IsPartial([NotNull] this TestBundle testBundle)

        {
            if (testBundle == null)
            {
                throw new ArgumentNullException(nameof(testBundle));
            }
            Debug.Assert(testBundle.FileName.IsNotNullOrEmpty());

            return
                (Path
                 .GetFileName(testBundle.FullName)
                 .StartsWith("_", StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 11
0
        private async Task RunTestsAsync(TestBundle testBundle, IEnumerable <SoftString> profiles)
        {
            var testIndex = 0;
            var tests     =
                from testCase in testBundle.Tests
                where testCase.CanExecute(profiles)
                from dataSource in testCase.DataSources(testBundle)
                select(testCase, dataSource, testIndex: testIndex++);

            var testBundleFormatter = _createRuntimeFormatter(testBundle.AllVariables(), new object[] { testBundle });

            var cache = new Dictionary <SoftString, (DataTable Data, string Query, TimeSpan Elapsed)>();

            using (_logger.BeginScope().WithCorrelationContext(new { TestBundle = testBundle.FileName }).AttachElapsed())
                using (Disposable.Create(() => { foreach (var(data, _, _) in cache.Values)
                                                 {
                                                     data.Dispose();
                                                 }
                                         }))
                {
                    foreach (var current in tests)
                    {
                        using (_logger.BeginScope().WithCorrelationContext(new { TestCase = current.testCase.Id }).AttachElapsed())
                        {
                            try
                            {
                                if (!cache.TryGetValue(current.dataSource.Id, out var cacheItem))
                                {
                                    var getDataStopwatch = Stopwatch.StartNew();
                                    var(data, query) = await current.dataSource.GetDataAsync(testBundle.Directoryname, testBundleFormatter);

                                    cache[current.dataSource.Id] = cacheItem = (data, query, getDataStopwatch.Elapsed);
                                }

                                var(result, elapsed, actions) = RunTest(current.testCase, cacheItem.Data);

                                _logger.Log(Abstraction.Layer.Infrastructure().Meta(new
                                {
                                    Test = new
                                    {
                                        current.testCase.Id,
                                        Result  = result,
                                        Elapsed = elapsed.ToString(@"mm\:ss\.fff"),
                                        Actions = actions
                                    }
                                }));

                                if (actions.Alert())
                                {
                                    var testCaseFormatter =
                                        _createRuntimeFormatter(
                                            variables: testBundle.AllVariables(),
                                            runtimeObjects: new object[]
                                    {
                                        testBundle,
                                        current.testCase,
                                        current.dataSource,
                                        new TestCounter
                                        {
                                            GetDataElapsed = cacheItem.Elapsed,
                                            RunTestElapsed = elapsed
                                        },
                                    }
                                            );

                                    await AlertAsync(new TestContext
                                    {
                                        TestBundle = testBundle,
                                        TestCase   = current.testCase,
                                        DataSource = current.dataSource,
                                        Data       = cacheItem.Data,
                                        Formatter  = testCaseFormatter,
                                        Query      = cacheItem.Query
                                    });
                                }

                                if (actions.Halt())
                                {
                                    break;
                                }

                                _logger.Log(Abstraction.Layer.Business().Routine(nameof(RunTestsAsync)).Completed());
                            }
                            catch (DynamicException ex) when(ex.NameMatches("^DataSource"))
                            {
                                _logger.Log(Abstraction.Layer.Business().Routine(nameof(RunTestsAsync)).Faulted(), ex);
                                break;
                            }
                            catch (Exception ex)
                            {
                                _logger.Log(Abstraction.Layer.Business().Routine(nameof(RunTestsAsync)).Faulted(), ex);
                            }
                        }
                    }
                }
        }
Exemplo n.º 12
0
 private void OnEnable()
 {
     testBundle        = (TestBundle)target;
     testBundle.assets = UnityEditor.AssetDatabase.GetAllAssetBundleNames();
 }
Exemplo n.º 13
0
 public static IEnumerable <KeyValuePair <SoftString, object> > AllVariables(this TestBundle testBundle) => testBundle.Variables.SelectMany(x => x);
Exemplo n.º 14
0
 public void TestFixtureSetup()
 {
     using (var zippedBundle = CreateDummyVersion1_5ZippedTestBundle())
         m_bundle = new TestBundle(zippedBundle.Path);
 }
Exemplo n.º 15
0
 public void TestFixtureSetup()
 {
     using (var zippedBundle = CreateZippedTestBundleFromResources())
         m_bundle = new TestBundle(zippedBundle.Path);
 }