Esempio n. 1
0
        public void FindBooksWithCSharpInTheirTitleLike()
        {
            //SETUP
            var sqlite = new SqliteInMemory();

            using (var context = sqlite.GetContextWithSetup())
            {
                context.SeedDatabase(TestFileHelpers.GetSolutionDirectory() + @"\EfCoreInAction\wwwroot\");
                sqlite.ClearLogs();

                //ATTEMPT
                var bookTitles = context.Books
                                 .Where(p => EF.Functions.Like(p.Title, "%C#%"))
                                 .Select(p => p.Title)
                                 .ToList();


                //VERIFY
                bookTitles.Count.ShouldEqual(5);
                foreach (var title in bookTitles)
                {
                    _output.WriteLine(title);
                }
            }
        }
Esempio n. 2
0
        public void Check02DatabaseDataLinksOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                DataLayerInitialise.InitialiseThis();
                var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");

                //ATTEMPT
                DataLayerInitialise.ResetDatabaseToTestData(db, filepath);

                //VERIFY
                var allPosts = db.Posts.Include(x => x.Blogger).Include(x => x.Tags).ToList();
                allPosts[0].Blogger.Name.ShouldEqual("Fred Bloggs");
                string.Join(",", allPosts[0].Tags.Select(x => x.Slug)).ShouldEqual("ugly,bad");
                allPosts[1].Blogger.Name.ShouldEqual("Jon Smith");
                string.Join(",", allPosts[1].Tags.Select(x => x.Slug)).ShouldEqual("good,ugly");
                allPosts[2].Blogger.Name.ShouldEqual("Jon Smith");
                string.Join(",", allPosts[2].Tags.Select(x => x.Slug)).ShouldEqual("bad");

                db.PostTagGrades.Count().ShouldEqual(2);
                db.PostTagGrades.ToList().All(x => x.PostId == allPosts[0].PostId).ShouldEqual(true);
                string.Join(",", db.PostTagGrades.Include(x => x.TagPart).Select(x => x.TagPart.Slug)).ShouldEqual("bad,ugly");
            }
        }
 public void SetUpFixture()
 {
     using (var db = new SampleWebAppDb())
     {
         DataLayerInitialise.InitialiseThis();
         var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
         DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
     }
 }
Esempio n. 4
0
        public void TestGetSolutionDirectoryOk()
        {
            //SETUP

            //ATTEMPT
            var testDir = TestFileHelpers.GetSolutionDirectory();

            //VERIFY
            testDir.EndsWith(@"EfCoreInAction").ShouldBeTrue(testDir);
        }
Esempio n. 5
0
        public void TestGetTestProjectDirectoryOk()
        {
            //SETUP

            //ATTEMPT
            var testDir = TestFileHelpers.GetTestDataFileDirectory();

            //VERIFY
            testDir.EndsWith(@"EfCoreInAction\test\TestData").ShouldBeTrue(testDir);
        }
        public void TestCreateReadBundleFileCdnOk()
        {
            //SETUP

            //ATTEMPT
            var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles02*.json"));

            //VERIFY
            CollectionAssert.AreEqual(new[] { "mainCss", "standardLibsJs", "appLibsJs", "jqueryval" }, reader.BundleNames);
        }
        public void TestReadBundleFileOk()
        {
            //SETUP

            //ATTEMPT
            using (new TimerToConsole("Read bundleFile"))
            {
                new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json"));
            }
            //VERIFY
        }
        public void CheckReadDefaultConfigAndUserConfigOk()
        {
            //SETUP

            //ATTEMPT
            using (new TimerToConsole("Read default config and user config"))
            {
                ConfigInfo.ReadConfig(TestFileHelpers.GetTestFileFilePath("bundlerForBower02*.json"));
            }
            //VERIFY
        }
        public void TestGetBundleCdnInfoNonCdnOk()
        {
            //SETUP
            var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json"));

            //ATTEMPT
            var cdns = reader.GetBundleCdnInfo("standardLibsJs");

            //VERIFY
            cdns.Count.ShouldEqual(0);
        }
        public void TestGetBundleDebugFilesCndFileBundleListOk(string bundleName, params string[] expectedfiles)
        {
            //SETUP
            var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json"));

            //ATTEMPT
            var files = reader.GetBundleDebugFiles(bundleName, "");

            //VERIFY
            CollectionAssert.AreEqual(expectedfiles, files);
        }
        public void TestGetBundleDebugFilesBadCndFileBundleSingleOk()
        {
            //SETUP
            var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles03*.json"));

            //ATTEMPT
            var ex = Assert.Throws <InvalidOperationException>(() => reader.GetBundleDebugFiles("missingDevelopmentJs"));

            //VERIFY
            ex.Message.ShouldEqual("The CDN bundle missingDevelopmentJs, array element 0, is missing a property called 'development'.");
        }
