public async Task CanUpdateProductDescription() { // Arrange var documentStoreProvider = DocumentStoreProvider; var existingProduct = new DbProduct { Name = "MyProduct", DescriptionMarkdown = "# Hello World!" }; using (var session = documentStoreProvider.Store.OpenAsyncSession()) { await session.StoreAsync(existingProduct, existingProduct.GetIdentifier()); } // Act var sut = new ProductManager(documentStoreProvider, logger); await sut.InsertOrUpdateProductDescriptionAsync("MyProduct", "# MyProduct"); // Assert using (var session = documentStoreProvider.Store.OpenAsyncSession()) { var product = await session.LoadAsync <DbProduct>(existingProduct.GetIdentifier()); product.ShouldNotBeNull(); product.DescriptionMarkdown.ShouldBe("# MyProduct"); } }
/// <summary> /// Inserts or updates the provided description for the product with the provided name. /// </summary> /// <param name="productName">The name of the product for which the description should be persisted.</param> /// <param name="descriptionMarkdown">The description that should be persisted.</param> public async Task InsertOrUpdateProductDescriptionAsync(string productName, string descriptionMarkdown) { var dbProduct = new DbProduct() { Name = productName, DescriptionMarkdown = descriptionMarkdown }; using (var session = _storeProvider.Store.OpenAsyncSession()) { // Using the store method when the product already exists in the database will override it completely, this is acceptable await session.StoreAsync(dbProduct, dbProduct.GetIdentifier()); await session.SaveChangesAsync(); } }