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);
        }
Пример #2
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);
        }