Esempio n. 12
0
        public void TestBookLoadOk()
        {
            //SETUP
            const string searchFile  = "JsonBooks01*.json";
            var          testDataDir = TestFileHelpers.GetTestDataFileDirectory();

            //ATTEMPT
            var books = BookJsonLoader.LoadBooks(testDataDir, searchFile);

            //VERIFY
            books.Count().ShouldEqual(4);
        }
        public void TestGetBundleDebugFilesNonCndFileBundleSingleOk(string bundleName, string expectedfile)
        {
            //SETUP
            var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles01*.json"));

            //ATTEMPT
            var files = reader.GetBundleDebugFiles(bundleName, "").ToList();

            //VERIFY
            files.Count().ShouldEqual(1);
            files[0].ShouldEqual(expectedfile);
        }
        public void TestCheckSingleBundleIsValidBadCndMissingCdnSuccessTestOk()
        {
            //SETUP
            var checker = new CheckBundles(TestFileHelpers.GetTestDataFileDirectory(), B4BSetupHelper.GetDirRelToTestDirectory("BadBowerBundlesFormat\\"));

            //ATTEMPT
            var errors = checker.CheckSingleBundleIsValid("BadCndMissingCdnSuccessTest");

            //VERIFY
            errors.Count.ShouldEqual(1);
            errors.First().ShouldEqual("In the bundle called BadCndMissingCdnSuccessTest, array element 0, the following properties were missing: cdnSuccessTest");
        }
        public void TestCheckSingleBundleIsValidBadCndBadCndCssNotSupportedOk()
        {
            //SETUP
            var checker = new CheckBundles(TestFileHelpers.GetTestDataFileDirectory(), B4BSetupHelper.GetDirRelToTestDirectory("BadBowerBundlesFormat\\"));

            //ATTEMPT
            var errors = checker.CheckSingleBundleIsValid("BadCndCssNotSupported");

            //VERIFY
            errors.Count.ShouldEqual(1);
            errors.First().ShouldEqual("This configuration of BundlerForBower does not support CDN bundles for .css files. Bad bundle is BadCndCssNotSupported.");
        }
        public void TestCheckSingleBundleIsValidBadCndContainsMixOk()
        {
            //SETUP
            var checker = new CheckBundles(TestFileHelpers.GetTestDataFileDirectory(), B4BSetupHelper.GetDirRelToTestDirectory("BadBowerBundlesFormat\\"));

            //ATTEMPT
            var errors = checker.CheckSingleBundleIsValid("BadCndContainsMix");

            //VERIFY
            errors.Count.ShouldEqual(1);
            errors.First().ShouldEqual("The Bundle called BadCndContainsMix contained both cdn and non cdn entries, which is not supported.");
        }
        public void TestCheckSingleBundleIsValidMissingDevProdOk()
        {
            //SETUP
            var checker = new CheckBundles(TestFileHelpers.GetTestDataFileDirectory(), B4BSetupHelper.GetDirRelToTestDirectory("BadBowerBundlesFormat\\"));

            //ATTEMPT
            var errors = checker.CheckSingleBundleIsValid("BadCndMissingDev");

            //VERIFY
            errors.Count.ShouldEqual(1);
            errors.First().ShouldEqual("The CDN bundle BadCndMissingDev, array element 0, is missing a property called 'development'.");
        }
        public void CheckGetActualFilePathFromVirtualPathDirOk()
        {
            //SETUP
            var          func    = B4BSetupHelper.GetActualFilePathFromVirtualPath();
            const string relPath = "Scripts\\";

            //ATTEMPT
            var path = func("~/" + relPath);

            //VERIFY
            path.ShouldEqual(Path.Combine(TestFileHelpers.GetTestDataFileDirectory(), relPath));
        }
        public void CheckGetActualFilePathFromVirtualPathFileOk()
        {
            //SETUP
            var          func    = B4BSetupHelper.GetActualFilePathFromVirtualPath();
            const string relPath = "Scripts\\Script1.js";

            //ATTEMPT
            var path = func("~/" + relPath);

            //VERIFY
            path.ShouldEqual(TestFileHelpers.GetTestFileFilePath(relPath));
        }
        public void TestCheckSingleBundleIsValidBadCndCdnBadFormatOk()
        {
            //SETUP
            var checker = new CheckBundles(TestFileHelpers.GetTestDataFileDirectory(), B4BSetupHelper.GetDirRelToTestDirectory("BadBowerBundlesFormat\\"));

            //ATTEMPT
            var errors = checker.CheckSingleBundleIsValid("CdnBadFormat");

            //VERIFY
            errors.Count.ShouldEqual(2);
            errors.First().ShouldEqual("The CDN bundle CdnBadFormat, array element 0, contained an invalid type Integer");
            errors.Last().ShouldEqual("The CDN bundle CdnBadFormat, array element 1, contained an invalid type Boolean");
        }
        public void TestCheckSingleBundleIsValidBadCndContaintsSearchTestOk()
        {
            //SETUP
            var checker = new CheckBundles(TestFileHelpers.GetTestDataFileDirectory(), B4BSetupHelper.GetDirRelToTestDirectory("BadBowerBundlesFormat\\"));

            //ATTEMPT
            var errors = checker.CheckSingleBundleIsValid("BadCndContaintsSearchTest");

            //VERIFY
            errors.Count.ShouldEqual(2);
            errors.First().ShouldEqual("The following files had 'development' with search strings in the bundles called 'BadCndContaintsSearchTest':\n - lib/jquery/dist/*jquery.js");
            errors.Last().ShouldEqual("The following files had 'production' with search strings in the bundles called 'BadCndContaintsSearchTest':\n - lib/jquery/dist/*jquery.js");
        }
