public void UpdateItemTest() { var customerKey = CreateCustomer(); VersionInfo customerVersion; using (var session = Domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { var customer = session.Query.Single <Customer>(customerKey); customerVersion = customer.VersionInfo; transactionScope.Complete(); } } Func <Key, VersionInfo> versionGetter = key => { if (key == customerKey) { return(customerVersion); } else { throw new ArgumentException(); } }; using (var session = Domain.OpenSession()) { using (VersionValidator.Attach(session, versionGetter)) { using (var transactionScope = session.OpenTransaction()) { var customer = session.Query.Single <Customer>(customerKey); customer.Name = "Customer3"; transactionScope.Complete(); } } } }
public async Task <IActionResult> FunctionBundlerImpl( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "FunctionBundler/{devEUI}")] HttpRequest req, ILogger log, string devEUI) { try { VersionValidator.Validate(req); } catch (IncompatibleVersionException ex) { return(new BadRequestObjectResult(ex.Message)); } EUIValidator.ValidateDevEUI(devEUI); var requestBody = await req.ReadAsStringAsync(); if (string.IsNullOrEmpty(requestBody)) { return(new BadRequestObjectResult("missing body")); } var functionBundlerRequest = JsonConvert.DeserializeObject <FunctionBundlerRequest>(requestBody); var result = await this.HandleFunctionBundlerInvoke(devEUI, functionBundlerRequest); return(new OkObjectResult(result)); }
public async Task <IActionResult> FunctionBundler( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "FunctionBundler/{devEUI}")] HttpRequest req, ILogger logger, string devEUI) { try { VersionValidator.Validate(req); } catch (IncompatibleVersionException ex) { return(new BadRequestObjectResult(ex.Message)); } if (!DevEui.TryParse(devEUI, EuiParseOptions.ForbidInvalid, out var parsedDevEui)) { return(new BadRequestObjectResult("Dev EUI is invalid.")); } var requestBody = await req.ReadAsStringAsync(); if (string.IsNullOrEmpty(requestBody)) { return(new BadRequestObjectResult("missing body")); } var functionBundlerRequest = JsonConvert.DeserializeObject <FunctionBundlerRequest>(requestBody); var result = await HandleFunctionBundlerInvoke(parsedDevEui, functionBundlerRequest, logger); return(new OkObjectResult(result)); }
public void TryParseShouldReturnCorrectVersion() { var version = VersionValidator.TryParse("1.1", TestObjectFactory.GetFailingValidationAction()); Assert.Equal(1, version.Major); Assert.Equal(1, version.Minor); }
public Parser(IFieldDataResultsAppender appender, ILog logger) { _appender = appender; _logger = logger; Config = LoadConfig(); VersionValidator = new VersionValidator(Config); }
public void TryParseShouldInvokeFailedActionIfStringIsNotInCorrectFormat() { var exception = Assert.Throws <NullReferenceException>(() => { VersionValidator.TryParse("test", TestObjectFactory.GetFailingValidationAction()); }); Assert.Equal("version valid version string invalid one", exception.Message); }
public static Version From(int current) { var version = new Version(current); var validator = new VersionValidator(); version.SetValidationResult(validator.Validate(version)); return(new Version(current)); }
public void VersionValidatorTest() { var domain = GetDomain(); using (var session = domain.OpenSession()) using (var scope = session.Activate()) { var versions = new VersionSet(); Person alex; Person dmitri; using (var tx = session.OpenTransaction()) { alex = new Person(session, "Yakunin, Alex"); dmitri = new Person(session, "Maximov, Dmitri"); tx.Complete(); } using (VersionCapturer.Attach(session, versions)) using (var tx = session.OpenTransaction()) { // Simulating entity displaying @ web page // By default this leads to their addition to VersionSet Dump(alex); Dump(dmitri); tx.Complete(); } // Let's clone VersionSet (actually - serialize & deserialize) versions = Cloner.Clone(versions); // And dump it Dump(versions); using (VersionValidator.Attach(session, versions)) using (var tx = session.OpenTransaction()) { alex.Name = "Edited Alex"; // Passes alex.Name = "Edited again"; // Passes, because this is not the very first modification tx.Complete(); } AssertEx.Throws <VersionConflictException>(() => { using (VersionValidator.Attach(session, versions)) using (var tx = session.OpenTransaction()) { alex.Name = "And again"; tx.Complete(); }// Version check fails on Session.Persist() here }); using (var tx = session.OpenTransaction()) versions.Add(alex, true); // Overwriting versions Dump(versions); using (VersionValidator.Attach(session, versions)) using (var tx = session.OpenTransaction()) { alex.Name = "Edited again"; // Passes now tx.Complete(); } } }
public async Task Error_if_no_version_key() { var manifest = JObject.Parse(@" { ""no_version_key"": 1 } "); var validator = new VersionValidator(manifest); var result = await validator.ValidateAsync(); Assert.AreEqual(1, result.ErrorMessages.Count); Assert.AreEqual(ValidationResult.MessageCode.VersionRequired, result.ErrorMessages.First()); }
public async Task Error_if_version_is_not_semver() { var manifest = JObject.Parse(@" { ""version"": ""string but not semver (should be something like 1.2.3)"" } "); var validator = new VersionValidator(manifest); var result = await validator.ValidateAsync(); Assert.AreEqual(1, result.ErrorMessages.Count); Assert.AreEqual(ValidationResult.MessageCode.VersionType, result.ErrorMessages.First()); }
public async Task Error_if_version_is_not_string() { var manifest = JObject.Parse(@" { ""version"": true } "); var validator = new VersionValidator(manifest); var result = await validator.ValidateAsync(); Assert.AreEqual(1, result.ErrorMessages.Count); Assert.AreEqual(ValidationResult.MessageCode.VersionType, result.ErrorMessages.First()); }
public async Task Warning_if_major_is_less_than_1() { var manifest = JObject.Parse(@" { ""version"": ""0.2.3"" } "); var validator = new VersionValidator(manifest); var result = await validator.ValidateAsync(); Assert.AreEqual(0, result.ErrorMessages.Count); Assert.AreEqual(1, result.WarningMessages.Count); Assert.AreEqual(ValidationResult.MessageCode.VersionMajorLessThanOne, result.WarningMessages.First()); }
public void GivenThreeMigrationsAndCurrentlyOnVersionTwo() { _outputWriter = new OutputWriterSpy(); var allMigrations = new List <MigrationData> { new MigrationData(1, "first", typeof(MigrationData).GetTypeInfo()), new MigrationData(2, "second (current)", typeof(MigrationData).GetTypeInfo()), new MigrationData(3, "third", typeof(MigrationData).GetTypeInfo()), }; _migrator = new Mock <ISimpleMigrator>(); _migrator.SetupGet(m => m.CurrentMigration).Returns(allMigrations[1]); _migrator.SetupGet(m => m.LatestMigration).Returns(allMigrations[2]); _migrator.SetupGet(m => m.Migrations).Returns(allMigrations); _versionValidator = new VersionValidator(_outputWriter); }
public virtual void OptimisticUpdate <T>(Key key, VersionInfo expectedVersion, Action <T> updater) where T : class, IEntity { var expectedVersions = new VersionSet( new List <KeyValuePair <Key, VersionInfo> > { new KeyValuePair <Key, VersionInfo>(key, expectedVersion), }); var session = Session.Demand(); using (VersionValidator.Attach(session, expectedVersions)) { using (var tx = session.OpenTransaction()) { var entity = session.Query.Single <T>(key); updater.Invoke(entity); session.Validate(); tx.Complete(); } } }
/// <summary> /// Validate version bump of changed modules or a specified module. /// </summary> private static void ValidateVersionBump() { var changedModules = new List <string>(); foreach (var directory in _projectDirectories) { var changeLogs = Directory.GetFiles(directory, "ChangeLog.md", SearchOption.AllDirectories) .Where(f => !ModuleFilter.IsAzureStackModule(f)) .Select(f => GetModuleManifestPath(Directory.GetParent(f).FullName)) .Where(m => !string.IsNullOrEmpty(m) && m.Contains(_moduleNameFilter)) .ToList(); changedModules.AddRange(changeLogs); } foreach (var projectModuleManifestPath in changedModules) { var moduleFileName = Path.GetFileName(projectModuleManifestPath); var moduleName = moduleFileName.Replace(".psd1", ""); var outputModuleManifest = _outputDirectories .SelectMany(d => Directory.GetDirectories(d, moduleName)) .SelectMany(d => Directory.GetFiles(d, moduleFileName)) .ToList(); if (outputModuleManifest.Count == 0) { throw new FileNotFoundException("No module manifest file found in output directories"); } else if (outputModuleManifest.Count > 1) { throw new IndexOutOfRangeException("Multiple module manifest files found in output directories"); } var outputModuleManifestFile = outputModuleManifest.FirstOrDefault(); var validatorFileHelper = new VersionFileHelper(_rootDirectory, outputModuleManifestFile, projectModuleManifestPath); _versionValidator = new VersionValidator(validatorFileHelper); _versionValidator.ValidateAllVersionBumps(); } }
public void RemoveChangedItemTest() { var customerKey = CreateCustomer(); VersionInfo customerVersion; using (var session = Domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { var customer = session.Query.Single <Customer>(customerKey); customerVersion = customer.VersionInfo; transactionScope.Complete(); } } RenameCustomer(customerKey); Func <Key, VersionInfo> versionGetter = key => { if (key == customerKey) { return(customerVersion); } else { throw new ArgumentException(); } }; using (var session = Domain.OpenSession()) { using (VersionValidator.Attach(session, versionGetter)) { AssertEx.Throws <VersionConflictException>(() => { using (var transactionScope = session.OpenTransaction()) { var customer = session.Query.Single <Customer>(customerKey); customer.Remove(); transactionScope.Complete(); } }); } } }
/// <summary> /// Tests whether HTTP response message version is the same as the provided version as string. /// </summary> /// <param name="version">Expected version as string.</param> /// <returns>The same HTTP response message test builder.</returns> public IAndHttpResponseMessageTestBuilder WithVersion(string version) { var parsedVersion = VersionValidator.TryParse(version, this.ThrowNewHttpResponseMessageAssertionException); return(this.WithVersion(parsedVersion)); }
public void ManualTest() { var config = DomainConfigurationFactory.Create(); config.Types.Register(typeof(Base)); config.Types.Register(typeof(Manual)); config.Types.Register(typeof(AnotherManual)); config.Types.Register(typeof(ManualInheritor)); config.Types.Register(typeof(AnotherManualInheritor)); var domain = Domain.Build(config); var manualTypeInfo = domain.Model.Types[typeof(Manual)]; var anotherManualTypeInfo = domain.Model.Types[typeof(AnotherManual)]; var manualInheritorTypeInfo = domain.Model.Types[typeof(ManualInheritor)]; var anotherManualInheritorTypeInfo = domain.Model.Types[typeof(AnotherManualInheritor)]; Assert.AreEqual(1, manualTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, anotherManualTypeInfo.GetVersionColumns().Count); Assert.AreEqual(1, manualInheritorTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, anotherManualInheritorTypeInfo.GetVersionColumns().Count); using (var session = domain.OpenSession()) { var versions = new VersionSet(); var updatedVersions = new VersionSet(); Manual manual; ManualInheritor manualInheritor; AnotherManual anotherManual; AnotherManualInheritor anotherManualInheritor; using (VersionCapturer.Attach(session, versions)) using (var t = session.OpenTransaction()) { manual = new Manual() { Tag = "Tag", Content = "Content", Version = 1 }; manualInheritor = new ManualInheritor() { Tag = "Tag", Content = "Content", Version = 1, Name = "Name" }; anotherManual = new AnotherManual() { Tag = "Tag", Content = "Content", Version = 1, SubVersion = 100 }; anotherManualInheritor = new AnotherManualInheritor() { Tag = "Tag", Content = "Content", Version = 1, SubVersion = 100, Name = "Name" }; t.Complete(); } using (VersionCapturer.Attach(session, updatedVersions)) using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { manual.Version = 2; manual.Tag = "AnotherTag"; manual.Tag = "AnotherTagCorrect"; manualInheritor.Name = "AnotherName"; manualInheritor.Version = 2; anotherManual.Tag = "AnotherTag"; anotherManual.SubVersion = 200; anotherManualInheritor.Name = "AnotherName"; anotherManualInheritor.SubVersion = 200; t.Complete(); } AssertEx.Throws <VersionConflictException>(() => { using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { manual.Tag = "YetAnotherTag"; anotherManual.Tag = "YetAnotherTag"; anotherManual.Version = 2; manualInheritor.Name = "YetAnotherName"; anotherManualInheritor.Name = "YetAnotherName"; t.Complete(); } }); using (VersionValidator.Attach(session, updatedVersions)) using (var t = session.OpenTransaction()) { manual.Tag = "YetAnotherTag"; anotherManual.Tag = "YetAnotherTag"; anotherManual.Version = 2; manualInheritor.Name = "YetAnotherName"; anotherManualInheritor.Name = "YetAnotherName"; t.Complete(); } } }
public void DefaultTest() { var config = DomainConfigurationFactory.Create(); config.Types.Register(typeof(Base)); config.Types.Register(typeof(Default)); config.Types.Register(typeof(DefaultInheritor)); var domain = Domain.Build(config); var defaultTypeInfo = domain.Model.Types[typeof(Default)]; var defaultInheritorTypeInfo = domain.Model.Types[typeof(DefaultInheritor)]; Assert.AreEqual(3, defaultTypeInfo.GetVersionColumns().Count); Assert.AreEqual(4, defaultInheritorTypeInfo.GetVersionColumns().Count); using (var session = domain.OpenSession()) { var versions = new VersionSet(); var updatedVersions = new VersionSet(); Default @default; using (VersionCapturer.Attach(session, versions)) using (var t = session.OpenTransaction()) { @default = new Default() { Name = "Name", Tag = "Tag", Version = 1 }; t.Complete(); } using (VersionCapturer.Attach(session, updatedVersions)) using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { @default.Version = 2; @default.Name = "AnotherName"; @default.Name = "AnotherNameCorrect"; t.Complete(); } AssertEx.Throws <VersionConflictException>(() => { using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { @default.Tag = "AnotherTag"; t.Complete(); } }); using (VersionValidator.Attach(session, updatedVersions)) using (var t = session.OpenTransaction()) { @default.Tag = "AnotherTag"; t.Complete(); } } var allVersions = new VersionSet(); using (var session = domain.OpenSession()) using (VersionCapturer.Attach(session, allVersions)) using (VersionValidator.Attach(session, allVersions)) { Default @default; using (var t = session.OpenTransaction()) { @default = new Default() { Name = "Name", Tag = "Tag", Version = 1 }; t.Complete(); } using (var t = session.OpenTransaction()) { @default.Version = 2; @default.Name = "AnotherName"; @default.Name = "AnotherNameCorrect"; t.Complete(); } using (var t = session.OpenTransaction()) { @default.Tag = "AnotherTag"; t.Complete(); } } }
public void AutoTest() { var config = DomainConfigurationFactory.Create(); config.Types.Register(typeof(Base)); config.Types.Register(typeof(Auto)); config.Types.Register(typeof(AutoInheritor)); var domain = Domain.Build(config); var autoTypeInfo = domain.Model.Types[typeof(Auto)]; var autoInheritorTypeInfo = domain.Model.Types[typeof(AutoInheritor)]; Assert.AreEqual(1, autoTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, autoInheritorTypeInfo.GetVersionColumns().Count); using (var session = domain.OpenSession()) { var versions = new VersionSet(); var updatedVersions = new VersionSet(); Auto auto; AutoInheritor autoInheritor; using (VersionCapturer.Attach(session, versions)) using (var t = session.OpenTransaction()) { auto = new Auto() { Content = "Content", Tag = "Tag" }; autoInheritor = new AutoInheritor() { Content = "Content", Tag = "Tag" }; t.Complete(); } using (VersionCapturer.Attach(session, updatedVersions)) using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { auto.Content = "AnotherContent"; auto.Content = "AnotherContetnCorrect"; autoInheritor.Content = "AnotherContent"; autoInheritor.Content = "AnotherContetnCorrect"; t.Complete(); } AssertEx.Throws <VersionConflictException>(() => { using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { auto.Tag = "AnotherTag"; autoInheritor.Tag = "AnotherTag"; t.Complete(); } }); using (VersionValidator.Attach(session, updatedVersions)) using (var t = session.OpenTransaction()) { auto.Tag = "AnotherTag"; autoInheritor.Tag = "AnotherTag"; t.Complete(); } } var allVersions = new VersionSet(); using (var session = domain.OpenSession()) using (VersionCapturer.Attach(session, allVersions)) using (VersionValidator.Attach(session, allVersions)) { Auto auto; AutoInheritor autoInheritor; using (var t = session.OpenTransaction()) { auto = new Auto() { Content = "Content", Tag = "Tag" }; autoInheritor = new AutoInheritor() { Content = "Content", Tag = "Tag" }; t.Complete(); } using (var t = session.OpenTransaction()) { auto.Content = "AnotherContent"; auto.Content = "AnotherContetnCorrect"; autoInheritor.Content = "AnotherContent"; autoInheritor.Content = "AnotherContetnCorrect"; t.Complete(); } using (var t = session.OpenTransaction()) { auto.Tag = "AnotherTag"; autoInheritor.Tag = "AnotherTag"; t.Complete(); } } }
public void SkipTest() { var config = DomainConfigurationFactory.Create(); config.Types.Register(typeof(Base)); config.Types.Register(typeof(Skip)); config.Types.Register(typeof(VersionBehavior.Model.Version)); config.Types.Register(typeof(HasVersion)); config.Types.Register(typeof(HasSkipVersion)); var domain = Domain.Build(config); var skipTypeInfo = domain.Model.Types[typeof(Skip)]; var hasVersionTypeInfo = domain.Model.Types[typeof(HasVersion)]; var hasSkipVersionTypeInfo = domain.Model.Types[typeof(HasSkipVersion)]; Assert.AreEqual(2, skipTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, hasVersionTypeInfo.GetVersionColumns().Count); Assert.AreEqual(2, hasSkipVersionTypeInfo.GetVersionColumns().Count); using (var session = domain.OpenSession()) { var versions = new VersionSet(); var updatedVersions = new VersionSet(); Skip skip; HasVersion hasVersion; using (VersionCapturer.Attach(session, versions)) using (var t = session.OpenTransaction()) { skip = new Skip() { Content = "Content", Tag = "Tag", Description = "Desription", NotVersion = "NotVersion" }; hasVersion = new HasVersion { Content = "Content", Tag = "Tag", Version = { Major = 10, Minor = 100, Meta = 1000 } }; t.Complete(); } using (VersionCapturer.Attach(session, updatedVersions)) using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { skip.Content = "AnotherContent"; skip.Content = "AnotherContetnCorrect"; hasVersion.Content = "AnotherContent"; hasVersion.Content = "AnotherContetnCorrect"; t.Complete(); } AssertEx.Throws <VersionConflictException>(() => { using (VersionValidator.Attach(session, versions)) using (var t = session.OpenTransaction()) { skip.Tag = "AnotherTag"; hasVersion.Tag = "AnotherTag"; t.Complete(); } }); using (VersionValidator.Attach(session, updatedVersions)) using (var t = session.OpenTransaction()) { skip.Tag = "AnotherTag"; hasVersion.Tag = "AnotherTag"; t.Complete(); } } var allVersions = new VersionSet(); using (var session = domain.OpenSession()) using (VersionCapturer.Attach(session, allVersions)) using (VersionValidator.Attach(session, allVersions)) { Skip skip; HasVersion hasVersion; using (var t = session.OpenTransaction()) { skip = new Skip() { Content = "Content", Tag = "Tag", Description = "Desription", NotVersion = "NotVersion" }; hasVersion = new HasVersion { Content = "Content", Tag = "Tag", Version = { Major = 10, Minor = 100, Meta = 1000 } }; t.Complete(); } using (var t = session.OpenTransaction()) { skip.Content = "AnotherContent"; skip.Content = "AnotherContetnCorrect"; hasVersion.Content = "AnotherContent"; hasVersion.Content = "AnotherContetnCorrect"; t.Complete(); } using (var t = session.OpenTransaction()) { skip.Tag = "AnotherTag"; hasVersion.Tag = "AnotherTag"; t.Complete(); } } }
public void TryParseShouldInvokeFailedActionIfStringIsNotInCorrectFormat() { VersionValidator.TryParse("test", TestObjectFactory.GetFailingValidationAction()); }
/// <summary> /// Adds HTTP version to the built HTTP request message. /// </summary> /// <param name="version">HTTP version provided by string.</param> /// <returns>The same HTTP request message builder.</returns> public IAndHttpRequestMessageBuilder WithVersion(string version) { var parsedVersion = VersionValidator.TryParse(version, this.ThrowNewInvalidHttpRequestMessageException); return(this.WithVersion(parsedVersion)); }
public when_validating_a_version() { _validator = new VersionValidator(); }