예제 #1
0
        public void Constructor_NotNullFieldStrategyHolder_Success()
        {
            var holder  = new StrategyHolder();
            var garbage = new GarbageProcessor(holder);

            Assert.That(garbage.StrategyHolder, Is.SameAs(holder));
        }
예제 #2
0
        public void TestAddingStrategyHolderToConstructor()
        {
            IStrategyHolder strategyHolder = new StrategyHolder();

            IGarbageProcessor processor = new GarbageProcessor(strategyHolder);

            Assert.AreEqual(strategyHolder, processor.StrategyHolder);
        }
        public static void Main()
        {
            var strategyHolder          = new StrategyHolder();
            var garbageProcessor        = new GarbageProcessor(strategyHolder);
            var recyclingStationManager = new RecyclingStationManager(garbageProcessor);
            var processStarter          = new ProcessStarter(recyclingStationManager);

            processStarter.Start();
        }
예제 #4
0
        public void ProcessWaste_SomeWaste_ThrowsException()
        {
            var holder  = new StrategyHolder();
            var garbage = new GarbageProcessor(holder);

            var waste = new StorableWaste("NuclearWaste", 10, 10);

            Assert.That(() => garbage.ProcessWaste(waste), Throws.ArgumentException);
        }
예제 #5
0
        public void ProcessWaste_ShouldThrowArgumentException()
        {
            // Arrange
            var garbage          = new StorableWaste("glass", 10.5, 1.2);
            var strategyHolder   = new StrategyHolder();
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            // Act and Assert
            garbageProcessor.ProcessWaste(garbage);
        }
예제 #6
0
        public void PropertyStrategyHolder_ShouldGetCorrectly()
        {
            // Arrange
            var strategyHolder   = new StrategyHolder();
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            // Act
            var actualStrategyHolder = garbageProcessor.StrategyHolder;

            // Assert
            Assert.AreEqual(strategyHolder, actualStrategyHolder);
        }
예제 #7
0
        public void Constructor_ShouldInitializeObject_WhenValidItemIsPassed()
        {
            // Arrange
            var strategyHolder = new StrategyHolder();


            // Act
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            // Assert
            Assert.AreEqual(strategyHolder, garbageProcessor.StrategyHolder);
        }
예제 #8
0
        public static void Main()
        {
            IGarbageFactory   garbageFactory   = new GarbageFactory();
            IGarbageProcessor garbageProcessor = new GarbageProcessor();
            IProcessingData   processingData   = new ProcessingData();

            ICommandInterpreter commandInterpreter =
                new CommandInterpreter(garbageFactory, garbageProcessor, processingData);

            IRunnable engine = new Engine(commandInterpreter);

            engine.Run();
        }
예제 #9
0
        public static void Main()
        {
            var processingData   = new ProcessingData();
            var strategyHolder   = new StrategyHolder();
            var garbageProcessor = new GarbageProcessor(processingData, strategyHolder);

            var reader      = new ConsoleReader();
            var writer      = new ConsoleWriter();
            var interpreter = new CommandInterpreter();
            var engine      = new Engine(interpreter, garbageProcessor, reader, writer);

            engine.Run();
        }
