public async Task Get() { var mine = new FrogMine(); // uncached var basket = new GetBasket <int, Frog>(3); await mine.SendAsync(basket).ConfigureAwait(false); Assert.True(basket.Note is OkNote); Assert.Equal(3, basket.AscentPayload.Id); Assert.Equal("Kermit", basket.AscentPayload.Name); Assert.Equal(3, basket.Visits.Count); // cached basket = new GetBasket <int, Frog>(3); await mine.SendAsync(basket).ConfigureAwait(false); Assert.True(basket.Note is ReturnNote); Assert.Equal(3, basket.AscentPayload.Id); Assert.Equal("Kermit", basket.AscentPayload.Name); Assert.Equal(1, basket.Visits.Count); // uncached basket = new GetBasket <int, Frog>(4); await mine.SendAsync(basket).ConfigureAwait(false); Assert.True(basket.Note is OkNote); Assert.Equal(4, basket.AscentPayload.Id); Assert.Equal("Kermit", basket.AscentPayload.Name); Assert.Equal(3, basket.Visits.Count); }
public void Construct() { var basket = new GetBasket <int, Frog>(85); Assert.Equal(typeof(Frog), basket.DataType); Assert.Equal(85, basket.DescentPayload); }
public async Task Pipeline() { var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal()) .Add(new TestGetStation1()) .Add(new TestGetStation2()); var basket = new GetBasket <int, Frog>(22); await shaft.SendAsync(basket).ConfigureAwait(false); Assert.Equal(22, basket.AscentPayload.Id); Assert.Equal("Frank21", basket.AscentPayload.Name); Assert.Equal(DateTime.Today, basket.AscentPayload.DateOfBirth); Assert.Equal(22, basket.DescentPayload); shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal()) .Add(new TestGetStation2()) .Add(new TestGetStation1()); basket = new GetBasket <int, Frog>(33); await shaft.SendAsync(basket).ConfigureAwait(false); Assert.Equal(33, basket.AscentPayload.Id); Assert.Equal("Frank12", basket.AscentPayload.Name); Assert.Equal(DateTime.Today, basket.AscentPayload.DateOfBirth); Assert.Equal(33, basket.DescentPayload); }
public async Task <IActionResult> GetItems(string username) { var query = new GetBasket(username); var result = await mediator.Send(query); return(View(result)); }
public GetBasketHandlerTests() { _message = new GetBasket(new SessionId("ABC123")); _basketRepository = new Mock <IBasketRepository>(); _sut = new GetBasketHandler(_basketRepository.Object); }
public Basket GetBasket(Guid basketId) { var request = new GetBasket(basketId); var response = request.Get(); if (string.IsNullOrWhiteSpace(response)) { return(null); } return(JsonConvert.DeserializeObject <Basket>(response)); }
public async Task Post() { var mine = new FrogMine(); // uncached item var getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is OkNote); Assert.Equal(3, getBasket.Visits.Count); Assert.Equal(33, getBasket.AscentPayload.Id); // cached item getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is ReturnNote); Assert.Equal(1, getBasket.Visits.Count); Assert.Equal(33, getBasket.AscentPayload.Id); // uncached collection var getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.Visits.Count); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); // cached collection getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is ReturnNote); Assert.Equal(1, getCollectionBasket.Visits.Count); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); await mine.SendAsync(new PostBasket <Frog, int>(new Frog { Id = 852 })).ConfigureAwait(false); // get cache should still exist getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is ReturnNote); Assert.Equal(33, getBasket.AscentPayload.Id); // but get collection shouldn't getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); }
public async Task Get() { var layer = GetLayer(); InsertFrogs(layer, 10); var getBasket = new GetBasket <int, Frog>(5); await layer.AddResultAsync(getBasket, new Visit("something", VisitDirections.Down)).ConfigureAwait(false); Assert.Equal(5, getBasket.AscentPayload.Id); Assert.Equal($"Frank{5}", getBasket.AscentPayload.Name); Assert.Equal(DateTime.Today.AddDays(-5), getBasket.AscentPayload.DateOfBirth); }
public async Task Simple() { var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal(), null); var basket = new GetBasket <int, Frog>(18); await shaft.SendAsync(basket).ConfigureAwait(false); Assert.Equal(typeof(OkNote), basket.Note.GetType()); Assert.Equal(18, basket.AscentPayload.Id); Assert.Equal("Frank", basket.AscentPayload.Name); Assert.Equal(DateTime.Today, basket.AscentPayload.DateOfBirth); Assert.Equal(18, basket.DescentPayload); }
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 ReturnEarly() { var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal()) .Add(new TestGetStation1()) .Add(new TestGetStation2()) .Add(new TestGetStationReturnEarly()); var basket = new GetBasket <int, Frog>(22); await shaft.SendAsync(basket).ConfigureAwait(false); Assert.True(basket.Note is ReturnNote); Assert.Equal(22, basket.AscentPayload.Id); Assert.Equal("Early Frog", basket.AscentPayload.Name); Assert.Equal(DateTime.Today.AddDays(-1), basket.AscentPayload.DateOfBirth); }
public async Task Get() { var mine = new FrogMine("allowed"); var basket = new GetBasket <int, Frog>(8); await mine.SendAsync(basket); Assert.Equal(8, basket.AscentPayload.Id); mine = new FrogMine("Get"); basket = new GetBasket <int, Frog>(8); await mine.SendAsync(basket); Assert.Equal(8, basket.AscentPayload.Id); mine = new FrogMine("not-allowed"); basket = new GetBasket <int, Frog>(8); 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 ExceptionUp() { var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal()) .Add(new TestGetStation1()) .Add(new TestGetStation2()) .Add(new TestGetStationExceptionUp()); var wasException = false; try { var basket = new GetBasket <int, Frog>(22); await shaft.SendAsync(basket).ConfigureAwait(false); } catch (Exception ex) { wasException = true; Assert.Equal("Ex on ascent", ex.InnerException.Message); } Assert.True(wasException); }
public async Task Trace() { var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal()) .Add(new TestGetStation1()) .Add(new TestGetStation2()); var basket = new GetBasket <int, Frog>(22); await shaft.SendAsync(basket).ConfigureAwait(false); Assert.Equal(5, basket.Visits.Count); var visits = basket.Visits.ToArray(); var visit = visits[0]; Assert.True(visit.Description == typeof(TestGetStation1).ToString() && visit.Direction == VisitDirections.Down && visit.Duration > TimeSpan.Zero); visit = visits[1]; Assert.True(visit.Description == typeof(TestGetStation2).ToString() && visit.Direction == VisitDirections.Down && visit.Duration > TimeSpan.Zero); visit = visits[2]; Assert.True(visit.Description == typeof(TestGetTerminal).ToString() && visit.Direction == VisitDirections.Down && visit.Duration > TimeSpan.Zero); visit = visits[3]; Assert.True(visit.Description == typeof(TestGetStation2).ToString() && visit.Direction == VisitDirections.Up && visit.Duration > TimeSpan.Zero); visit = visits[4]; Assert.True(visit.Description == typeof(TestGetStation1).ToString() && visit.Direction == VisitDirections.Up && visit.Duration > TimeSpan.Zero); var waypointTimes = visits.Sum(v => v.Duration?.TotalMilliseconds); Assert.True(basket.JourneyDuration.TotalMilliseconds >= waypointTimes); }
public async Task Patch() { var mine = new FrogMine(); // uncached item var getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is OkNote); Assert.Equal(33, getBasket.AscentPayload.Id); // cached item getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is ReturnNote); Assert.Equal(33, getBasket.AscentPayload.Id); // uncached collection var getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); // cached collection getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is ReturnNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); await mine.SendAsync(new PatchBasket <int, Frog, int>( new PatchRequest <int, Frog>( new Delta <int, Frog>(8, new Dictionary <string, object> { { nameof(Frog.Name), "a" } })))) .ConfigureAwait(false); // get cache should still exist getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is ReturnNote); Assert.Equal(33, getBasket.AscentPayload.Id); // but get collection shouldn't getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); await mine.SendAsync(new PatchBasket <int, Frog, int>( new PatchRequest <int, Frog>( new Delta <int, Frog>(33, new Dictionary <string, object> { { nameof(Frog.Name), "a" } })))) .ConfigureAwait(false); // get cache should now be cleared exist getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is OkNote); Assert.Equal(33, getBasket.AscentPayload.Id); // and so should the get collection's getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); }
public Task <IEnumerable <BasketDto> > Handle(GetBasket request, CancellationToken cancellationToken) { throw new System.NotImplementedException(); }
// Handlers. void HandleGetBasket(GetBasket _) { Sender.Tell(_basket); }
public GetBasketResponse Post(GetBasket request) { var basket = TransactionLibrary.GetBasket(true); return(new GetBasketResponse(basket)); }
public async Task Delete() { var mine = new FrogMine(); // uncached item var getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is OkNote); Assert.Equal(33, getBasket.AscentPayload.Id); // cached item getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is ReturnNote); Assert.Equal(33, getBasket.AscentPayload.Id); // uncached collection var getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); // cached collection getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is ReturnNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); await mine.SendAsync(new DeleteBasket <int, Frog, int>(8)).ConfigureAwait(false); // get cache should still exist getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is ReturnNote); Assert.Equal(33, getBasket.AscentPayload.Id); // but get collection shouldn't getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); await mine.SendAsync(new DeleteBasket <int, Frog, int>(33)).ConfigureAwait(false); // get cache should now be cleared exist getBasket = new GetBasket <int, Frog>(33); await mine.SendAsync(getBasket).ConfigureAwait(false); Assert.True(getBasket.Note is OkNote); Assert.Equal(33, getBasket.AscentPayload.Id); // and so should the get collection's getCollectionBasket = new GetCollectionBasket <Frog>(new GetCollectionRequest <Frog>()); await mine.SendAsync(getCollectionBasket).ConfigureAwait(false); Assert.True(getCollectionBasket.Note is OkNote); Assert.Equal(3, getCollectionBasket.AscentPayload.Length); }