Example #1
0
        public async Task <IActionResult> Deposit(
            [FromBody] DepositRequest request,
            CancellationToken token)
        {
            var query = new DepositCommand(
                request.AccountNumber,
                request.Amount,
                CorrelationContext.Get());
            var response = await _mediator
                           .Send(
                query,
                token);

            if (!response
                .ValidationResult
                .IsValid)
            {
                var errors = string.Empty;
                response
                .ValidationResult
                .Errors
                .ToList()
                .ForEach(e => { errors += $"{e}//r//n"; });
                return(BadRequest(errors));
            }

            return(Ok(new DepositView(
                          response.Balance)));
        }
Example #2
0
        public void TestCorrelationCoreAddOperationAndVerify_RNG_Remove()
        {
            CorrelationContext cc = new CorrelationContext(1337);

            long op1 = cc.AddOperation();
            long op2 = cc.AddOperation();
            long op3 = cc.AddOperation();
            long op4 = cc.AddOperation();

            Assert.AreEqual(5, cc.CurrentOperationPosition.Position);

            long removed = cc.RemoveOperation();

            Assert.AreEqual(op4, removed);

            Assert.AreEqual(4, cc.CurrentOperationPosition.Position);

            string correlationContext = cc.Get();

            string[] parts = correlationContext.Split('|');

            // Assert.AreEqual(Convert.ToBase64String(BitConverter.GetBytes(RootValue)), parts[0]); always random
            Assert.AreEqual(Convert.ToBase64String(BitConverter.GetBytes(op1)), parts[1]);
            Assert.AreEqual(Convert.ToBase64String(BitConverter.GetBytes(op2)), parts[2]);
            Assert.AreEqual(Convert.ToBase64String(BitConverter.GetBytes(op3)), parts[3]);
        }
Example #3
0
        public void TestCorrelationCoreRestoreCapturedContext()
        {
            byte[]             manualContext = new byte[] { 57, 5, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 104, 185, 146, 200, 227, 216, 0, 0, 55, 91, 88, 60, 143, 210, 129, 32 };
            CorrelationContext cc            = new CorrelationContext(manualContext);

            string correlationContext = cc.Get();

            string[] parts = correlationContext.Split('|');

            Assert.AreEqual("OQUAAAAAAAA=", parts[0]);
            Assert.AreEqual("AwAAAAAAAAA=", parts[1]);
            Assert.AreEqual("aLmSyOPYAAA=", parts[2]);
            Assert.AreEqual("N1tYPI/SgSA=", parts[3]);
        }
Example #4
0
        public void TestCorrelationCoreAddOperationAndVerify()
        {
            CorrelationContext cc = new CorrelationContext(RootValue);

            long op1 = cc.AddOperation(SecondOperationId);
            long op2 = cc.AddOperation(ThirdOperationId);
            long op3 = cc.AddOperation(2342384793843948343L);

            Assert.AreEqual(4, cc.CurrentOperationPosition.Position);

            string correlationContext = cc.Get();

            string[] parts = correlationContext.Split('|');

            // Assert.AreEqual("OQUAAAAAAAA=", parts[0]); always random
            Assert.AreEqual("AwAAAAAAAAA=", parts[1]);
            Assert.AreEqual("aLmSyOPYAAA=", parts[2]);
            Assert.AreEqual("N1tYPI/SgSA=", parts[3]);
        }