public void scenario_10()
        {
            var propertyUpgradeUoW = new Mock<IPropertyUpgradeUoW>();
            propertyUpgradeUoW.Setup(x => x.ProductTypeRepository.Get())
                .Returns(GetDomainProductTypes());
            var calculator = new CityStorageCalculator(propertyUpgradeUoW.Object);
            var cityStorage = GetCityStorage();
            cityStorage.CurrentInventory.First(x => x.ProductTypeId == 1).Quantity = 8;
            cityStorage.CurrentInventory.First(x => x.ProductTypeId == 2).Quantity = 8;
            cityStorage.CurrentInventory.First(x => x.ProductTypeId == 3).Quantity = 8;
            cityStorage.CurrentInventory.First(x => x.ProductTypeId == 4).Quantity = 8;
            var request = new CalculateStorageRequest
            {
                CityStorage = cityStorage,
                NewProductQuantities = new[]
                {
                    new SimGame.Handler.Entities.Product
                    {
                        ProductTypeId = 3,
                        Quantity = 2
                    },
                }
            };

            var ret = calculator.CalculateNewStorageAmounts(request);
            ret.CityStorage.CurrentInventory.First(x => x.ProductTypeId == 4).Quantity.ShouldEqual(6);
            ret.CityStorage.CurrentInventory.First(x => x.ProductTypeId == 3).Quantity.ShouldEqual(10);
            ret.CityStorage.CurrentInventory.First(x => x.ProductTypeId == 2).Quantity.ShouldEqual(8);
            ret.CityStorage.CurrentInventory.First(x => x.ProductTypeId == 1).Quantity.ShouldEqual(8);
        }
예제 #2
0
 public CalculateStorageResponse CalculateNewStorageAmounts(CalculateStorageRequest calculateStorageRequest)
 {
     if (ValidateRequest(calculateStorageRequest))
         return new CalculateStorageResponse
         {
             CityStorage = calculateStorageRequest.CityStorage
         };
     _productTypes = GetProductTypes(calculateStorageRequest);
     foreach (var updateProduct in calculateStorageRequest.NewProductQuantities)
     {
         AddTopLevelProductToCityStorage(updateProduct, calculateStorageRequest.CityStorage);
     }
     return new CalculateStorageResponse
     {
         CityStorage = calculateStorageRequest.CityStorage
     };
 }
예제 #3
0
 private ProductType[] GetProductTypes(CalculateStorageRequest calculateStorageRequest)
 {
     if (calculateStorageRequest.ProductTypes != null)
         return calculateStorageRequest.ProductTypes;
     return _propertyUpgradeUoW.ProductTypeRepository.Get().ToArray();
 }
예제 #4
0
 private static bool ValidateRequest(CalculateStorageRequest calculateStorageRequest)
 {
     return calculateStorageRequest == null || calculateStorageRequest.CityStorage == null ||
             calculateStorageRequest.CityStorage.CurrentInventory == null ||
             calculateStorageRequest.NewProductQuantities == null;
 }
 public CalculateStorageResponse CalculateNewStorageAmounts(CalculateStorageRequest calculateStorageRequest)
 {
     throw new System.NotImplementedException();
 }
예제 #6
0
 private CalculateStorageResponse CalculateNewCityStorageAmounts(SupplyChainRequest request, BuildingUpgradeHandlerRequest calcRequest, ProductType[] productTypes)
 {
     var strgResults = new CalculateStorageResponse
     {
         CityStorage = calcRequest.City.CurrentCityStorage
     };
     //If we have products queued for production then calculate the new city storage.
     if (request.RequiredProductUpdates == null) return strgResults;
     var calculateStorageRequest = new CalculateStorageRequest
     {
         ProductTypes = productTypes,
         NewProductQuantities = request.RequiredProductUpdates.Select(Mapper.Map<Handler.Entities.Product>).ToArray(),
         CityStorage = calcRequest.City.CurrentCityStorage
     };
     return _cityStorageCalculator.CalculateNewStorageAmounts(calculateStorageRequest);
 }