예제 #1
0
        public void FullSimulation()
        {
            //var temp = Path.GetTempPath();

            //var fileNames = new[]
            //{
            //    Path.GetRandomFileName(),
            //    Path.GetRandomFileName(),
            //    Path.GetRandomFileName(),
            //};

            var fileProvider = new InMemoryFileProvider
            {
                { @"C:\temp" },
                { @"C:\temp\foo.txt", "foo" },
                { @"C:\temp\bar.txt", "bar" },
                { @"C:\temp\sub" },
                { @"C:\temp\sub\baz.txt", "baz" },
            };

            //Assert.AreEqual(5, fileProvider.GetFileInfo(@"C:\temp").Count());
            //Assert.AreEqual(2, fileProvider.GetFileInfo(@"C:\temp\sub").Count());

            var foo = fileProvider.GetFileInfo(@"C:\temp\foo.txt");

            Assert.IsTrue(foo.Exists);
            Assert.IsFalse(foo.IsDirectory);
            Assert.AreEqual("foo", foo.ReadAllTextAsync().GetAwaiter().GetResult());

            var sub = fileProvider.GetFileInfo(@"C:\temp\sub");

            Assert.IsTrue(sub.Exists);
            Assert.IsTrue(sub.IsDirectory);
            //Assert.AreEqual(2, sub.Count());
        }
        public void CheckIfControllerThisObjectAccessible()
        {
            var fakefs = new InMemoryFileProvider();

            fakefs.AddFile("controllers/test.os", "Процедура Б() А = ЭтотОбъект; КонецПроцедуры");
            fakefs.AddFile("main.os", "");
            var appEngine = new WebApplicationEngine();
            var app       = ApplicationInstance.Create(new FileInfoCodeSource(fakefs.GetFileInfo("main.os")), appEngine);
            var provider  = new OscriptApplicationModelProvider(app, appEngine, fakefs, Mock.Of <IAuthorizationPolicyProvider>());

            var context = new ApplicationModelProviderContext(new TypeInfo[0]);

            provider.OnProvidersExecuting(context);

            var cc = new ControllerContext();
            var ad = new ControllerActionDescriptor();

            ad.Properties["type"]            = context.Result.Controllers[0].Properties["type"];
            ad.Properties["CompilationInfo"] = context.Result.Controllers[0].Properties["CompilationInfo"];
            cc.ActionDescriptor    = ad;
            cc.HttpContext         = new DefaultHttpContext();
            cc.HttpContext.Session = null;

            var activator  = new ScriptedControllerActivator(appEngine);
            var controller = (ScriptedController)activator.Create(cc);

            Assert.Equal(controller, controller.GetPropValue(0));
        }
        public void CheckIfControllerCreatedFromScript()
        {
            var fakefs = new InMemoryFileProvider();

            fakefs.AddFile("controllers/test.os", "");
            fakefs.AddFile("main.os", "");
            var appEngine = new WebApplicationEngine();
            var app       = ApplicationInstance.Create(new FileInfoCodeSource(fakefs.GetFileInfo("main.os")), appEngine);
            var provider  = new OscriptApplicationModelProvider(app, appEngine, fakefs, Mock.Of <IAuthorizationPolicyProvider>());

            var context = new ApplicationModelProviderContext(new TypeInfo[0]);

            provider.OnProvidersExecuting(context);

            var cc = new ControllerContext();
            var ad = new ControllerActionDescriptor();

            ad.Properties["type"]   = context.Result.Controllers[0].Properties["type"];
            ad.Properties["module"] = context.Result.Controllers[0].Properties["module"];
            cc.ActionDescriptor     = ad;
            cc.HttpContext          = new DefaultHttpContext();
            cc.HttpContext.Session  = null;

            var activator  = new ScriptedControllerActivator(appEngine);
            var controller = (ScriptedController)activator.Create(cc);

            Assert.Equal("Контроллер.test", controller.SystemType.Name);
        }
 public void GetFileInfo_ReturnsNotFoundFileInfo_ForEmptyPath()
 {
     using (var provider = new InMemoryFileProvider())
     {
         var info = provider.GetFileInfo(string.Empty);
         Assert.IsType(typeof(NotFoundFileInfo), info);
     }
 }
 public void GetFileInfo_ReturnsNotFoundFileInfo_ForRelativePathAboveRootPath()
 {
     using (var provider = new InMemoryFileProvider())
     {
         var info = provider.GetFileInfo(Path.Combine("..", Guid.NewGuid().ToString()));
         Assert.IsType(typeof(NotFoundFileInfo), info);
     }
 }
 public void GetFileInfo_ReturnsNonExistentFileInfo_ForIllegalPath(string path)
 {
     using (var provider = new InMemoryFileProvider())
     {
         var info = provider.GetFileInfo(path);
         Assert.False(info.Exists);
     }
 }
        public void GetFileInfo_ReturnsNotFoundFileInfo_IfNoDirectoryItems()
        {
            // Arrange
            var provider = new InMemoryFileProvider();

            // Act
            var fileInfo = provider.GetFileInfo("DoesNotExist.txt");

            // Assert
            Assert.NotNull(fileInfo);
            Assert.False(fileInfo.Exists);
        }
        public void GetFileInfo_ReturnsNotFoundFileInfo_IfFileDoesNotExist()
        {
            // Arrange
            var provider = new InMemoryFileProvider();

            provider.Directory.AddFile("", new StringFileInfo("contents", "DoesExist.txt"));
            // Act
            var fileInfo = provider.GetFileInfo("DoesNotExist.txt");

            // Assert
            Assert.NotNull(fileInfo);
            Assert.False(fileInfo.Exists);
        }
        public void GetFileInfo_ReturnsNotFoundFileInfo_ForRelativePathWithEmptySegmentsThatNavigates()
        {
            var rootDir = new InMemoryDirectory("root");

            // add a file at root/a.txt
            rootDir.AddFile("", new StringFileInfo("some content", "b"));

            using (var provider = new InMemoryFileProvider(rootDir))
            {
                var info = provider.GetFileInfo("a///../../" + "root" + "/b");
                Assert.IsType(typeof(NotFoundFileInfo), info);
            }
        }
        public void GetFileInfo_ReturnsNotFoundFileInfo_ForRelativePathThatNavigatesAboveRoot()
        {
            var rootDir = new InMemoryDirectory("root");

            // add a file at root/a.txt
            rootDir.AddFile("", new StringFileInfo("some content", "a.txt"));

            using (var provider = new InMemoryFileProvider(rootDir))
            {
                // Act
                var info = provider.GetFileInfo("../root/a.txt");
                Assert.IsType(typeof(NotFoundFileInfo), info);
            }
        }
        public void CreateReadStream_Succeeds_OnEmptyFile()
        {
            var rootDir = new InMemoryDirectory("root");

            // add a file at root/a.txt
            rootDir.AddFile("", new StringFileInfo(null, "a.txt"));

            using (var provider = new InMemoryFileProvider(rootDir))
            {
                var info = provider.GetFileInfo("root/a.txt");
                using (var stream = info.CreateReadStream())
                {
                    Assert.NotNull(stream);
                }
            }
        }
        public void GetFileInfo_ReturnsFileInfo_ForEmbeddedFile()
        {
            using (var provider = new InMemoryFileProvider())
            {
                var embeddedFileInfo = new EmbeddedFileInfo(GetAssemblyFromType(this.GetType()),
                                                            $"Dazinator.AspNet.Extensions.FileProviders.Tests.Resources.myresource.txt",
                                                            "myfile.txt");

                provider.Directory.AddFile("/some/folder", embeddedFileInfo);

                var info = provider.GetFileInfo("/some/folder/myfile.txt");
                using (var stream = info.CreateReadStream())
                {
                    Assert.NotNull(stream);
                    Assert.True(stream.Length > 0);
                }
            }
        }