Пример #1
0
        public void Reservation_Test(RealTimeInventory inventory, int toReserve)
        {
            IInventoryServiceCompletedMessage response = null;

            using (var testHelper = CreateInventoryServiceServer(inventory))
                response = testHelper.ReserveAsync(inventory, toReserve).WaitAndGetOperationResult();

            InventoryServiceSpecificationHelper.AssertReservations(inventory, toReserve, response);
        }
Пример #2
0
        private RealTimeInventory RunSomeInventoryOperationUsingEventsSync(List <Tuple <int, RealTimeInventory, int> > events, InventoryServiceServer testHelper)
        {
            var operations = InventoryServiceSpecificationHelper.GetOperations(testHelper);

            IInventoryServiceCompletedMessage currentInventoryAfterLastOperationResult = null;

            foreach (var @event in events)
            {
                currentInventoryAfterLastOperationResult = operations[@event.Item1](@event.Item2, @event.Item3).WaitAndGetOperationResult();
            }
            var currentInventoryAfterLastOperation = currentInventoryAfterLastOperationResult.RealTimeInventory;

            return(currentInventoryAfterLastOperation as RealTimeInventory);
        }
Пример #3
0
 public static void AssertHolds(IRealTimeInventory inventory, int toHold, IInventoryServiceCompletedMessage r)
 {
     if (inventory.Quantity - inventory.Holds - toHold >= 0)
     {
         Assert.True(r.Successful);
         Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds + (int)toHold);
     }
     else
     {
         Assert.False(r.Successful);
         Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds);
         //-todo when there is a failure, return nothing   Assert.Equal(r.Holds, (int)toHold);
     }
     Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
     Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity);
 }
 public RealTimeInventoryFinalResult(RealTimeInventory realTimeInventory, IInventoryServiceCompletedMessage inventoryServiceCompletedMessage, OperationResult <IRealTimeInventory> result)
 {
     RealTimeInventory = realTimeInventory;
     InventoryServiceCompletedMessage = inventoryServiceCompletedMessage;
     Result = result;
 }
Пример #5
0
        public static void AssertResetInventoryQuantityReserveAndHold(RealTimeInventory inventory, int toUpdate, int toReserve, int toHold, IInventoryServiceCompletedMessage r)
        {
            if ((toUpdate - toReserve >= 0) || toReserve <= 0)
            {
                if (toUpdate - toHold >= 0)
                {
                    Assert.True(r.Successful);
                    var newReserved = Math.Max(0, toReserve);
                    Assert.Equal(r.RealTimeInventory.Reserved, newReserved);
                    Assert.Equal(r.RealTimeInventory.Holds, toHold);
                }
                else
                {
                    Assert.False(r.Successful);
                }
            }
            else
            {
                Assert.False(r.Successful);
            }

            if (r.Successful)
            {
                return;
            }
            //else things remain same
            Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity);
            Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
            Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds);
        }
Пример #6
0
 public static void AssertUpdateQuantityAndHold(IRealTimeInventory inventory, uint toUpdate, IInventoryServiceCompletedMessage r)
 {
     if (inventory.Holds <= inventory.Quantity)
     {
         Assert.True(r.Successful);
         Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity + (int)toUpdate);
         Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
         Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds + (int)toUpdate);
     }
     else
     {
         Assert.False(r.Successful);
         Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity);
         Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
         Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds);
     }
 }
Пример #7
0
        public static void AssertUpdateQuantity(IRealTimeInventory inventory, int toUpdate, IInventoryServiceCompletedMessage r)
        {
            Assert.True(r.Successful);
            Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity + toUpdate);

            Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
            Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds);
        }
