private async Task Multiply() { await MatureTadpolesAsync().ConfigureAwait(false); var request = new GetSingleRequest <PairSelection>(new Filter <PairSelection>(new[] { new FilterTerm(nameof(PairSelection.Date), FilterOperators.Equal, _day) })); var getPairBasket = await _pairSelectionMine.SendAsync(new GetSingleBasket <PairSelection>(request)) .ConfigureAwait(false); var pair = getPairBasket.AscentPayload; if (pair.IsValid) { var mateBasket = new PostBasket <MatingEvent, string>(new MatingEvent(pair.Male, pair.Female, pair.Date)); // this call returns a basket, but it's just the same basket that was passed in. Since we already have a reference // to it we don't need to assign the result to a new variable await _matingEventMine.SendAsync(mateBasket).ConfigureAwait(false); System.Console.WriteLine(mateBasket.AscentPayload); } }
public void Construct() { var frog = new Frog { Name = "Fred", DateOfBirth = DateTime.Today }; var basket = new PostBasket <Frog, int>(frog); Assert.Equal(typeof(Frog), basket.DataType); Assert.Same(frog, basket.DescentPayload); }
private async Task MatureTadpolesAsync() { var maturationBasket = new PostBasket <MaturationEvent, int>(new MaturationEvent(_day)); await _maturationEventMine.SendAsync(maturationBasket).ConfigureAwait(false); var maturedCount = maturationBasket.AscentPayload; if (maturedCount > 0) { System.Console.WriteLine($"[{_day:d}] {maturedCount} tadpoles have matured"); } }
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); }
private void InsertFrogs(FrogLayer layer, int count) { var tasks = new Task[count]; for (var i = 1; i <= count; i++) { var frog = new Frog { Id = i, Name = $"Frank{i}", DateOfBirth = DateTime.Today.AddDays(-i) }; var basket = new PostBasket <Frog, int>(frog); tasks[i - 1] = layer.AddResultAsync(basket, new Visit("something", VisitDirections.Down)); } Task.WaitAll(tasks); }
public async Task Post() { var mine = new FrogMine("allowed"); var basket = new PostBasket <Frog, int>(new Frog()); await mine.SendAsync(basket); Assert.True(basket.AscentPayload > 0); mine = new FrogMine("Post"); basket = new PostBasket <Frog, int>(new Frog()); await mine.SendAsync(basket); Assert.True(basket.AscentPayload > 0); mine = new FrogMine("not-allowed"); basket = new PostBasket <Frog, int>(new Frog()); await Assert.ThrowsAnyAsync <ShaftException>(() => mine.SendAsync(basket)); }
public async Task Delete() { 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 deleteBasket = new DeleteBasket <string, MyContact, int>(id); await layer.AddResultAsync(deleteBasket, new Visit("Delete", VisitDirections.Down)).ConfigureAwait(false); Assert.Equal(1, deleteBasket.AscentPayload); Exception exception = null; try { var getBasket = new GetBasket <string, MyContact>(id); await layer.AddResultAsync(getBasket, new Visit("Get", VisitDirections.Down)).ConfigureAwait(false); } catch (InvalidOperationException ex) { exception = ex; } Assert.NotNull(exception); Assert.Contains("Done: True, Count: 0", exception.Message); }
public async Task AddResultAsync(IPostBasket <Types.MaturationEvent, int> basket, IVisit visit) { var date = basket.DescentPayload.Date; var filter = new Filter <Types.Tadpole>(new[] { new FilterTerm(nameof(Types.Tadpole.DateOfBirth), FilterOperators.LessThanOrEqual, date.AddMonths(-2)) }); // get all tadpoles who are of a certain age - see filter above var getTadpolesBasket = new GetCollectionBasket <Types.Tadpole>(new GetCollectionRequest <Types.Tadpole>(filter)); await _tadpoleMine.SendAsync(getTadpolesBasket).ConfigureAwait(false); var tadpoles = getTadpolesBasket.AscentPayload; if (tadpoles.Length > 0) { // covert the retrieved tadpoles into frogs... foreach (var tadpole in tadpoles) { var frog = tadpole.ToFrog(); using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { // ... create frog var postFrogBasket = new PostBasket <Types.Frog, int>(frog); var postFrogTask = _frogMine.SendAsync(postFrogBasket); // ...and get rid of the tapole which has now become a frog var deleteTadpoleBasket = new DeleteBasket <int, Types.Tadpole, int>(tadpole.Id); var deleteTadpoleTask = _tadpoleMine.SendAsync(deleteTadpoleBasket); Task.WaitAll(postFrogTask, deleteTadpoleTask); scope.Complete(); } } } basket.AscentPayload = tadpoles.Length; }
private IPostBasket <Types.Tadpole, int>[] GenerateTadpoles(IBasket parent, Types.Frog mother, Types.Frog father, DateTime date) { var tadpoleCount = 10; var tasks = new Task[tadpoleCount]; var baskets = new IPostBasket <Types.Tadpole, int> [tadpoleCount]; // generate 10 tadpoles for the mother and father var surname = $"{father.Id}-{mother.Id}"; var eventNo = 1; // this is just something to ensure the child has a unique name - it's not important to understand if (FamilyEventsEvents.ContainsKey(surname)) { eventNo = FamilyEventsEvents[surname] + 1; } for (var i = 0; i < tadpoleCount; i++) { var tadpole = new Types.Tadpole { DateOfBirth = date.AddDays(i), MotherId = mother.Id, FatherId = father.Id, LivesInPondId = mother.LivesInPondId, IsMale = i % 2 == 0, Name = (i % 2 == 0 ? "M" : "F") + $"{i}:{eventNo}:{surname}" }; var postBasket = new PostBasket <Types.Tadpole, int>(tadpole, parent); tasks[i] = _tadpoleMine.SendAsync(postBasket); baskets[i] = postBasket; } FamilyEventsEvents[surname] = eventNo; Task.WaitAll(tasks); return(baskets); }