Beispiel #1
0
            public void ShouldExportChildPagesRecursively()
            {
                var parent = new Page {
                    PageTitle = "Parent"
                };
                var child = new Page {
                    PageTitle = "Child"
                };
                var grandchild = new Page {
                    PageTitle = "Grandchild"
                };

                parent.Pages = new List <Page> {
                    child
                };
                child.Pages = new List <Page> {
                    grandchild
                };
                var          result        = parent.ToJson( );
                const string parentKey     = "\"Title\": \"Parent\"";
                const string childKey      = "\"Title\": \"Child\"";
                const string grandChildKey = "\"Title\": \"Grandchild\"";

                Assert.Greater(result.IndexOf(parentKey), -1);
                Assert.Greater(result.IndexOf(childKey), -1);
                Assert.Greater(result.IndexOf(grandChildKey), -1);
            }
Beispiel #2
0
        public void HexWith2DigitsEscapedSelector()
        {
            string html   = "<div id=\"B&W?\"><p>test</p></div>";
            var    dom    = CsQuery.CQ.CreateFragment(html);
            var    result = dom.Select("#B\\26 W\\3F");

            Assert.Greater(result.Length, 0);
        }
        public async Task TestMvcMusicStore()
        {
            string solutionPath = Directory.EnumerateFiles(tempDir, "MvcMusicStore.sln", SearchOption.AllDirectories).FirstOrDefault();

            FileAssert.Exists(solutionPath);

            AnalyzerConfiguration configuration = new AnalyzerConfiguration(LanguageOptions.CSharp)
            {
                ExportSettings =
                {
                    GenerateJsonOutput = false,
                    OutputPath         = @"/tmp/UnitTests"
                },

                MetaDataSettings =
                {
                    LiteralExpressions = true,
                    MethodInvocations  = true,
                    Annotations        = true,
                    DeclarationNodes   = true,
                    LocationData       = false,
                    ReferenceData      = true,
                    LoadBuildData      = true
                }
            };
            CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(configuration, NullLogger.Instance);

            using var result = (await analyzer.AnalyzeSolution(solutionPath)).FirstOrDefault();
            Assert.True(result != null);
            Assert.False(result.ProjectBuildResult.IsSyntaxAnalysis);

            Assert.AreEqual(28, result.ProjectResult.SourceFiles.Count);

            //Project has 16 nuget references and 19 framework/dll references:
            Assert.AreEqual(29, result.ProjectResult.ExternalReferences.NugetReferences.Count);
            Assert.AreEqual(24, result.ProjectResult.ExternalReferences.SdkReferences.Count);

            var homeController = result.ProjectResult.SourceFileResults.Where(f => f.FilePath.EndsWith("HomeController.cs")).FirstOrDefault();

            Assert.NotNull(homeController);

            var classDeclarations = homeController.Children.OfType <Codelyzer.Analysis.Model.NamespaceDeclaration>().FirstOrDefault();

            Assert.Greater(classDeclarations.Children.Count, 0);

            var classDeclaration = homeController.Children.OfType <Codelyzer.Analysis.Model.NamespaceDeclaration>().FirstOrDefault().Children[0];

            Assert.NotNull(classDeclaration);

            var declarationNodes   = classDeclaration.Children.OfType <Codelyzer.Analysis.Model.DeclarationNode>();
            var methodDeclarations = classDeclaration.Children.OfType <Model.MethodDeclaration>();

            //HouseController has 3 identifiers declared within the class declaration:
            Assert.AreEqual(4, declarationNodes.Count());

            //It has 2 method declarations
            Assert.AreEqual(2, methodDeclarations.Count());
        }
Beispiel #4
0
            public void ShouldExportAsJson()
            {
                var blockType = new BlockType
                {
                    Name = "Foo"
                };
                var          result = blockType.ToJson();
                const string key    = "\"Name\": \"Foo\"";

                Assert.Greater(result.IndexOf(key), -1, string.Format("'{0}' was not found in '{1}'.", key, result));
            }
Beispiel #5
0
            public void ShouldSerializeAsJsonViaCustomConverter()
            {
                var device = DeviceAtCCV();

                var    result = device.ToJson();
                string key1   = "\"GeoPoint\": {";
                string key2   = "\"WellKnownText\": ";

                Assert.Greater(result.IndexOf(key1), -1, string.Format("'{0}' was not found in '{1}'.", key1, result));
                Assert.Greater(result.IndexOf(key2), -1, string.Format("'{0}' was not found in '{1}'.", key2, result));
            }
Beispiel #6
0
            public void ShouldExportAsJson()
            {
                var html = new HtmlContent
                {
                    Content = "Foo"
                };

                var          result = html.ToJson();
                const string key    = "\"Content\": \"Foo\"";

                Assert.Greater(result.IndexOf(key), -1, string.Format("'{0}' was not found in '{1}'.", key, result));
            }
