public static void ConnectClient(Socket clientSocket) { var clientCalcIO = new TCPCalcIO(clientSocket, _consoleCalcIO); _clientCalcIO.Add(clientCalcIO); var expParser = new ExpressionParser(); var pathReader = new PathReader(); var firstOperation = new SaveNumberOperation(); var operations = new List <IOperation> { new AddOperation(), new SubstractOperation(), new DivideOperation(), new MultiplyOperation(), new JumpOperation(), new ExitOperation(), new LoadOperation(), new SaveOperation() }; var inputParser = new CalcInputParser(clientCalcIO); var mathBuffer = new MathBuffer(clientCalcIO); var history = new OperationsHistory(); var storage = new ProcessorStorageFilesWork(mathBuffer, clientCalcIO, history, expParser, pathReader, inputParser); var processor = new OperationsProcessor(storage, operations, firstOperation); processor.OperationPreReadAction += () => history.Update(processor, storage); var thread = new Thread(new ThreadStart(processor.Start)); _clientThreads.Add(thread); thread.Start(); }
private static void Main(string[] args) { // ADD FACTORY var calcIO = new ConsoleCalcIO(); var inputParser = new CalcInputParser(calcIO); var mathBuffer = new MathBuffer(calcIO); var history = new OperationsHistory(); var expParser = new ExpressionParser(); var pathReader = new PathReader(); var storage = new ProcessorStorageFilesWork(mathBuffer, calcIO, history, expParser, pathReader, inputParser); var firstOperation = new SaveNumberOperation(); var operations = new List <IOperation> { new AddOperation(), new SubstractOperation(), new DivideOperation(), new MultiplyOperation(), new JumpOperation(), new ExitOperation(), new LoadOperation(), new SaveOperation() }; var processor = new OperationsProcessor(storage, operations, firstOperation); processor.OperationPreReadAction += () => history.Update(processor, storage); processor.Start(); }
public DefaultHub( HeadProcessor <DefaultHub> head, BlocksProcessor <DefaultHub> blocks, OperationsProcessor <DefaultHub> operations, ILogger <DefaultHub> logger, IConfiguration config) : base(logger, config) { Head = head; Blocks = blocks; Operations = operations; }
public DefaultHub( HeadProcessor <DefaultHub> head, BlocksProcessor <DefaultHub> blocks, OperationsProcessor <DefaultHub> operations, BigMapsProcessor <DefaultHub> bigMaps, AccountsProcessor <DefaultHub> accounts, ILogger <DefaultHub> logger, IConfiguration config) : base(logger, config) { Head = head; Blocks = blocks; Operations = operations; BigMaps = bigMaps; Accounts = accounts; }
private static void Main(string[] args) { var calcIO = new ConsoleCalcIO(); var inputParser = new CalcInputParser(calcIO); var mathBuffer = new MathBuffer(calcIO); var storage = new ProcessorStorage(mathBuffer, calcIO, inputParser); var firstOperation = new SaveNumberOperation(); var operations = new List <IOperation> { new AddOperation(), new SubstractOperation(), new DivideOperation(), new MultiplyOperation(), new JumpOperation(), new ExitOperation() }; var processor = new OperationsProcessor(storage, operations, firstOperation); processor.Start(); }
public async Task ProcessAsync_Performs_LocalId_ReplacementAsync_In_Relationships() { // arrange var request = @"[ { ""op"": ""add"", ""data"": { ""type"": ""authors"", ""lid"": ""a"", ""attributes"": { ""name"": ""dgeb"" } } }, { ""op"": ""add"", ""data"": { ""type"": ""articles"", ""attributes"": { ""title"": ""JSON API paints my bikeshed!"" }, ""relationships"": { ""author"": { ""data"": { ""type"": ""authors"", ""lid"": ""a"" } } } } } ]"; var op1Result = @"{ ""links"": { ""self"": ""http://example.com/authors/9"" }, ""data"": { ""type"": ""authors"", ""id"": ""9"", ""lid"": ""a"", ""attributes"": { ""name"": ""dgeb"" } } }"; var operations = JsonConvert.DeserializeObject <List <Operation> >(request); var addOperationResult = JsonConvert.DeserializeObject <Operation>(op1Result); var databaseMock = new Mock <DatabaseFacade>(_dbContextMock.Object); var transactionMock = new Mock <IDbContextTransaction>(); databaseMock.Setup(m => m.BeginTransactionAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(transactionMock.Object); _dbContextMock.Setup(m => m.Database).Returns(databaseMock.Object); var opProcessorMock = new Mock <IOpProcessor>(); opProcessorMock.Setup(m => m.ProcessAsync(It.Is <Operation>(op => op.DataObject.Type.ToString() == "authors"))) .ReturnsAsync(addOperationResult); _resolverMock.Setup(m => m.LocateCreateService(It.IsAny <Operation>())) .Returns(opProcessorMock.Object); _dbContextResolverMock.Setup(m => m.GetContext()).Returns(_dbContextMock.Object); var operationsProcessor = new OperationsProcessor(_resolverMock.Object, _dbContextResolverMock.Object, _jsonApiContextMock.Object); // act var results = await operationsProcessor.ProcessAsync(operations); // assert opProcessorMock.Verify( m => m.ProcessAsync( It.Is <Operation>(o => o.DataObject.Type.ToString() == "articles" && o.DataObject.Relationships["author"].SingleData.Id == "9" ) ) ); }
public async Task ProcessAsync_Performs_LocalId_ReplacementAsync_In_References() { // arrange var request = @"[ { ""op"": ""add"", ""data"": { ""type"": ""authors"", ""lid"": ""a"", ""attributes"": { ""name"": ""jaredcnance"" } } }, { ""op"": ""update"", ""ref"": { ""type"": ""authors"", ""lid"": ""a"" }, ""data"": { ""type"": ""authors"", ""lid"": ""a"", ""attributes"": { ""name"": ""jnance"" } } } ]"; var op1Result = @"{ ""data"": { ""type"": ""authors"", ""id"": ""9"", ""lid"": ""a"", ""attributes"": { ""name"": ""jaredcnance"" } } }"; var operations = JsonConvert.DeserializeObject <List <Operation> >(request); var addOperationResult = JsonConvert.DeserializeObject <Operation>(op1Result); var databaseMock = new Mock <DatabaseFacade>(_dbContextMock.Object); var transactionMock = new Mock <IDbContextTransaction>(); databaseMock.Setup(m => m.BeginTransactionAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(transactionMock.Object); _dbContextMock.Setup(m => m.Database).Returns(databaseMock.Object); // setup add var addOpProcessorMock = new Mock <IOpProcessor>(); addOpProcessorMock.Setup(m => m.ProcessAsync(It.Is <Operation>(op => op.DataObject.Type.ToString() == "authors"))) .ReturnsAsync(addOperationResult); _resolverMock.Setup(m => m.LocateCreateService(It.IsAny <Operation>())) .Returns(addOpProcessorMock.Object); // setup update var updateOpProcessorMock = new Mock <IOpProcessor>(); updateOpProcessorMock.Setup(m => m.ProcessAsync(It.Is <Operation>(op => op.DataObject.Type.ToString() == "authors"))) .ReturnsAsync((Operation)null); _resolverMock.Setup(m => m.LocateUpdateService(It.IsAny <Operation>())) .Returns(updateOpProcessorMock.Object); _dbContextResolverMock.Setup(m => m.GetContext()).Returns(_dbContextMock.Object); var operationsProcessor = new OperationsProcessor(_resolverMock.Object, _dbContextResolverMock.Object, _jsonApiContextMock.Object); // act var results = await operationsProcessor.ProcessAsync(operations); // assert updateOpProcessorMock.Verify( m => m.ProcessAsync( It.Is <Operation>(o => o.DataObject.Type.ToString() == "authors" // && o.DataObject.Id == "9" // currently, we will not replace the data.id member && o.DataObject.Id == null && o.Ref.Id == "9" ) ) ); }