Beispiel #1
0
        private async Task _DownloadManifest(BarId barId, String manifestPath)
        {
            var fileName = barId.Guid.ToString("D", CultureInfo.InvariantCulture).ToUpperInvariant();

            var url = $"https://amarok.blob.core.windows.net/drinks/{fileName}.xml";

            using (var client = new WebClient())
            {
                await client.DownloadFileTaskAsync(url, manifestPath).ConfigureAwait(false);
            }
        }
Beispiel #2
0
        public async Task GetAll_Alexander()
        {
            var barId = new BarId(new Guid("A8A4E6C2-2B7D-41EE-8B3D-2053D74FAD67"));

            var repo = new AzureBlobDrinkRepository();

            var drink = (await repo.GetAll(barId)).SingleOrDefault(x => x.Name.Equals("Alexander"));

            Check.That(drink).IsNotNull();

            Check.That(drink.Id).IsNotEqualTo(Guid.Empty);
            Check.That(drink.BarId.Guid).IsEqualTo(new Guid("A8A4E6C2-2B7D-41EE-8B3D-2053D74FAD67"));
            Check.That(drink.Name).IsEqualTo("Alexander");
            Check.That(drink.Teaser).IsEqualTo("Gin, Crème de Cacao, Sahne, Muskatnuss");
            Check.That(drink.ImageId.Guid).IsEqualTo(new Guid("{8AFFEC5A-A659-460F-8BE4-438C1F17F638}"));
            Check.That(drink.Tags).ContainsExactly("sweet", "creamy");

            Check.That(drink.Description)
            .Contains(
                "Der Alexander ist ein alkoholischer Sahne-Cocktail",
                "Der Cocktail entstand Anfang des 20. Jahrhunderts, eine",
                "⁽¹⁾ ᵂᶦᵏᶦᵖᵉᵈᶦᵃ"
                );

            Check.That(drink.Glass).IsEqualTo("Martini");
            Check.That(drink.Ice).IsEqualTo("None");
            Check.That(drink.Garnish).IsEqualTo("Muskatnuss");

            Check.That(drink.Recipe.Ingredients).HasSize(4);

            Check.That(drink.Recipe.Ingredients[0].Amount.Value).IsEqualTo(3);
            Check.That(drink.Recipe.Ingredients[0].Unit).IsEqualTo("cl");
            Check.That(drink.Recipe.Ingredients[0].Substance).IsEqualTo("Beefeater 24 London Dry Gin");

            Check.That(drink.Recipe.Ingredients[1].Amount.Value).IsEqualTo(3);
            Check.That(drink.Recipe.Ingredients[1].Unit).IsEqualTo("cl");
            Check.That(drink.Recipe.Ingredients[1].Substance).IsEqualTo("Crème de Cacao Blanc");

            Check.That(drink.Recipe.Ingredients[2].Amount.Value).IsEqualTo(3);
            Check.That(drink.Recipe.Ingredients[2].Unit).IsEqualTo("cl");
            Check.That(drink.Recipe.Ingredients[2].Substance).IsEqualTo("Sahne");

            Check.That(drink.Recipe.Ingredients[3].Amount).IsNull();
            Check.That(drink.Recipe.Ingredients[3].Unit).IsNull();
            Check.That(drink.Recipe.Ingredients[3].Substance).IsEqualTo("Muskatnuss");

            Check.That(drink.Recipe.Instructions).HasSize(3);
            Check.That(drink.Recipe.Instructions[0]).IsEqualTo("SHAKE alle Zutaten");
            Check.That(drink.Recipe.Instructions[1]).IsEqualTo("FINE STRAIN ins Gästeglas");
            Check.That(drink.Recipe.Instructions[2]).IsEqualTo("DUST mit Muskatnuss");
        }
        public IEnumerable <AggregateCommit> Apply(AggregateCommit current)
        {
            if (ShouldApply(current))
            {
                var fooId        = new FooId("1234", "elders");
                var newFooEvents = new List <IEvent>();
                foreach (IEvent @event in current.Events)
                {
                    if (@event.GetType() == typeof(TestCreateEventFooBar))
                    {
                        newFooEvents.Add(new TestCreateEventFoo(fooId));
                    }
                    else if (@event.GetType() == typeof(TestUpdateEventFooBar))
                    {
                        var theEvent = @event as TestUpdateEventFooBar;
                        newFooEvents.Add(new TestUpdateEventFoo(fooId, theEvent.UpdatedFieldValue));
                    }
                }
                var aggregateCommitFoo = new AggregateCommit(fooId.RawId, current.Revision, newFooEvents);
                yield return(aggregateCommitFoo);

                var barId        = new BarId("5432", "elders");
                var newBarEvents = new List <IEvent>();
                foreach (IEvent @event in current.Events)
                {
                    if (@event.GetType() == typeof(TestCreateEventFooBar))
                    {
                        newBarEvents.Add(new TestCreateEventBar(barId));
                    }
                    else if (@event.GetType() == typeof(TestUpdateEventFooBar))
                    {
                        var theEvent = @event as TestUpdateEventFooBar;
                        newBarEvents.Add(new TestUpdateEventBar(barId, theEvent.UpdatedFieldValue));
                    }
                }
                var aggregateCommitBar = new AggregateCommit(barId.RawId, current.Revision, newFooEvents);

                yield return(aggregateCommitBar);
            }
            else
            {
                yield return(current);
            }
        }
