Пример #1
0
        public void RemoveStrategy_ShouldReturnTrue_WhenRecieveValidParameters()
        {
            // Arrange
            var strategy = new BurnableDisposalStrategy();
            var type     = new DisposableAttribute();
            var holder   = new StrategyHolder();

            // Act and Assert
            Assert.IsTrue(holder.RemoveStrategy(type));
        }
Пример #2
0
    public void RemoveStrategies()
    {
        //Arrange
        Type            disType = typeof(DisposableAttribute);
        IStrategyHolder sut     = new StrategyHolder(strategies);

        bool result = sut.AddStrategy(disType, ds);

        //Assert
        Assert.IsTrue(sut.RemoveStrategy(disType));
    }
        public void RemoveStrategies()
        {
            //Arrange
            IGarbageDisposalStrategy ds = new BurnableGarbageDisposalStrategy();
            Type disType = typeof(DisposableAttribute);
            IDictionary <Type, IGarbageDisposalStrategy> strategies = new Dictionary <Type, IGarbageDisposalStrategy>();
            IStrategyHolder sut = new StrategyHolder(strategies);

            //Act
            bool reult2 = sut.AddStrategy(disType, ds);

            //Assert
            Assert.IsTrue(sut.RemoveStrategy(disType));
        }
Пример #4
0
    public void RemoveStrategiesAndCheckCount()
    {
        //Arrange
        Type            disType  = typeof(BurnableStrategyAttribute);
        Type            disType1 = typeof(StorableStrategyAttribute);
        Type            disType2 = typeof(RecyclableStrategyAttribute);
        IStrategyHolder sut      = new StrategyHolder(strategies);

        bool result  = sut.AddStrategy(disType, ds);
        bool result1 = sut.AddStrategy(disType1, ds);
        bool result2 = sut.AddStrategy(disType2, ds);

        bool removeResult = sut.RemoveStrategy(disType);

        //Assert
        Assert.AreEqual(2, sut.GetDisposalStrategies.Count);
    }
        public void RemoveStrategiesAndCheckCount()
        {
            //Arrange
            IGarbageDisposalStrategy ds = new BurnableGarbageDisposalStrategy();
            Type disType = typeof(DisposableAttribute);
            IDictionary <Type, IGarbageDisposalStrategy> strategies = new Dictionary <Type, IGarbageDisposalStrategy>();
            IStrategyHolder sut = new StrategyHolder(strategies);

            //Act
            bool reult  = sut.AddStrategy(disType, ds);
            bool reult1 = sut.AddStrategy(disType, ds);
            bool reult2 = sut.AddStrategy(disType, ds);

            bool removeResult = sut.RemoveStrategy(disType);

            //Assert
            Assert.AreEqual(0, sut.GetDisposalStrategies.Count);
        }
Пример #6
0
        public void TestRemoveStrategy()
        {
            StrategyHolder holder = new StrategyHolder();

            BurnableDisposalStrategy   burnStrategy  = new BurnableDisposalStrategy();
            RecyclableDisposalStrategy recStrategy   = new RecyclableDisposalStrategy();
            StorableDisposalStrategy   storeStrategy = new StorableDisposalStrategy();

            holder.AddStrategy(
                typeof(BurnableDisposableAttribute),
                burnStrategy);

            holder.AddStrategy(
                typeof(RecyclableDisposableAttribute),
                recStrategy);

            holder.AddStrategy(
                typeof(StorableDisposableAttribute),
                storeStrategy);

            holder.RemoveStrategy(typeof(BurnableDisposableAttribute));

            holder.GetDisposalStrategy(typeof(BurnableDisposableAttribute));
        }
        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();
            }
        }