Esempio n. 22
0
        public void FixtureSetup()
        {
            //This remembers the SqlErrorTextDict
            _rememberDefaultSqlErrorTextDict =
                GenericServicesConfig.SqlErrorDict.Select(x => new KeyValuePair <int, string>(x.Key, x.Value))
                .ToList();
            GenericServicesConfig.ClearSqlHandlerDict();

            using (var db = new SampleWebAppDb())
            {
                DataLayerInitialise.InitialiseThis();
                var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");
                DataLayerInitialise.ResetDatabaseToTestData(db, filepath);
            }
        }
Esempio n. 23
0
        public void TestGetChecksumOk()
        {
            //SETUP
            var mvc5ImagePath = Path.Combine(TestFileHelpers.GetSolutionDirectory(),
                                             "WebApplication.Mvc5\\images\\annoyed-cat.jpg");
            var fileSize = File.ReadAllBytes(mvc5ImagePath).Length;

            //ATTEMPT
            using (new TimerToConsole($"GetChecksumBasedOnFileContent - file size {fileSize:#,###} bytes"))
            {
                var output = BowerBundlerHelper.GetChecksumBasedOnFileContent(mvc5ImagePath);
            }

            //VERIFY
        }
Esempio n. 24
0
        public void TestBookLoadBuildReviewsOk()
        {
            //SETUP
            const string searchFile  = "JsonBooks01*.json";
            var          testDataDir = TestFileHelpers.GetTestDataFileDirectory();


            //ATTEMPT
            var books = BookJsonLoader.LoadBooks(testDataDir, searchFile);

            //VERIFY
            var expectedAveVotes = new[] { 5.0, 3.0, 4.0, 4.5 };

            books.Select(x => x.Reviews.Average(y => y.NumStars)).ShouldEqual(expectedAveVotes);
        }
Esempio n. 25
0
        public void CheckReadConfigOverrideCssCndToNullOk()
        {
            //SETUP

            //ATTEMPT
            var config = ConfigInfo.ReadConfig(TestFileHelpers.GetTestFileFilePath("bundlerForBower02*.json"));

            //VERIFY
            config.ToString().ShouldEqual(
                "BundlesFileName: newName.json, StaticFileCaching: {fileUrl}?v={cachebuster}, JsDirectory: js/, " +
                "JsDebugHtmlFormatString: <script src='{fileUrl}'></script>, JsNonDebugHtmlFormatString: <script src='{fileUrl}?v={cachebuster}'></script>, " +
                "JsCdnHtmlFormatString: <script src='{cdnUrl}'></script><script>({cdnSuccessTest}||document.write(\"\\x3Cscript src='{fileUrl}?v={cachebuster}'\\x3C/script>\"));</script>, " +
                "CssDirectory: css/, " +
                "CssDebugHtmlFormatString: <link href='{fileUrl}' rel='stylesheet'/>, CssNonDebugHtmlFormatString: <link href='{fileUrl}?v={cachebuster}' rel='stylesheet'/>, " +
                "CssCdnHtmlFormatString: "
                );
        }