Пример #8
0
 public static void AssertPurchaseFromHolds(IRealTimeInventory inventory, uint toPurchase, IInventoryServiceCompletedMessage r)
 {
     if ((inventory.Holds >= toPurchase) && (inventory.Quantity - toPurchase >= 0))
     {
         Assert.True(r.Successful);
         Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity - (int)toPurchase);
         Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds - (int)toPurchase);
     }
     else
     {
         Assert.False(r.Successful);
         Assert.Equal(r.RealTimeInventory.Quantity, inventory.Quantity);
         Assert.Equal(r.RealTimeInventory.Holds, inventory.Holds);
         //-todo when there is a failure, return nothing      Assert.Equal(r.Quantity, (int)toPurchase);
     }
     Assert.Equal(r.RealTimeInventory.Reserved, inventory.Reserved);
 }
Пример #9
0
        public static void AssertReservations(IRealTimeInventory initialInventory, int reservationQuantity, IInventoryServiceCompletedMessage result)
        {
            if ((initialInventory.Quantity - initialInventory.Holds - initialInventory.Reserved - reservationQuantity >= 0) || reservationQuantity <= 0)
            {
                Assert.True(result.Successful);

                var newReserved = Math.Max(0, initialInventory.Reserved + reservationQuantity);

                Assert.Equal(result.RealTimeInventory.Reserved, newReserved);
            }
            else
            {
                Assert.False(result.Successful);
                Assert.Equal(result.RealTimeInventory.Reserved, initialInventory.Reserved);
            }
            Assert.Equal(result.RealTimeInventory.Holds, initialInventory.Holds);
            Assert.Equal(result.RealTimeInventory.Quantity, initialInventory.Quantity);
        }
Пример #10
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            try
            {
                var productName = "productName";
                var inventory   = new RealTimeInventory(
                    productName,
                    Convert.ToInt32(InitialQuantity.Text),
                    Convert.ToInt32(InitialReservation.Text),
                    Convert.ToInt32(InitialHold.Text));
                InventoryServiceServer helper = new InventoryServiceServer(new TestPerformanceService(), new NullBackUp(), new InventoryServerOptions()
                {
                    StorageType       = typeof(Storage.InMemoryLib.InMemory),
                    InitialInventory  = inventory,
                    ClientActorSystem = ActorSystem
                });

                var t = helper.ReserveAsync(ActorSystem.ActorSelection(textBox1.Text), 1);

                var task = ActorSystem.ActorSelection(textBox1.Text).ResolveOne(TimeSpan.FromSeconds(5));
                // task.ConfigureAwait(false);

                task.ContinueWith(r =>
                {
                    IInventoryServiceCompletedMessage result = null;
                    var newUpdate = Convert.ToInt32(NewQuantity.Text);
                    switch (cmbOoperation.SelectedItem.ToString())
                    {
                    case "ReadInventory":
                        result = helper.GetInventoryAsync(productName).WaitAndGetOperationResult();
                        break;

                    case "Reserve":
                        result = helper.ReserveAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "UpdateQuantity":
                        result = helper.UpdateQuantityAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "UpdateQuantityAndHold":
                        result = helper.UpdateQuantityAndHoldAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "PlaceHold":
                        result = helper.PlaceHoldAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "Purchase":
                        result = helper.PurchaseAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;

                    case "PurchaseFromHolds":
                        result = helper.PurchaseFromHoldsAsync(inventory, newUpdate).WaitAndGetOperationResult();
                        break;
                    }

                    if (result != null)
                    {
                        ResultQuantity.Text    = result.RealTimeInventory.Quantity.ToString();
                        ResultHold.Text        = result.RealTimeInventory.Holds.ToString();
                        ResultReservation.Text = result.RealTimeInventory.Reserved.ToString();

                        if (!result.Successful)
                        {
                            var errorMessage       = result as InventoryOperationErrorMessage;
                            var list               = new List <string>();
                            var aggregateException = errorMessage?.Error;
                            if (aggregateException != null)
                            {
                                list.Add(aggregateException.ErrorMessage);
                            }
                            richTextBox1.Text = errorMessage?.Error?.ErrorMessage + " - " + string.Join(" ", list);
                        }
                        else
                        {
                            richTextBox1.Text = "";
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                richTextBox1.Text = ex.Message + ex?.InnerException?.Message;
            }
        }