Beispiel #7
0
        public void CreatePostActionShouldReturnCreateViewAndModelStateWithErrorsForInvalidEntityData()
        {
            // Prepare
            FillControllerValueProviderWithEntityToInsertKeyNamesAndValues(_invalidEntity);

            // Act
            var result = _controller.Create(null) as ViewResult;

            // Assert
            CheckActionReturnsAViewResultAndHasAModelOfType(result, "Create", typeof(ModelInstance));
            Assert.Greater(_controller.ModelState.Count, 0, "ModelState error should exist");
        }
Beispiel #8
0
            public void ShouldExportAsJson()
            {
                var page = new Page
                {
                    PageTitle = "FooPage"
                };

                var          result = page.ToJson();
                const string key    = "\"Title\": \"FooPage\"";

                Assert.Greater(result.IndexOf(key), -1, string.Format("'{0}' was not found in '{1}'.", key, result));
            }
Beispiel #9
0
            public void ShouldExportAsJson()
            {
                var guid        = Guid.NewGuid();
                var pageContext = new PageContext
                {
                    Guid = guid
                };

                var result = pageContext.ToJson();
                var key    = string.Format("\"Guid\": \"{0}\"", guid);

                Assert.Greater(result.IndexOf(key), -1, string.Format("'{0}' was not found in '{1}'.", key, result));
            }
Beispiel #10
0
    public IEnumerator TestAddressableAsyncLoad()
    {
        yield return(ValidateTestDependency());

        PreInstall();
        AsyncOperationHandle <GameObject> handle = default;

        Container.BindAsync <GameObject>().FromMethod(async() =>
        {
            try
            {
                var locationsHandle = Addressables.LoadResourceLocationsAsync("TestAddressablePrefab");
                await locationsHandle.Task;
                Assert.Greater(locationsHandle.Result.Count, 0, "Key required for test is not configured. Check Readme.txt in addressable test folder");

                IResourceLocation location = locationsHandle.Result[0];
                handle = Addressables.LoadAsset <GameObject>(location);
                await handle.Task;
                return(handle.Result);
            }
            catch (InvalidKeyException)
            {
            }
            return(null);
        }).AsCached();
        PostInstall();

        yield return(null);

        AsyncInject <GameObject> asycFoo = Container.Resolve <AsyncInject <GameObject> >();

        int frameCounter = 0;

        while (!asycFoo.HasResult && !asycFoo.IsFaulted)
        {
            frameCounter++;
            if (frameCounter > 10000)
            {
                Addressables.Release(handle);
                Assert.Fail();
            }
            yield return(null);
        }

        Addressables.Release(handle);
        Assert.Pass();
    }
        public void NormalDistribution(double mean, double sd, double min, double max)
        {
            const int iterations = 100;
            var       rand       = new Random();
            var       fit        = 0.0;

            for (var i = 0; i < iterations; i++)
            {
                var normal = rand.NormalDistribution(mean, sd);
                if (min <= normal && normal <= max)
                {
                    fit++;
                }
            }

            Assert.Greater(fit, iterations * 0.9);
        }
        public void Initialize_Test(int neurals, int weights, double between)
        {
            var layer = new PerceptronLayer(neurals, weights);
            var fit   = 0;

            foreach (var perceptron in layer.Neurals)
            {
                foreach (double weight in perceptron.Weights)
                {
                    if (-between <= weight && weight < between)
                    {
                        fit++;
                    }
                }
            }

            Assert.Greater(fit, neurals * weights * 0.9);
        }
Beispiel #13
0
            public void ShouldExportChildPages()
            {
                var page = new Page
                {
                    PageTitle = "FooPage",
                    Pages     = new List <Page> {
                        new Page {
                            PageTitle = "BarPage"
                        }
                    }
                };

                var result = page.ToJson();

                result = result.Substring(result.IndexOf("\"Pages\":") + 7);
                const string key = "\"Title\": \"BarPage\"";

                Assert.Greater(result.IndexOf(key), -1);
            }
        public void Get_ReturnIfEntityExist()
        {
            var repository = new Mock <IRepository <Team> >();
            var restClient = new Mock <IRestClient>();

            var entity = new List <Team>()
            {
                new Team()
                {
                    Id       = 1,
                    Name     = "Test",
                    LeagueId = 3
                },
                new Team()
                {
                    Id       = 2,
                    Name     = "Test2",
                    LeagueId = 3
                }
            };

            var leagueResponse = new ResponseLeague()
            {
                Id   = 3,
                Name = "Test League",
            };

            var response = new RestResponse <ResponseLeague>()
            {
                Content    = JsonConvert.SerializeObject(leagueResponse),
                StatusCode = HttpStatusCode.OK
            };

            restClient.Setup(st => st.Execute(It.IsAny <RestRequest>())).Returns(() => response);
            repository.Setup(st => st.List()).Returns(() => entity);

            var service = new TeamService(restClient.Object, repository.Object);
            var result  = service.Get();

            Assert.IsNotNull(result);
            Assert.Greater(result.Count, 0);
        }
 public void TestMainHumidityAboveZero()
 {
     Assert.Greater(service.WeatherDTO.WeatherAPIRoots.Main.Humidity, 0.0);
 }