Ejemplo n.º 1
0
        public void TestSelectVehicle()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("Warehouse", "OMG");

            Assert.AreEqual("Selected Semi", this.master.SelectVehicle("OMG", 1));
        }
Ejemplo n.º 2
0
        public void ATestStorageStatus()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());

            this.master.RegisterStorage("Warehouse", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("HardDrive", 8.60);

            this.master.AddProduct("HardDrive", 7.60);

            this.master.AddProduct("HardDrive", 1.50);

            this.master.RegisterStorage("Warehouse", "Fantastico");

            this.master.LoadVehicle(new string[3] {
                "HardDrive", "HardDrive", "HardDrive"
            });

            this.master.SendVehicleTo("OMG", 1, "Fantastico");

            this.master.UnloadVehicle("Fantastico", 3);

            Assert.AreEqual($"Stock (3/10): [HardDrive (3)]\r\nGarage: [Semi|Semi|Semi|Semi|empty|empty|empty|empty|empty|empty]", this.master.GetStorageStatus("Fantastico"));
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var storageMaster = new Core.StorageMaster();
            var engine        = new Engine(storageMaster);

            engine.Run();
        }
Ejemplo n.º 4
0
        public Engine(IReader reader, IWriter writer)
        {
            this.reader = reader;
            this.writer = writer;

            this.storageMaster = new StorageMaster();
        }
Ejemplo n.º 5
0
 public Engine()
 {
     this.storagemaster = new StorageMaster();
     this.productNames  = new List <string>();
     this.products      = new Dictionary <string, Stack <Product> >();
     this.storages      = new Dictionary <string, Storage>();
     this.isRunning     = false;
 }
Ejemplo n.º 6
0
 public Engine(
     StorageMaster storageMaster,
     IReader dataReader,
     IWriter dataWriter)
 {
     this.storageMaster = storageMaster;
     this.dataReader    = dataReader;
     this.dataWriter    = dataWriter;
 }
Ejemplo n.º 7
0
        public void Run()
        {
            StorageMaster storageMaster = new StorageMaster();

            while (true)
            {
                var    input   = Console.ReadLine().Split();
                string command = input[0];

                if (command.Equals("END"))
                {
                    break;
                }

                string result = null;

                try
                {
                    switch (command)
                    {
                    case "AddProduct":
                        result = storageMaster.AddProduct(input[1], double.Parse(input[2]));
                        break;

                    case "RegisterStorage":
                        result = storageMaster.RegisterStorage(input[1], input[2]);
                        break;

                    case "SelectVehicle":
                        result = storageMaster.SelectVehicle(input[1], int.Parse(input[2]));
                        break;

                    case "LoadVehicle":
                        result = storageMaster.LoadVehicle(input.Skip(1).ToList());
                        break;

                    case "SendVehicleTo":
                        result = storageMaster.SendVehicleTo(input[1], int.Parse(input[2]), input[3]);
                        break;

                    case "UnloadVehicle":
                        result = storageMaster.UnloadVehicle(input[1], int.Parse(input[2]));
                        break;

                    case "GetStorageStatus":
                        result = storageMaster.GetStorageStatus(input[1]);
                        break;
                    }
                }
                catch (InvalidOperationException e)
                {
                    result = "Error: " + e.Message;
                }
                Console.WriteLine(result);
            }
            Console.WriteLine(storageMaster.GetSummary());
        }
