public IReadOnlyList <IProductRecipe> GetRecipes(IProductType productType, RecipeClassification classification) { ValidateHealthState(); var recipes = RecipeManagement.GetRecipes(productType, classification); return(recipes.Select(ReplaceOrigin).ToArray()); }
/// <inheritdoc /> public IReadOnlyList <IProductRecipe> LoadRecipes(long productId, RecipeClassification classifications) { using (var uow = Factory.Create()) { var repo = uow.GetRepository <IProductTypeEntityRepository>(); var productEntity = repo.GetByKey(productId); if (productEntity == null) { return(null); } var classificationMask = (int)classifications; var recipeEntities = (from recipeEntity in uow.GetRepository <IProductRecipeEntityRepository>().Linq.Active() let classificationValue = recipeEntity.Classification where recipeEntity.ProductId == productId where classificationValue >= 0 // We never return clones in this query where (classificationValue & classificationMask) == classificationMask select recipeEntity).ToArray(); return(recipeEntities.Select(entity => LoadRecipe(uow, entity)).ToArray()); } }
public IReadOnlyList <IProductRecipe> GetRecipes(IProductType productType, RecipeClassification classification) { return(Storage.LoadRecipes(productType.Id, classification)); }
public void ForwardBackwardRecipeConversionWithoutInformationLoss(DummyProductRecipe originalRecipe, RecipeClassification classification, RecipeState state, DummyProductType backupProductType, DummyWorkplan workplanInTargetRecipe, int testCaseCounter) { // Arrange // - Basic Workplan properties originalRecipe.Id = 42; originalRecipe.Name = "TestName"; originalRecipe.Revision = 1337; originalRecipe.Classification = classification; originalRecipe.State = state; // - Mock workplan requests if there could be a Workplan var originalWorkplanRecipe = originalRecipe as DummyProductWorkplanRecipe; if (originalWorkplanRecipe is not null) { _workplanManagementMock.Setup(wm => wm.LoadWorkplan(It.IsAny <long>())) .Returns((long id) => new DummyWorkplan() { Id = id }); } // - Create target object var targetDummyRecipe = (DummyProductRecipe)Activator.CreateInstance(originalRecipe.GetType()); targetDummyRecipe.Id = 42; if (originalWorkplanRecipe is not null) { ((DummyProductWorkplanRecipe)targetDummyRecipe).Workplan = workplanInTargetRecipe; } // - No change of classification on clones should be possible, thereby preset it if (originalRecipe.Classification.HasFlag(RecipeClassification.Clone)) { targetDummyRecipe.Classification = originalRecipe.Classification; } // Act var convertedModel = _productConverter.ConvertRecipe(originalRecipe); var recoveredOriginal = _productConverter.ConvertRecipeBack(convertedModel, targetDummyRecipe, backupProductType); // Assert // - Backup products are used for recipes without products if (originalRecipe.Product is null) { originalRecipe.Product = backupProductType; } Assert.AreEqual(originalRecipe, recoveredOriginal); // - If there is a workplan and it changed, reload it at backward conversion if (originalWorkplanRecipe?.Workplan is not null && originalWorkplanRecipe.Workplan.Id != workplanInTargetRecipe.Id) { _workplanManagementMock.Verify(wm => wm.LoadWorkplan(originalWorkplanRecipe.Workplan.Id), Times.Once); }