Esempio n. 26
0
        public void CheckReadConfigAspNetCore1ConfigOk()
        {
            //SETUP

            //ATTEMPT
            var config = ConfigInfo.ReadConfig(TestFileHelpers.GetTestFileFilePath("ASPNET Core 1 Config/bundlerForBower.json"));

            //VERIFY
            config.ToString().ShouldEqual(
                "BundlesFileName: AspNetCore1BowerBundles.json, StaticFileCaching: , JsDirectory: wwwroot/js/, " +
                "JsDebugHtmlFormatString: <script src='{fileUrl}'></script>, JsNonDebugHtmlFormatString: <script src=\"{fileUrl}\" asp-append-version=\"true\"></script>, " +
                "JsCdnHtmlFormatString: <script src='{cdnUrl}' asp-fallback-src='{fileUrl}' asp-fallback-test='{cdnSuccessTest}'></script>, " +
                "CssDirectory: wwwroot/css/, " +
                "CssDebugHtmlFormatString: <link href='{fileUrl}' rel='stylesheet'/>, " +
                "CssNonDebugHtmlFormatString: <link href=\"{fileUrl}\" asp-append-version=\"true\" rel=\"stylesheet\"/>, " +
                "CssCdnHtmlFormatString: <link rel=\"stylesheet\" href='{cdnUrl}' asp-fallback-href='{fileUrl}' asp-fallback-test-class=\"{testClass}\" asp-fallback-test-property=\"{testProperty}\" asp-fallback-test-value=\"{testValue}\" />"
                );
        }
Esempio n. 27
0
        public void Check10DatabaseResetWithIGenericServicesDbContextOk()
        {
            using (var db = new SampleWebAppDb() as IGenericServicesDbContext)
            {
                //SETUP
                DataLayerInitialise.InitialiseThis();
                var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");

                //ATTEMPT
                DataLayerInitialise.ResetDatabaseToTestData(db as SampleWebAppDb, filepath);

                //VERIFY
                db.Set <Blog>().Count().ShouldEqual(2);
                db.Set <Post>().Count().ShouldEqual(3);
                db.Set <Tag>().Count().ShouldEqual(3);
                db.Set <PostTagGrade>().Count().ShouldEqual(2);
            }
        }
Esempio n. 28
0
        public void Check01DatabaseResetOk()
        {
            using (var db = new SampleWebAppDb())
            {
                //SETUP
                DataLayerInitialise.InitialiseThis();
                var filepath = TestFileHelpers.GetTestFileFilePath("DbContentSimple.xml");

                //ATTEMPT
                DataLayerInitialise.ResetDatabaseToTestData(db, filepath);

                //VERIFY
                db.Blogs.Count().ShouldEqual(2);
                db.Posts.Count().ShouldEqual(3);
                db.Tags.Count().ShouldEqual(3);
                db.Database.SqlQuery <int>("SELECT COUNT(*) FROM dbo.TagPosts").First().ShouldEqual(5);
                db.PostTagGrades.Count().ShouldEqual(2);
            }
        }
        public void TestGetBundleCdnInfoCdnOk()
        {
            //SETUP
            var reader = new ReadBundleFile(TestFileHelpers.GetTestFileFilePath("BowerBundles02*.json"));

            //ATTEMPT
            var cdns = reader.GetBundleCdnInfo("standardLibsJs").ToList();

            //VERIFY
            cdns.Count.ShouldEqual(2);
            var i = 0;

            cdns[i++].ToString().ShouldEqual("Development: jquery.js, Production: jquery.min.js, " +
                                             "cdnUrl: https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js, cdnSuccessTest: window.jQuery");
            cdns[i++].ToString().ShouldEqual("Development: bootstrap.js, Production: bootstrap.min.js, " +
                                             "cdnUrl: https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/bootstrap.min.js, cdnSuccessTest: window.jQuery && window.jQuery.fn && window.jQuery.fn.modal");
            //foreach (var cdnInfo in cdns)
            //{
            //    Console.WriteLine("cdns[i++].ToString().ShouldEqual(\"{0}\");", cdnInfo);
            //}
        }
Esempio n. 30
0
        public void FindBooksWithCSharpInTheirTitleContains()
        {
            //SETUP
            var sqlite = new SqliteInMemory();

            using (var context = sqlite.GetContextWithSetup())
            {
                context.SeedDatabase(TestFileHelpers.GetSolutionDirectory() + @"\EfCoreInAction\wwwroot\");
                sqlite.ClearLogs();

                //ATTEMPT
                var books = context.Books
                            .Where(p => p.Title.Contains("C#"))
                            .ToList();

                //VERIFY
                books.Count.ShouldEqual(5);
                foreach (var log in sqlite.Logs)
                {
                    _output.WriteLine(log);
                }
            }
        }