Ejemplo n.º 8
0
        public void Run()
        {
            string        command = Console.ReadLine();
            StorageMaster master  = new StorageMaster();

            while (command != "END")
            {
                string[] arr = command.Split();

                try
                {
                    switch (arr[0])
                    {
                    case "AddProduct":
                        string type  = arr[1];
                        double price = double.Parse(arr[2]);
                        Console.WriteLine(master.AddProduct(type, price));
                        break;

                    case "RegisterStorage":
                        type = arr[1];
                        string name = arr[2];
                        Console.WriteLine(master.RegisterStorage(type, name));
                        break;

                    case "SelectVehicle":
                        Console.WriteLine(master.SelectVehicle(storageName: arr[1], garageSlot: int.Parse(arr[2])));
                        break;

                    case "LoadVehicle":
                        IEnumerable <string> productNames = arr.Skip(1).ToArray();
                        Console.WriteLine(master.LoadVehicle(productNames));
                        break;

                    case "SendVehicleTo":
                        Console.WriteLine(master.SendVehicleTo(sourceName: arr[1], sourceGarageSlot: int.Parse(arr[2]), destinationName: arr[3]));
                        break;

                    case "UnloadVehicle":
                        Console.WriteLine(master.UnloadVehicle(storageName: arr[1], garageSlot: int.Parse(arr[2])));
                        break;

                    case "GetStorageStatus":
                        Console.WriteLine(master.GetStorageStatus(storageName: arr[1]));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex.Message}");
                }
                command = Console.ReadLine();
            }
            Console.WriteLine(master.GetSummary());
        }
Ejemplo n.º 9
0
        public void StorageMasterConstructorPass()
        {
            IReader reader = new ConsoleReader();
            IWriter writer = new ConsoleWriter();
            Engine  engine = new Engine(reader, writer);

            StorageMaster.Core.StorageMaster storageMaster = new StorageMaster.Core.StorageMaster();
            string type  = "car";
            double price = 1000;

            Assert.AreEqual($"Added {type} to pool", storageMaster.AddProduct(type, price));
        }
Ejemplo n.º 10
0
        public void TestLoadingWithMoreStuffThrows()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("Warehouse", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("Ram", 8.60);

            this.master.AddProduct("Ram", 7.60);

            Assert.Throws <InvalidOperationException>(() => this.master.LoadVehicle(new string[3] {
                "Ram", "Ram", "Ram"
            }));
        }
Ejemplo n.º 11
0
        public void TestLoading()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("Warehouse", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("Ram", 8.60);

            this.master.AddProduct("Ram", 7.60);

            Assert.AreEqual("Loaded 2/2 products into Semi", this.master.LoadVehicle(new string[2] {
                "Ram", "Ram"
            }));
        }
Ejemplo n.º 12
0
        public void TestSendVehicle()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("DistributionCenter", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("HardDrive", 8.60);

            this.master.AddProduct("HardDrive", 7.60);

            this.master.AddProduct("HardDrive", 1.50);

            this.master.RegisterStorage("Warehouse", "Fantastico");

            Assert.AreEqual("Sent Van to Fantastico (slot 3)", this.master.SendVehicleTo("OMG", 1, "Fantastico"));
        }
Ejemplo n.º 13
0
        public void TestLoadingWhenVehicleIsFull()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("DistributionCenter", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("HardDrive", 8.60);

            this.master.AddProduct("HardDrive", 7.60);

            this.master.AddProduct("HardDrive", 1.50);

            Assert.AreEqual("Loaded 2/3 products into Van", this.master.LoadVehicle(new string[3] {
                "HardDrive", "HardDrive", "HardDrive"
            }));
        }
Ejemplo n.º 14
0
        public void SendVehicleShouldThrowWhenWrongStorage()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("DistributionCenter", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("HardDrive", 8.60);

            this.master.AddProduct("HardDrive", 7.60);

            this.master.AddProduct("HardDrive", 1.50);

            this.master.RegisterStorage("Warehouse", "Fantastico");

            Assert.Throws <InvalidOperationException>(() => this.master.SendVehicleTo("Kurax", 1, "Fantastico"));

            Assert.Throws <InvalidOperationException>(() => this.master.SendVehicleTo("OMG", 1, "Kurax"));
        }
