public void Enumerate_LoadsTextFilesCorrectly()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var fsMock2 = new InMemoryFileSystem(fsMock.Object);

            var defaultCulture = "en-US";
            CreateTemplateSet(fsMock2, @"c:\mock", "t1", null, defaultCulture, "txt");
            CreateTemplateSet(fsMock2, @"c:\mock", "t1", "de", defaultCulture, "txt");
            CreateTemplateSet(fsMock2, @"c:\mock", "t2", null, defaultCulture, "txt");
            CreateTemplateSet(fsMock2, @"c:\notinrightdir", "t3", null, defaultCulture, "txt");

            var configMock = new Mock<IConfiguration>();
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_FOLDER))
                .Returns(@"c:\mock");
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_DEFLANG))
                .Returns(defaultCulture);

            // ACT
            var queue = new FileFolderTemplateRepository(
                configuration: configMock.Object,
                fileSystem: fsMock2);

            var templates = new List<Template>();
            queue.EnumerateTemplates(templates.Add);

            // ASSERT
            Assert.AreEqual(3, templates.Count);

            AssertTemplateContents(templates, "t1", "en-US");
            AssertTemplateContents(templates, "t1", "de");
            AssertTemplateContents(templates, "t2", "en-US");
        }
예제 #2
0
        public void RemoveWorks()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var subject = new InMemoryFileSystem(fsMock.Object);

            var dir1 = @"c:\temp\one";

            var file1a = Path.Combine(dir1, @"file1");

            // ACT
            subject.Save(file1a, file1a);
            subject.Remove(file1a);

            // ASSERT
            var actual = subject.PeekOldest(dir1);
            Assert.IsNull(actual);
        }
        public void Enumerate_LoadsTextAndHtmlFilesCorrectlyWithincludes()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var fsMock2 = new InMemoryFileSystem(fsMock.Object);
            var basedir = @"c:\mock";
            var defaultCulture = "en-US";

            fsMock2.Save(Path.Combine(basedir, "t1", "body.txt"), "Hi @inc(body2.txt) bob");
            fsMock2.Save(Path.Combine(basedir, "t1", "body2.txt"), "alice");

            fsMock2.Save(Path.Combine(basedir, "t1", "body.html"), "Hi @inc(body2.html) john");
            fsMock2.Save(Path.Combine(basedir, "t1", "body2.html"), "mary");
           
            var configMock = new Mock<IConfiguration>();
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_FOLDER))
                .Returns(basedir);
            configMock.Setup(m => m.GetValue(FileFolderTemplateRepository.APP_KEY_DEFLANG))
                .Returns(defaultCulture);

            // ACT
            var queue = new FileFolderTemplateRepository(
                configuration: configMock.Object,
                fileSystem: fsMock2);

            var templates = new List<Template>();
            queue.EnumerateTemplates(templates.Add);

            // ASSERT
            Assert.AreEqual(1, templates.Count);

            var t = templates.FirstOrDefault(x => x.Key =="t1" && x.Language.Name.StartsWith("en"));

            Assert.AreEqual("Hi alice bob", t.Content.TextBody);
            Assert.AreEqual("Hi mary john", t.Content.Body);

        }
예제 #4
0
        public void MultipleFiles()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var subject = new InMemoryFileSystem(fsMock.Object);

            var dir1 = @"c:\temp\one";

            var file1a = Path.Combine(dir1, @"file1");
            var file1b = Path.Combine(dir1, @"file2");

            // ACT
            subject.Save(file1a, file1a);
            subject.Save(file1b, file1b);

            // ASSERT
            var actual1 = subject.PeekOldest(dir1);
            Assert.AreEqual(file1a, actual1);
            subject.Remove(file1a);

            var actual2 = subject.PeekOldest(dir1);
            Assert.AreEqual(file1b, actual2);
        }
예제 #5
0
        public void GetContentsReadFiles()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var subject = new InMemoryFileSystem(fsMock.Object);

            var dir1 = @"c:\temp\one";
            var dir2 = @"c:\temp\two";

            var file1a = Path.Combine(dir1, @"file1");
            var file1b = Path.Combine(dir1, @"file2");

            var file2a = Path.Combine(dir2, @"file1");
            var file2b = Path.Combine(dir2, @"file2");

            subject.Save(file1a, file1a);
            subject.Save(file2a, file2a);
            subject.Save(file1b, file1b);
            subject.Save(file2b, file2b);

          
            // ACT
            var contents = subject.GetContents(file1a.ToUpper());

            // ASSERT
            Assert.AreEqual(file1a, contents);
            
        }
예제 #6
0
        public void EnumerateGetAllFilesInDir()
        {
            // ARRANGE
            var fsMock = new Mock<IFileSystem>();
            fsMock.Setup(m => m.ExistDir(It.IsAny<string>())).Returns(true);

            var subject = new InMemoryFileSystem(fsMock.Object);

            var dir1 = @"c:\temp\one";
            var dir11 = @"c:\temp\one\a";
            var dir12 = @"c:\temp\one\b";

            var dir2 = @"c:\temp\two";

            var file1a = Path.Combine(dir1, @"file1");
            var file1b = Path.Combine(dir1, @"file2");

            var file11a = Path.Combine(dir11, @"file11");
            var file12a = Path.Combine(dir12, @"file12");
            
            var file2a = Path.Combine(dir2, @"file1");
            var file2b = Path.Combine(dir2, @"file2");

            subject.Save(file1a, file1a);
            subject.Save(file2a, file2a);
            subject.Save(file1b, file1b);
            subject.Save(file2b, file2b);
            subject.Save(file11a, file11a);
            subject.Save(file12a, file12a);

            var subdirs0 = new List<string>();
            var subdirs1 = new List<string>();
            var subdirs2 = new List<string>();
            
            // ACT
            subject.EnumerateDirectory(@"c:\temp", subdirs0.Add);
            subject.EnumerateDirectory(dir1, subdirs1.Add);
            subject.EnumerateDirectory(dir2, subdirs2.Add);

            // ASSERT
            Assert.AreEqual(2, subdirs0.Count);
            Assert.AreEqual("one", subdirs0.First());
            Assert.AreEqual("two", subdirs0.Last());

            Assert.AreEqual(2, subdirs1.Count);
            Assert.AreEqual("a", subdirs1.First());
            Assert.AreEqual("b", subdirs1.Last());

            Assert.AreEqual(0, subdirs2.Count);            
        }