public Task AddResultAsync(IPostBasket <Types.MatingEvent, string> basket, IVisit visit)
        {
            // get what we need out of the basket so that a response can be generated
            var male   = basket.DescentPayload.Male;
            var female = basket.DescentPayload.Female;
            var date   = basket.DescentPayload.Date;

            // we're going to patch the male and female, so there is a record of them mating
            var modifiedProps = new Dictionary <string, object> {
                { nameof(Types.Frog.DateLastMated), date }
            };

            var patchMaleBasket = new PatchBasket <int, Types.Frog, int>(
                new PatchRequest <int, Types.Frog>(new Delta <int, Types.Frog>(male.Id, modifiedProps)), basket);

            var patchFemaleBaset = new PatchBasket <int, Types.Frog, int>(
                new PatchRequest <int, Types.Frog>(new Delta <int, Types.Frog>(female.Id, modifiedProps)), basket);

            // generate some children for the male and female
            var tadpoleBaskets = GenerateTadpoles(basket, female, male, date);

            Task.WaitAll(_frogMine.SendAsync(patchMaleBasket), _frogMine.SendAsync(patchFemaleBaset));

            var tadpoleCount = tadpoleBaskets.Select(t => t.AscentPayload).Count();

            // the result of this operation is a string
            basket.AscentPayload = $"[{date:d}] {male.Name} and {female.Name} had {tadpoleCount} children";

            return(Task.CompletedTask);
        }
        public async Task Patch()
        {
            var mine   = new FrogMine("allowed");
            var basket = new PatchBasket <int, Frog, int>(new PatchRequest <int, Frog>(new Delta <int, Frog>(5,
                                                                                                             new Dictionary <string, object> {
                { nameof(Frog.Name), "abc" }
            })));
            await mine.SendAsync(basket);

            Assert.Equal(1, basket.AscentPayload);

            mine   = new FrogMine("Patch");
            basket = new PatchBasket <int, Frog, int>(new PatchRequest <int, Frog>(new Delta <int, Frog>(5,
                                                                                                         new Dictionary <string, object> {
                { nameof(Frog.Name), "abc" }
            })));
            await mine.SendAsync(basket);

            Assert.Equal(1, basket.AscentPayload);

            mine   = new FrogMine("not-allowed");
            basket = new PatchBasket <int, Frog, int>(new PatchRequest <int, Frog>(new Delta <int, Frog>(5,
                                                                                                         new Dictionary <string, object> {
                { nameof(Frog.Name), "abc" }
            })));
            await Assert.ThrowsAnyAsync <ShaftException>(() => mine.SendAsync(basket));
        }
        public void Construct()
        {
            var delta = new Delta <int, Frog>(752, new Dictionary <string, object>
            {
                { nameof(Frog.Name), "abc" },
                { nameof(Frog.DateOfBirth), DateTime.Today }
            });

            var basket = new PatchBasket <int, Frog, int>(new PatchRequest <int, Frog>(delta));

            Assert.Equal(typeof(Frog), basket.DataType);
            Assert.Same(delta, basket.DescentPayload.Delta);
        }
Exemple #4
0
        public async Task Patch()
        {
            var layer = new SalesforceLayer <MyContact>(_forceClient, new MyContactObjectDescriptor());

            var contact = new MyContact
            {
                Forename   = Guid.NewGuid().ToString(),
                Surname    = Guid.NewGuid().ToString(),
                Street     = Guid.NewGuid().ToString(),
                City       = "Glasgow",
                Country    = "United Kingdom",
                PostalCode = "G12AB",
                CanEmail   = true
            };

            var postBasket = new PostBasket <MyContact, string>(contact);
            await layer.AddResultAsync(postBasket, new Visit("Post", VisitDirections.Down)).ConfigureAwait(false);

            var id = postBasket.AscentPayload;

            Assert.False(string.IsNullOrWhiteSpace(id));

            var patchRequest = new PatchRequest <string, MyContact>(
                new Delta <string, MyContact>(id, new Dictionary <string, object>
            {
                { nameof(MyContact.Forename), "Jimmy" },
                { nameof(MyContact.Surname), "Riddle" }
            }));
            var patchBasket = new PatchBasket <string, MyContact, int>(patchRequest);
            await layer.AddResultAsync(patchBasket, new Visit("Patch", VisitDirections.Down)).ConfigureAwait(false);

            Assert.Equal(1, patchBasket.AscentPayload);

            var getBasket = new GetBasket <string, MyContact>(id);
            await layer.AddResultAsync(getBasket, new Visit("Get", VisitDirections.Down)).ConfigureAwait(false);

            var readContact = getBasket.AscentPayload;

            Assert.Equal(id, readContact.Id);
            Assert.Equal("Jimmy", readContact.Forename);
            Assert.Equal("Riddle", readContact.Surname);
            Assert.Equal(contact.Street, readContact.Street);
            Assert.Equal(contact.City, readContact.City);
            Assert.Equal(contact.Country, readContact.Country);
            Assert.Equal(contact.PostalCode, readContact.PostalCode);
            Assert.Equal(contact.CanMailshot, readContact.CanMailshot);
            Assert.Equal(contact.CanEmail, readContact.CanEmail);
            Assert.Equal(contact.CanPhone, readContact.CanPhone);
        }
        public async Task Patch()
        {
            var layer = GetLayer();

            InsertFrogs(layer, 10);

            var patchBasket = new PatchBasket <int, Frog, int>(
                new PatchRequest <int, Frog>(new Delta <int, Frog>(7,
                                                                   new Dictionary <string, object> {
                { nameof(Frog.Name), "Patched" }
            })));

            await layer.AddResultAsync(patchBasket, new Visit("something", VisitDirections.Down)).ConfigureAwait(false);

            Assert.Equal(1, patchBasket.AscentPayload);

            var getBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>());
            await layer.AddResultAsync(getBasket, new Visit("something", VisitDirections.Down)).ConfigureAwait(false);

            var seenPatched = false;

            Assert.Equal(10, getBasket.AscentPayload.Length);
            foreach (var frog in getBasket.AscentPayload)
            {
                if (frog.Id == 7)
                {
                    Assert.Equal("Patched", frog.Name);
                    seenPatched = true;
                }
                else
                {
                    Assert.Equal($"Frank{frog.Id}", frog.Name);
                }
            }

            Assert.True(seenPatched);
        }