예제 #10
0
        public static void Main()
        {
            IReader reader = new ConsoleReader();
            IWriter writer = new ConsoleWriter();
            Dictionary <Type, IGarbageDisposalStrategy> strategies = new Dictionary <Type, IGarbageDisposalStrategy>();
            IStrategyHolder   strategyHolder   = new StrategyHolder(strategies);
            IGarbageProcessor garbageProcessor = new GarbageProcessor(strategyHolder);
            IWasteFactory     wasteFactory     = new WasteFactory();
            IRecyclingManager recyclingManager = new RecyclingManager(garbageProcessor, wasteFactory);
            IEngine           engine           = new Engine(reader, writer, recyclingManager);

            engine.Run();
        }
        private static void Main()
        {
            IOutputWriter       outputWriter       = new ConsoleWriter();
            IInputReader        inputReader        = new ConsoleReader();
            IRepository         repo               = new Repository();
            IWasteFactory       wasteFactory       = new WasteFactory();
            StrategyHolder      strategies         = new StrategyHolder();
            IGarbageProcessor   processor          = new GarbageProcessor(strategies);
            ICommandInterpreter commandInterpreter = new CommandInterpreter(repo, wasteFactory, processor);

            IRunable engine = new Engine(commandInterpreter, inputReader, outputWriter);

            engine.Run();
        }
        public static void Main()
        {
            IReader             consoleReader      = new ConsoleReader();
            IWriter             consoleWriter      = new ConsoleWriter();
            IInputOutputManager inputOutputManager = new InputOutputManager(consoleReader, consoleWriter);

            IStrategyHolder   strategyHolder   = new StrategyHolder(new Dictionary <Type, IGarbageDisposalStrategy>());
            IGarbageProcessor garbageProcessor = new GarbageProcessor(strategyHolder);
            IGarbageFactory   garbageFactory   = new GarbageFactory();
            IRecyclingManager recyclingManager = new RecyclingManager(garbageProcessor, garbageFactory);

            IRunnable engine = new Engine(inputOutputManager, recyclingManager);

            engine.Run();
        }
        private static RecyclingManager CreateRecyclingManager()
        {
            var garbageFactory = new GarbageFactory();

            var strategyHolder   = new StrategyHolder(new Dictionary <Type, IGarbageDisposalStrategy>());
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            var requirementData = new StoredData(0, 0);
            var recyclingManagementRequirement = new RecyclingManagementRequirement(requirementData, null);

            var storedData = new StoredData(0, 0);

            var recyclingManager = new RecyclingManager(garbageFactory, garbageProcessor, recyclingManagementRequirement, storedData);

            return(recyclingManager);
        }
예제 #14
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            IInputOutput consoleInputOutput              = new ConsoleInputOutput();
            IRecyclingStationRepository repository       = new RecyclingStationRepository();
            IStrategyHolder             strategyHolder   = new StrategyHolder();
            IGarbageProcessor           garbageProcessor = new GarbageProcessor(strategyHolder);

            IEngine engine = new Engine(
                repository,
                garbageProcessor,
                strategyHolder,
                consoleInputOutput);

            engine.Run();
        }
예제 #15
0
    private static void Main()
    {
        IReader reader = new ConsoleReader();
        IWriter writer = new ConsoleWriter();

        IStrategyHolder strategyHolder = new StrategyHolder();

        IGarbageProcessor garbageProcessor = new GarbageProcessor(strategyHolder);

        IWasteFactory wasteFactory = new WasteFactory();

        IRecyclingManager recyclingManager = new RecyclingManager(garbageProcessor, wasteFactory);

        IEngine engine = new Engine(reader, writer, recyclingManager);

        engine.Run();
    }