Ejemplo n.º 15
0
        private static void Execute(string commandLine, StorageMaster storageMaster)
        {
            var    args    = commandLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var    command = args[0];
            string result;

            switch (command)
            {
            case "AddProduct":
                result = storageMaster.AddProduct(args[1], double.Parse(args[2]));
                break;

            case "RegisterStorage":
                result = storageMaster.RegisterStorage(args[1], args[2]);
                break;

            case "SelectVehicle":
                result = storageMaster.SelectVehicle(args[1], int.Parse(args[2]));
                break;

            case "LoadVehicle":
                result = storageMaster.LoadVehicle(args.Skip(1).ToArray());
                break;

            case "SendVehicleTo":
                result = storageMaster.SendVehicleTo(args[1], int.Parse(args[2]), args[3]);
                break;

            case "UnloadVehicle":
                result = storageMaster.UnloadVehicle(args[1], int.Parse(args[2]));
                break;

            case "GetStorageStatus":
                result = storageMaster.GetStorageStatus(args[1]);
                break;

            default:
                throw new ArgumentException();
            }

            Console.WriteLine(result);
        }
Ejemplo n.º 16
0
        public void Run()
        {
            var storageMaster = new StorageMaster();

            string commandLine;

            while ((commandLine = Console.ReadLine()) != "END")
            {
                try
                {
                    Execute(commandLine, storageMaster);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine($"Error: {ex.Message}");
                }
            }

            Console.WriteLine(storageMaster.GetSummary());
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            var storageFac = new StorageFactory();

            var storageRepo = new StorageRepository();

            var productFac = new ProductFactory();

            var productRepo = new ProductRepository();

            var master = new Core.StorageMaster(productFac, productRepo, storageFac, storageRepo);

            var reader = new Reader();

            var writer = new Writer();

            var engine = new Engine(master, reader, writer);

            engine.Run();
        }
Ejemplo n.º 18
0
        public void ATestUnloadVehicle()
        {
            this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
            this.master.RegisterStorage("Warehouse", "OMG");

            this.master.SelectVehicle("OMG", 1);

            this.master.AddProduct("HardDrive", 8.60);

            this.master.AddProduct("HardDrive", 7.60);

            this.master.AddProduct("HardDrive", 1.50);

            this.master.RegisterStorage("Warehouse", "Fantastico");

            this.master.LoadVehicle(new string[3] {
                "HardDrive", "HardDrive", "HardDrive"
            });

            this.master.SendVehicleTo("OMG", 1, "Fantastico");

            Assert.AreEqual("Unloaded 3/3 products at Fantastico", this.master.UnloadVehicle("Fantastico", 3));
        }
Ejemplo n.º 19
0
        public void MoveCommand(string inputLine, StorageMaster sm)
        {
            string[] input   = inputLine.Split();
            string   command = input[0];

            switch (command)
            {
            case "AddProduct":
                Console.WriteLine(sm.AddProduct(input[1], double.Parse(input[2]))); break;

            case "RegisterStorage":
                Console.WriteLine(sm.RegisterStorage(input[1], input[2])); break;

            case "SelectVehicle":
                Console.WriteLine(sm.SelectVehicle(input[1], int.Parse(input[2]))); break;

            case "LoadVehicle":
                List <string> collection = new List <string>();
                for (int i = 1; i < input.Length; i++)
                {
                    collection.Add(input[i]);
                }
                Console.WriteLine(sm.LoadVehicle(collection)); break;

            case "SendVehicleTo":
                Console.WriteLine(sm.SendVehicleTo(input[1], int.Parse(input[2]), input[3])); break;

            case "UnloadVehicle":
                Console.WriteLine(sm.UnloadVehicle(input[1], int.Parse(input[2]))); break;

            case "GetStorageStatus":
                Console.WriteLine(sm.GetStorageStatus(input[1])); break;

            default: break;
            }
        }
Ejemplo n.º 20
0
 public Engine()
 {
     this.storageMaster = new StorageMaster();
     this.outputs       = new StringBuilder();
 }
Ejemplo n.º 21
0
 public Engine(StorageMaster storageMaster)
 {
     this.storageMaster = storageMaster;
     IsRunning          = false;
 }
 public Engine()
 {
     this.storageMaster = new StorageMaster();
 }
