public void DeserializeCreateStockCommand() { var serializer = new RestClientSerializer(); var id = Guid.NewGuid(); var json = "{\"id\":\"" + id + "\"," + "\"listingDate\":\"2013-01-02\"," + "\"asxCode\":\"ABC\"," + "\"name\":\"ABC Pty Ltd\"," + "\"trust\":true," + "\"category\":\"internationalProperty\"," + "\"childSecurities\":[" + "{\"asxCode\":\"ABC1\",\"name\":\"Child1\",\"trust\":true}," + "{\"asxCode\":\"ABC2\",\"name\":\"Child2\",\"trust\":false}" + "]}"; var command = serializer.Deserialize <CreateStockCommand>(json); var expected = new CreateStockCommand() { Id = id, ListingDate = new Date(2013, 01, 02), AsxCode = "ABC", Name = "ABC Pty Ltd", Trust = true, Category = AssetCategory.InternationalProperty, }; expected.AddChildSecurity("ABC1", "Child1", true); expected.AddChildSecurity("ABC2", "Child2", false); command.Should().BeEquivalentTo(expected); }
public async Task CreateStock() { var mockRepository = new MockRepository(MockBehavior.Strict); var stockId = Guid.NewGuid(); var messageHandler = mockRepository.Create <IRestClientMessageHandler>(); messageHandler.Setup(x => x.PostAsync <CreateStockCommand>( It.Is <string>(x => x == "stocks"), It.Is <CreateStockCommand>(x => x.Id == stockId && x.AsxCode == "ABC"))) .Returns(Task.CompletedTask) .Verifiable(); var resource = new StockResource(messageHandler.Object); var stock = new CreateStockCommand() { Id = stockId, AsxCode = "ABC" }; await resource.CreateStock(stock); mockRepository.Verify(); }
public IActionResult CreateStock() { var createCommand = new CreateStockCommand(Guid.NewGuid(), -1, "Gold", 0.221, 3.454); _commandDispatcher.DispatchCommand(createCommand); return(new OkObjectResult("OK")); }
//CreateStockCommand command //Guid id, string stockType, double? up, double? down, DateTime stockChange, int version, byte[] data public StockCreatedEvent(CreateStockCommand command) { Id = command.Id; StockType = command.StockType; Up = command.Up; Down = command.Down; StockChange = command.StockChange; Version = command.ExpectedVersion; Metadata = command.AsJsonString().AsByteArray(); }
public ActionResult CreateStock([FromBody] CreateStockCommand command) { ServiceResult result; // if (command.ChildSecurities.Count == 0) result = _StockService.ListStock(command.Id, command.AsxCode, command.Name, command.ListingDate, command.Trust, command.Category.ToDomain()); // else // result = _StockService.ListStapledSecurity(command.Id, command.AsxCode, command.Name, command.ListingDate, command.Category, command.ChildSecurities.Select(x => new StapledSecurityChild(x.ASXCode, x.Name, x.Trust))); return(result.ToActionResult()); }
public async Task Consume(ConsumeContext <StockInitializedIntegrationEvent> context) { StockInitializedIntegrationEvent stockInitializedIntegrationEvent = context.Message; var queryProductCommand = new QueryProductCommand(0, 1) { ProductId = stockInitializedIntegrationEvent.ProductId }; ProductCollectionResponse productCollectionResponse = await _mediator.Send(queryProductCommand); ProductResponse productResponse = productCollectionResponse.Data.First(); var createStockCommand = new CreateStockCommand(productResponse.ProductId, productResponse.ProductCode, stockInitializedIntegrationEvent.StockActionId, stockInitializedIntegrationEvent.StockCreatedOn); await _mediator.Send(createStockCommand); }
public async Task <StockResponse> Handle(CreateStockCommand request, CancellationToken cancellationToken) { if (request == null) { throw new RequestException(); } var stockModel = new StockModel(request.ProductId, request.ProductCode, 0, request.StockActionId, request.LastStockOperationDate); _dataContext.Add(stockModel); await _dataContext.SaveChangesAsync(cancellationToken); var stockResponse = stockModel.ToStockResponse(); return(stockResponse); }
public void CreateStock() { var command = new CreateStockCommand() { Id = _Stock.Id, ListingDate = new Date(2009, 01, 01), AsxCode = "XYZ", Name = "XYZ Name", Trust = true, Category = RestApi.Stocks.AssetCategory.AustralianFixedInterest }; var response = _Controller.CreateStock(command); response.Should().BeOkResult(); }
//Guid id, string stockType, double? up, double? down, DateTime stockChange, int version, byte[] data public Stock(CreateStockCommand command) { Id = command.Id; ApplyChange(new StockCreatedEvent(command)); //id, stockType, up, down, stockChange, version, data }
public async Task CreateStock(CreateStockCommand command) { await _MessageHandler.PostAsync <CreateStockCommand>("stocks", command); }