Ejemplo n.º 1
0
        public void FinalMultiThreadedTest()
        {
            ConcurrentBag <Reserved> bag           = new ConcurrentBag <Reserved>();
            List <Reserved>          reservedsList = new List <Reserved>();

            Parallel.For(0, 10, i =>
            {
                var context          = new TestingContextDB();
                var service          = new CreateReservedService(context);
                var availableProduct = new AvailableProductService(context);
                for (var j = 0; j < 1000; j++)
                {
                    var amountOfRandom = new Random().Next(1, 3);
                    var product        = availableProduct.GetItemAsync(1).GetAwaiter().GetResult();
                    if (product != null && (product.Amount - amountOfRandom) >= 0)
                    {
                        product.Amount -= amountOfRandom;
                        var result      = service.CreateReservedAsync(Customer(context).GetAwaiter().GetResult(), product, amountOfRandom)
                                          .GetAwaiter()
                                          .GetResult();
                        if (result != null)
                        {
                            bag.Add(result);
                        }
                    }
                }
            });
            Assert.IsTrue(bag.Count > 0);
        }
Ejemplo n.º 2
0
 public void InitReserved() => serviceReserved = new CreateReservedService(new TestingContextDB());