public async Task <DbFeature> InsertOrUpdateFeatureAsync(Feature feature, string productName, string groupName, string version) { _logger.LogInformation("Persisting feature {FeatureTitle} version {Version} for product {ProductName} and group {GroupName}", feature.Title, version, productName, groupName); var hash = feature.CalculateHash(); DbFeature dbFeature; using (var session = _storeProvider.Store.OpenAsyncSession()) { dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, feature.Title, hash)); if (dbFeature != null) { // Add the new version to the list var versions = new List <string>(dbFeature.Versions); versions.Add(version); // Prevent duplicates dbFeature.Versions = versions.Distinct().ToArray(); } else { // Create a new feature var processor = new FeatureProcessor(); string parentTitle = processor.DetermineParent(feature); dbFeature = new DbFeature(feature, productName, groupName, parentTitle, version); await session.StoreAsync(dbFeature, dbFeature.GetIdentifier()); } await session.SaveChangesAsync(); } return(dbFeature); }
public async Task CanPersistTestResults() { // Arrange var documentStoreProvider = DocumentStoreProvider; var expectedTestResults = new FeatureTestResult { FeatureTitle = "My Feature", Result = TestResult.Passed, TestExecutionDate = DateTime.Now }; using (var session = documentStoreProvider.Store.OpenAsyncSession()) { await session.StoreDbFeatureAsync("MyProduct", "MyGroup", "My Feature", "0.0.0"); await session.SaveChangesAsync(); } // Act var sut = new FeatureManager(documentStoreProvider, configurationManager, logger); await sut.PersistFeatureTestResultAsync(expectedTestResults, "MyProduct", "MyGroup", "0.0.0"); // Assert using (var session = documentStoreProvider.Store.OpenAsyncSession()) { var dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier("MyProduct", "MyGroup", "My Feature", "0.0.0")); dbFeature.ShouldNotBeNull(); dbFeature.TestResult.ShouldNotBeNull(); dbFeature.TestResult.Result.ShouldBe(TestResult.Passed); dbFeature.TestResult.TestExecutionDate.ShouldBe(expectedTestResults.TestExecutionDate); } }
public async Task DeleteFeatureAsync(string productName, string groupName, string title, string version) { using (var session = Database.DocumentStore.OpenAsyncSession()) { // The delete method only marks the entity with the provided id for deletion, as such it is not asynchronous session.Delete(DbFeatureExtensions.GetIdentifier(productName, groupName, title, version)); await session.SaveChangesAsync(); } }
public async Task PersistFeatureTestResultAsync(FeatureTestResult testResult, string productName, string groupName, string version) { using (var session = Database.DocumentStore.OpenAsyncSession()) { var dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, testResult.FeatureTitle, version)); if (dbFeature == null) { throw new Exception(String.Format(CultureInfo.InvariantCulture, "Feature {0} does not exist for product {1} under group {2}.", testResult.FeatureTitle, productName, groupName)); } dbFeature.TestResult = testResult; await session.SaveChangesAsync(); } }
/// <summary> /// Gets the feature that matches the provided criteria. /// </summary> /// <param name="productName">The name of the product under which the feature is positioned.</param> /// <param name="groupName">The name of the group under which the feature is positioned.</param> /// <param name="title">The title of the feature.</param> /// <param name="version">Version of the feature to retrieve.</param> /// <returns> /// A <see cref="DisplayableFeature"/> instance describing the requested feature; /// or <c>null</c> if the feature cannot be found. /// </returns> public async Task <DisplayableFeature> GetFeatureAsync(string productName, string groupName, string title, string version) { using (var session = Database.DocumentStore.OpenAsyncSession()) { var dbFeature = await session.LoadAsync <DbFeature>(DbFeatureExtensions.GetIdentifier(productName, groupName, title, version)); if (dbFeature == null) { return(null); } var result = new DisplayableFeature(dbFeature); result.TestResult = dbFeature.TestResult; result.Version = dbFeature.Version; // Process the server tags var processor = new FeatureProcessor(); processor.Process(result); return(result); } }