Ejemplo n.º 23
0
 public void TestAddProduct()
 {
     this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
     Assert.AreEqual("Added Ram to pool", this.master.AddProduct("Ram", 8.60));
 }
Ejemplo n.º 24
0
 public Engine()
 {
     sm = new StorageMaster();
 }
Ejemplo n.º 25
0
 public Engine(IReader dataReader, IWriter dataWriter)
 {
     this.storageMaster = new StorageMaster();
     this.dataReader    = dataReader;
     this.dataWriter    = dataWriter;
 }
Ejemplo n.º 26
0
 public void Setup()
 {
     this.storageMaster = new StorageMaster.Core.StorageMaster();
 }
Ejemplo n.º 27
0
        public void Run()
        {
            string[] command = Console.ReadLine()
                               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();

            StorageMaster storageMaster = new StorageMaster();

            while (command[0]?.ToLower() != "end")
            {
                try
                {
                    string type             = string.Empty;
                    double price            = 0;
                    string name             = string.Empty;
                    string storageName      = string.Empty;
                    int    garageSlot       = 0;
                    string sourceName       = string.Empty;
                    int    sourceGarageSlot = 0;
                    string destinationName  = string.Empty;

                    switch (command[0].ToLower())
                    {
                    case "addproduct":
                        type  = command[1];
                        price = double.Parse(command[2]);
                        string addedProduct = storageMaster.AddProduct(type, price);
                        Console.WriteLine(addedProduct);
                        break;

                    case "registerstorage":
                        type = command[1];
                        name = command[2];
                        string registeredStorage = storageMaster.RegisterStorage(type, name);
                        Console.WriteLine(registeredStorage);
                        break;

                    case "selectvehicle":
                        storageName = command[1];
                        garageSlot  = int.Parse(command[2]);
                        string selectedVehicle = storageMaster.SelectVehicle(storageName, garageSlot);
                        Console.WriteLine(selectedVehicle);
                        break;

                    case "loadvehicle":
                        List <string> productNames = new List <string>();
                        for (int i = 1; i < command.Length; i++)
                        {
                            productNames.Add(command[i]);
                        }
                        string loadedVehicle = storageMaster.LoadVehicle(productNames);
                        Console.WriteLine(loadedVehicle);
                        break;

                    case "sendvehicleto":
                        sourceName       = command[1];
                        sourceGarageSlot = int.Parse(command[2]);
                        destinationName  = command[3];
                        string sendVehicle = storageMaster.SendVehicleTo(sourceName, sourceGarageSlot, destinationName);
                        Console.WriteLine(sendVehicle);
                        break;

                    case "unloadvehicle":
                        storageName = command[1];
                        garageSlot  = int.Parse(command[2]);
                        string unloadedVehicle = storageMaster.UnloadVehicle(storageName, garageSlot);
                        Console.WriteLine(unloadedVehicle);
                        break;

                    case "getstoragestatus":
                        storageName = command[1];
                        string storageStatus = storageMaster.GetStorageStatus(storageName);
                        Console.WriteLine(storageStatus);
                        break;

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine($"Error: {e.Message}");
                }
                command = Console.ReadLine()
                          .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                          .ToArray();
            }
            Console.WriteLine(storageMaster.GetSummary());
        }
Ejemplo n.º 28
0
 public void TestRegisterStorage()
 {
     this.master = new StorageMaster(new ProductFactory(), new ProductRepository(), new StorageFactory(), new StorageRepository());
     Assert.AreEqual("Registered OMG", this.master.RegisterStorage("Warehouse", "OMG"));
 }
Ejemplo n.º 29
0
 public Engine(StorageMaster sm)
 {
     this.sm = sm;
 }
Ejemplo n.º 30
0
 public Engine()
 {
     this.storageMaster = new StorageMaster();
     this.IsRunning     = true;;
 }