Beispiel #4
0
        public async Task GetAll()
        {
            var barId = new BarId(new Guid("A8A4E6C2-2B7D-41EE-8B3D-2053D74FAD67"));

            var repo = new AzureBlobDrinkRepository();

            List <Drink> drinks = (await repo.GetAll(barId)).ToList();

            Check.That(drinks.Count).IsStrictlyGreaterThan(10);

            foreach (var drink in drinks)
            {
                Check.That(drink.Id).IsNotEqualTo(Guid.Empty);
                Check.That(drink.BarId.Guid).IsEqualTo(new Guid("A8A4E6C2-2B7D-41EE-8B3D-2053D74FAD67"));
                Check.That(drink.Name).Not.IsEmpty();
                Check.That(drink.Teaser).Not.IsEmpty();
                Check.That(drink.Description).IsNotNull();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets all Drinks for the given Bar.
        /// </summary>
        public async Task <IEnumerable <Drink> > GetAll(BarId barId)
        {
            String tempPath = null;

            try
            {
                tempPath = Path.GetTempFileName();

                await _DownloadManifest(barId, tempPath).ConfigureAwait(false);

                return(_LoadFromManifest(barId, tempPath));
            }
            finally
            {
                if (tempPath != null)
                {
                    File.Delete(tempPath);
                }
            }
        }
Beispiel #6
0
        private async Task _Loading()
        {
            try
            {
                ViewModel.IsDrinksLoading = true;

                var barId = new BarId(new Guid("A8A4E6C2-2B7D-41EE-8B3D-2053D74FAD67"));

                IEnumerable <Drink> drinks = await DrinkRepository.GetAll(barId).ConfigureAwait(true);

                var uiDrinks = new List <UiDrink>();

                foreach (var drink in drinks.OrderBy(x => x.Name))
                {
                    var imageUri = await ImageRepository.GetById(drink.ImageId).ConfigureAwait(true);

                    var image = new BitmapImage();
                    image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                    image.UriSource     = imageUri;

                    var item = new UiDrink {
                        Drink = drink, Image = image, IsImageLoading = true
                    };

                    uiDrinks.Add(item);

                    image.ImageFailed += (_sender, _e) => {
                        image.UriSource     = new Uri("ms-appx:///Assets/{00000000-0000-0000-0000-000000000000}.jpg");
                        item.IsImageLoading = false;
                    };

                    image.ImageOpened += (_sender, _e) => { item.IsImageLoading = false; };
                }

                ViewModel.DrinksView.Source = uiDrinks.ToList();
            }
            finally
            {
                ViewModel.IsDrinksLoading = false;
            }
        }
Beispiel #7
0
        public TestAggregateRootBar(BarId id)
        {
            var @event = new TestCreateEventBar(id);

            Apply(@event);
        }
Beispiel #8
0
        private List <Drink> _LoadFromManifest(BarId barId, String manifestPath)
        {
            var doc         = XDocument.Load(manifestPath);
            var catalogNode = doc.Element("catalog");

            var substances = new Dictionary <String, String>();

            foreach (var substanceNode in catalogNode.Element("substances").Elements("substance"))
            {
                var id   = substanceNode.Attribute("id").Value;
                var name = substanceNode.Value;

                substances.Add(id, name.Trim());
            }

            var drinks = new List <Drink>();

            foreach (var drinkNode in catalogNode.Element("drinks").Elements("drink"))
            {
                var name    = drinkNode.Element("name").Value;
                var teaser  = drinkNode.Element("teaser").Value;
                var image   = Guid.Parse(drinkNode.Element("image").Value);
                var desc    = drinkNode.Element("description").Value;
                var tags    = drinkNode.Element("tags").Value;
                var glass   = drinkNode.Element("glass")?.Value;
                var ice     = drinkNode.Element("ice")?.Value;
                var garnish = drinkNode.Element("garnish")?.Value;

                var drink = new Drink(new DrinkId(Guid.NewGuid()), barId).SetName(name.Trim())
                            .SetTeaser(teaser.Trim())
                            .SetImage(new ImageId(image))
                            .SetDescription(_TrimDescription(desc))
                            .SetTags(_SplitAndTrimTags(tags))
                            .SetGlass(glass?.Trim() ?? String.Empty)
                            .SetIce(ice?.Trim() ?? String.Empty)
                            .SetGarnish(garnish?.Trim() ?? String.Empty);

                Ingredient[] ingredients  = null;
                String[]     instructions = null;

                var recipeNode = drinkNode.Element("recipe");

                if (recipeNode != null)
                {
                    ingredients = recipeNode.Elements("ingredient")
                                  .Select(
                        x => {
                        var amount    = x.Attribute("amount")?.Value;
                        var unit      = x.Attribute("unit")?.Value;
                        var substance = x.Attribute("substance").Value;

                        if (substance.StartsWith("@", StringComparison.Ordinal))
                        {
                            var substanceId = substance.Substring(1);

                            if (substances.TryGetValue(substanceId, out var substanceName))
                            {
                                substance = substanceName;
                            }
                        }

                        if (amount == null && unit == null)
                        {
                            return(new Ingredient(substance));
                        }

                        return(new Ingredient(
                                   Double.Parse(amount, CultureInfo.InvariantCulture),
                                   unit,
                                   substance
                                   ));
                    }
                        )
                                  .ToArray();

                    instructions = recipeNode.Elements("instruction").Select(x => x.Value?.Trim()).ToArray();
                }

                drink.SetRecipe(
                    new Recipe(ingredients ?? Array.Empty <Ingredient>(), instructions ?? Array.Empty <String>())
                    );

                drinks.Add(drink);
            }

            return(drinks);
        }