public async Task TestFulfillOrderWithBackorder()
        {
            // instruct the mock inventory service to always return less quantity than requested
            // so that FulfillOrder always ends up in backordered status.

            MockInventoryService inventoryService = new MockInventoryService()
            {
                RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(quantity - 1)
            };

            MockServiceProxy serviceProxy = new MockServiceProxy();

            serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService);

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();

            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);

            await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0);

            await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 4)
            });

            await target.FulfillOrderAsync();

            Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName));
        }
        public async Task TestFulfillOrderSimple()
        {
            // The default mock inventory service behavior is to always complete an order.

            MockInventoryService inventoryService = new MockInventoryService();

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();

            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);

            await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0);

            await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 4)
            });

            await target.FulfillOrderAsync();

            Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName));
        }
        public async Task TestFulfillOrderToCompletion()
        {
            int itemCount = 5;

            // instruct the mock inventory service to only fulfill one item each time
            // so that FulfillOrder has to make multiple iterations to complete an order
            MockInventoryService inventoryService = new MockInventoryService()
            {
                RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(1)
            };

            MockServiceProxy serviceProxy = new MockServiceProxy();

            serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService);

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();

            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);

            await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0);

            await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 5)
            });

            for (int i = 0; i < itemCount - 1; ++i)
            {
                await target.FulfillOrderAsync();

                Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName));
            }

            await target.FulfillOrderAsync();

            Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName));
        }
        public async Task TestFulfillOrderSimple()
        {
            // The default mock inventory service behavior is to always complete an order.

            MockInventoryService inventoryService = new MockInventoryService();

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();
            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);
            await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0);
            await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 4)
            });

            await target.FulfillOrderAsync();

            Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName));
        }
        public async Task TestFulfillOrderCancelled()
        {
            // instruct the mock inventory service to return 0 for all items to simulate items that don't exist.
            // and have it return false when asked if an item exists to make sure FulfillOrder doesn't get into
            // an infinite backorder loop.
            MockInventoryService inventoryService = new MockInventoryService()
            {
                IsItemInInventoryAsyncFunc = itemId => Task.FromResult(false),
                RemoveStockAsyncFunc       = (itemId, quantity, cmid) => Task.FromResult(0)
            };

            MockServiceProxy serviceProxy = new MockServiceProxy();

            serviceProxy.Supports <IInventoryService>(serviceUri => inventoryService);

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();

            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync <CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);

            await target.StateManager.SetStateAsync <long>(RequestIdPropertyName, 0);

            await target.StateManager.SetStateAsync <List <CustomerOrderItem> >(OrderItemListPropertyName, new List <CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 5)
            });

            await target.FulfillOrderAsync();

            CustomerOrderStatus status = await target.StateManager.GetStateAsync <CustomerOrderStatus>(OrderStatusPropertyName);

            Assert.AreEqual <CustomerOrderStatus>(CustomerOrderStatus.Canceled, status);
        }
        public async Task TestFulfillOrderWithBackorder()
        {
            // instruct the mock inventory service to always return less quantity than requested 
            // so that FulfillOrder always ends up in backordered status.            

            MockInventoryService inventoryService = new MockInventoryService()
            {
                RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(quantity - 1)
            };

            MockServiceProxy serviceProxy = new MockServiceProxy();
            serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService);

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();
            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);
            await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0);
            await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 4)
            });

            await target.FulfillOrderAsync();

            Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName));
        }
        public async Task TestFulfillOrderCancelled()
        {
            // instruct the mock inventory service to return 0 for all items to simulate items that don't exist.
            // and have it return false when asked if an item exists to make sure FulfillOrder doesn't get into
            // an infinite backorder loop.
            MockInventoryService inventoryService = new MockInventoryService()
            {
                IsItemInInventoryAsyncFunc = itemId => Task.FromResult(false),
                RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(0)
            };

            MockServiceProxy serviceProxy = new MockServiceProxy();
            serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService);

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();
            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);
            await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0);
            await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 5)
            });

            await target.FulfillOrderAsync();

            CustomerOrderStatus status = await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName);

            Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Canceled, status);
        }
        public async Task TestFulfillOrderToCompletion()
        {
            int itemCount = 5;

            // instruct the mock inventory service to only fulfill one item each time
            // so that FulfillOrder has to make multiple iterations to complete an order
            MockInventoryService inventoryService = new MockInventoryService()
            {
                RemoveStockAsyncFunc = (itemId, quantity, cmid) => Task.FromResult(1)
            };

            MockServiceProxy serviceProxy = new MockServiceProxy();
            serviceProxy.Supports<IInventoryService>(serviceUri => inventoryService);

            MockServiceProxyFactory serviceProxyFactory = new MockServiceProxyFactory();
            serviceProxyFactory.AssociateMockServiceAndName(new Uri("fabric:/someapp/" + InventoryServiceName), inventoryService);

            CustomerOrderActor target = await CreateCustomerOrderActor(serviceProxyFactory);

            await target.StateManager.SetStateAsync<CustomerOrderStatus>(RequestIdPropertyName, CustomerOrderStatus.Submitted);
            await target.StateManager.SetStateAsync<long>(RequestIdPropertyName, 0);
            await target.StateManager.SetStateAsync<List<CustomerOrderItem>>(OrderItemListPropertyName, new List<CustomerOrderItem>()
            {
                new CustomerOrderItem(new InventoryItemId(), 5)
            });

            for (int i = 0; i < itemCount - 1; ++i)
            {
                await target.FulfillOrderAsync();
                Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Backordered, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName));
            }

            await target.FulfillOrderAsync();
            Assert.AreEqual<CustomerOrderStatus>(CustomerOrderStatus.Shipped, await target.StateManager.GetStateAsync<CustomerOrderStatus>(OrderStatusPropertyName));
        }