예제 #16
0
        public void ProcessWaste_ShouldReturnValidCurrentStrategy()
        {
            // Arrange
            var garbage          = new StorableWaste("glass", 10.5, 1.2);
            var strategyHolder   = new StrategyHolder();
            var garbageProcessor = new GarbageProcessor(strategyHolder);

            Type type = garbage.GetType();
            DisposableAttribute      disposalAttribute = (DisposableAttribute)type.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(DisposableAttribute));
            IGarbageDisposalStrategy currentStrategy   = new BurnableDisposalStrategy();
            var expectedResult = currentStrategy.ProcessGarbage(garbage);

            // Act
            var actualResult = garbageProcessor.ProcessWaste(garbage);

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
예제 #17
0
        public void ProcessWaste()
        {
            double expectedRecCapital    = 4000;
            double expectedRecBurnEnergy = -5.7;
            double expectedBurnEnergy    = 97.0012;
            double expectedCapital       = 0;
            double expectedStorCapital   = -2.2961;
            double expectedStorEnergy    = -0.4592;

            BurnableGarbage   burnGarbage = new BurnableGarbage("Burnable", 3.657, 33.156);
            RecyclableGarbage recGarbage  = new RecyclableGarbage("rec", 1.14, 10);
            StorableGarbage   storGarbage = new StorableGarbage("stor", 1.57, 2.25);

            IStrategyHolder strategyHolder = new StrategyHolder();

            strategyHolder.AddStrategy(
                typeof(BurnableDisposableAttribute),
                new BurnableDisposalStrategy());

            strategyHolder.AddStrategy(
                typeof(RecyclableDisposableAttribute),
                new RecyclableDisposalStrategy());

            strategyHolder.AddStrategy(
                typeof(StorableDisposableAttribute),
                new StorableDisposalStrategy());

            IGarbageProcessor processor   = new GarbageProcessor(strategyHolder);
            IProcessingData   processData = processor.ProcessWaste(burnGarbage);

            Assert.AreEqual(expectedBurnEnergy, Math.Round(processData.EnergyBalance, 4));
            Assert.AreEqual(expectedCapital, processData.CapitalBalance);

            processData = processor.ProcessWaste(recGarbage);

            Assert.AreEqual(expectedRecBurnEnergy, Math.Round(processData.EnergyBalance, 1));
            Assert.AreEqual(expectedRecCapital, processData.CapitalBalance);

            processData = processor.ProcessWaste(storGarbage);

            Assert.AreEqual(expectedStorEnergy, Math.Round(processData.EnergyBalance, 4));
            Assert.AreEqual(expectedStorCapital, Math.Round(processData.CapitalBalance, 4));
        }
        private static void Main(string[] args)
        {
            double energy  = 0;
            double capital = 0;

            ManagementRequirement managementRequierement = null;

            var input = Console.ReadLine();

            while (input != "TimeToRecycle")
            {
                if (input == "Status")
                {
                    Console.WriteLine("Energy: {0:0.00} Capital: {1:0.00}", energy, capital);
                }
                else
                {
                    var commandArgs = input?.Split(' ', '|');

                    if (commandArgs?[0] == "ProcessGarbage")
                    {
                        var strategyHolder = new StrategyHolder();
                        strategyHolder.AddStrategy(typeof(RecyclableAttribute), new RecyclableGarbageDsiposalStrategy());
                        strategyHolder.AddStrategy(typeof(BurnableAttribute), new BurnableGarbageDisposalStrategy());
                        strategyHolder.AddStrategy(typeof(StorableAttribute), new StorableGarbageDisposalStrategy());

                        var garbageProcessor = new GarbageProcessor(strategyHolder);

                        var name        = commandArgs[1];
                        var weight      = Convert.ToDouble(commandArgs[2]);
                        var volumePerKg = Convert.ToDouble(commandArgs[3]);
                        var type        = commandArgs[4];

                        IWaste garbage = null;
                        switch (type)
                        {
                        case "Recyclable":
                            garbage = new RecyclableGarbage(name, volumePerKg, weight);
                            break;

                        case "Burnable":
                            garbage = new BurnableGarbage(name, volumePerKg, weight);
                            break;

                        case "Storable":
                            garbage = new StorableGarbage(name, volumePerKg, weight);
                            break;

                        default:
                            throw new ArgumentException();
                        }

                        if (managementRequierement != null &&
                            (managementRequierement.CapitalBalance > capital ||
                             managementRequierement.EnergyBalance > energy))
                        {
                            Type attrType = Type.GetType("RecyclingStation.WasteDisposal.Attributes." + managementRequierement.GarbageType + "Attribute");
                            strategyHolder.RemoveStrategy(attrType);
                        }

                        var data = garbageProcessor.ProcessWaste(garbage);
                        if (data != null)
                        {
                            energy  += data.EnergyBalance;
                            capital += data.CapitalBalance;

                            Console.WriteLine("{0:0.00} kg of {1} successfully processed!", weight, name);
                        }
                        else
                        {
                            Console.WriteLine("Processing Denied!");
                        }
                    }
                    else if (commandArgs?[0] == "ChangeManagementRequirement")
                    {
                        var energyBalance  = Convert.ToDouble(commandArgs[1]);
                        var capitalBalance = Convert.ToDouble(commandArgs[2]);
                        var garbageType    = commandArgs[3];

                        managementRequierement = new ManagementRequirement(energyBalance, capitalBalance, garbageType);

                        Console.WriteLine("Management requirement changed!");
                    }
                }

                input = Console.ReadLine();
            }
        }
예제 #19
0
 protected Command(GarbageProcessor garbageProcessor, string[] args)
 {
     this.GarbageProcessor = garbageProcessor;
     this.Args             = args;
 }
예제 #20
0
 public StatusCommand(GarbageProcessor garbageProcessor, string[] args)
     : base(garbageProcessor, args)
 {
 }
예제 #21
0
        public void EmptyConstructor_NotNullFieldStrategyHolder_Success()
        {
            var garbage = new GarbageProcessor();

            Assert.That(garbage.StrategyHolder, Is.Not.Null);
        }
예제 #22
0
 public Engine()
 {
     this.garbageProcessor = new GarbageProcessor();
 }
 public ChangeManagementRequirementCommand(GarbageProcessor garbageProcessor, string[] args)
     : base(garbageProcessor, args)
 {
 }
 public ProcessGarbageCommand(GarbageProcessor garbageProcessor, string[] args)
     : base(garbageProcessor, args)
 {
 }