public async Task GenerateAndSaveIfChangedAsync_Pulls_Version_FromHeader()
        {
            //Arrange
            var options = new ClassGeneratorOptions
            {
                ClassName = "OurTest",
                Location  = _location
            };

            var generator = new StaticContentClassGenerator(options);

            var source = new MockContentSource();

            source.SetData("en-US", new Dictionary <string, string> {
                { "A", "ValA" }
            });
            await generator.GenerateAndSaveIfChangedAsync(new ContentVersion { Version = "1.0", ReleaseDate = new DateTime(2020, 1, 1) }, source);


            //Act
            var generator2 = new StaticContentClassGenerator(options);
            var version    = await generator2.GetExistingVersionAsync();

            //Assert
            Assert.Equal("1.0", version.Version);
            Assert.Equal(new DateTime(2020, 1, 1), version.ReleaseDate);
        }
        public async Task Carousel_GenerateAndSaves()
        {
            //Arrange
            var generator = new StaticContentClassGenerator(new ClassGeneratorOptions
            {
                ClassName = "OurTest",
                Location  = _location
            });

            var source = new MockContentSource();

            source.SetData("en-US",
                           new Dictionary <string, string> {
                { "A", "ValA" },
                { "C", @"<exigocarousel><exigocarouselattributes type=""bootstrap3"" /><exigobanner name=""Banner_One"" /><exigobanner name=""Banner_Two"" /></exigocarousel>" },
                { "Banner_One", "Banner_One_Value" },
                { "Banner_Two", "Banner_Two_Value" },
            });


            //Act
            await generator.GenerateAndSaveIfChangedAsync(new ContentVersion { Version = "1.0" }, source);

            //Assert
            var contents = File.ReadAllText(generator.GetFullFileName());

            _output.WriteLine(contents);

            Assert.Contains("string A =>", contents);
        }
Пример #3
0
        public async Task ClassGeneration_Updtes_Through_Stack()
        {
            //Arrange
            var source = new MockContentSource();

            var version1 = new ContentVersion {
                ReleaseDate = new DateTime(2020, 1, 1)
            };

            source.SetData(version1, "en-US", new Dictionary <string, string> {
                { "A", "ValA" }
            });

            var localizer = new LocalizerConfiguration()
                            .AddMemorySource()
                            .AddProtoFileSource(o => o.Location = _location)
                            .AddContentSource(() => source)
                            .AddUpdater(o =>
            {
                o.StartupDelay = TimeSpan.Zero;
                o.Frequency    = TimeSpan.FromMilliseconds(1);
            })
                            .AddClassGenerator(o =>
            {
                o.Location  = _location;
                o.ClassName = "OurClass";
            })
                            .BuildLocalizer();

            //Act/Assert
            // new version

            await Task.Delay(100);

            var version2 = new ContentVersion {
                ReleaseDate = new DateTime(2020, 1, 2)
            };

            source.SetData(version2, "en-US", new Dictionary <string, string> {
                { "A", "ValA-2" }
            });

            // give the updater a chance to do its magic
            await Task.Delay(100);

            var generator = new StaticContentClassGenerator(new ClassGeneratorOptions
            {
                ClassName = "OurClass",
                Location  = _location
            });

            ((IDisposable)localizer).Dispose();

            var version = await generator.GetExistingVersionAsync();

            Assert.Equal(version2.ReleaseDate, version.ReleaseDate);
        }
        public async Task GeneratedFile_OnlyUpdates_For_New_Version()
        {
            //Arrange
            var options = new ClassGeneratorOptions
            {
                ClassName = "OurTest",
                Location  = _location
            };

            var generator = new StaticContentClassGenerator(options);

            var source = new MockContentSource();

            source.SetData("en-US", new Dictionary <string, string> {
                { "A", "ValA" }
            });

            await Task.Delay(100);

            //Act
            await generator.GenerateAndSaveIfChangedAsync(new ContentVersion { Version = "1.0", ReleaseDate = new DateTime(2020, 1, 1) }, source);

            var date1 = File.GetLastWriteTime(generator.GetFullFileName());

            await Task.Delay(100);

            //same version
            await generator.GenerateAndSaveIfChangedAsync(new ContentVersion { Version = "1.0", ReleaseDate = new DateTime(2020, 1, 1) }, source);

            var date2 = File.GetLastWriteTime(generator.GetFullFileName());

            await Task.Delay(100);

            //new version
            await generator.GenerateAndSaveIfChangedAsync(new ContentVersion { Version = "2.0", ReleaseDate = new DateTime(2020, 1, 1) }, source);

            var date3 = File.GetLastWriteTime(generator.GetFullFileName());


            //Assert
            Assert.Equal(date1, date2);
            Assert.NotEqual(date1, date3);
        }
        public async Task GenerateAndSaveIfChangedAsync_Writes_File()
        {
            //Arrange
            var generator = new StaticContentClassGenerator(new ClassGeneratorOptions
            {
                ClassName = "OurTest",
                Location  = _location
            });

            var source = new MockContentSource();

            source.SetData("en-US", new Dictionary <string, string> {
                { "A", "ValA" }
            });


            //Act
            await generator.GenerateAndSaveIfChangedAsync(new ContentVersion { Version = "1.0" }, source);

            //Assert
            var contents = File.ReadAllText(generator.GetFullFileName());

            Assert.Contains("string A =>", contents);
        }