示例#1
0
        public void TestAddingGettingStrategyToStrategyHolder()
        {
            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);

            Assert.AreEqual(burnStrategy,
                            holder.GetDisposalStrategy(typeof(BurnableDisposableAttribute)));

            Assert.AreEqual(recStrategy,
                            holder.GetDisposalStrategy(typeof(RecyclableDisposableAttribute)));

            Assert.AreEqual(storeStrategy,
                            holder.GetDisposalStrategy(typeof(StorableDisposableAttribute)));
        }
        private StrategyHolder GetAllStrategies()
        {
            StrategyHolder stratHolder = new StrategyHolder();

            stratHolder.AddStrategy(typeof(RecyclableGarbage), new RecyclableStrategy());
            stratHolder.AddStrategy(typeof(BurnableGarbage), new BurnableStrategy());
            stratHolder.AddStrategy(typeof(StorableGarbage), new StorableStrategy());
            return(stratHolder);
        }
    public void AddSameStrategiesAndCheckCollectionHaveOne()
    {
        //Arrange
        Type            disType = typeof(DisposableAttribute);
        IStrategyHolder sut     = new StrategyHolder(strategies);

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

        //Assert
        Assert.AreEqual(1, sut.GetDisposalStrategies.Count);
    }
    public void AddDifferentStrategiesAndCheckCollection()
    {
        //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);

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

        //Act
        var type = sut.AddStrategy(disType, ds);


        //Assert
        Assert.IsTrue(sut.AddStrategy(disType, ds));
    }
        public void AddSameStrategies()
        {
            //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);

            //Assert
            Assert.AreEqual(1, sut.GetDisposalStrategies.Count);
        }
        public void CheckGarbageProcessorInitializationWithAGivenStrategyHolder()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(RecyclableGarbage), new RecyclableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            Assert.AreEqual(1, this.garbageProcessor.StrategyHolder.GetDisposalStrategies.Count);
        }
        public void GarbageProcessorShouldThrowErrorIfNoStrategyIsPresentForGivenType()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(RecyclableGarbage), new RecyclableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            IWaste          burnableWasteTestObject = new BurnableGarbage("RecyclMePls", 10, 10);
            IProcessingData tempData = this.garbageProcessor.ProcessWaste(burnableWasteTestObject);
        }
    public void AddStrategy()
    {
        //Arrange
        Type            disType = typeof(DisposableAttribute);
        IStrategyHolder sut     = new StrategyHolder(strategies);

        //Assert
        Assert.IsTrue(sut.AddStrategy(disType, ds));
    }
        public void GivingNullGarbageToProcessShouldThrowError()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(RecyclableGarbage), new RecyclableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            IWaste          burnableWasteTestObject = null;
            IProcessingData tempData = this.garbageProcessor.ProcessWaste(burnableWasteTestObject);
        }
        public void AddDifferentStrategiesAndCheckCount()
        {
            //Arrange
            IGarbageDisposalStrategy ds = new BurnableGarbageDisposalStrategy();
            Type disType  = typeof(StorableStrategyAttribute);
            Type disType1 = typeof(BurnableStrategyAttribute);
            Type disType2 = typeof(RecyclableStrategyAttribute);
            IDictionary <Type, IGarbageDisposalStrategy> strategies = new Dictionary <Type, IGarbageDisposalStrategy>();
            IStrategyHolder sut = new StrategyHolder(strategies);

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


            //Assert
            Assert.AreEqual(3, sut.GetDisposalStrategies.Count);
        }
示例#12
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));
        }
        public void AddStrategy_ShouldReturnTrue_WhenRecieveValidParameters()
        {
            // Arrange
            var strategy = new BurnableDisposalStrategy();
            var type     = new DisposableAttribute();
            var holder   = new StrategyHolder();

            // Act and Assert
            Assert.IsTrue(holder.AddStrategy(type, strategy));
        }
示例#14
0
    public void RemoveSomeStrategyAndTestCount()
    {
        //Arrange
        Type dystype  = typeof(BurnableStrategyAttribute);
        Type dystype2 = typeof(RecyclableStrategyAttribute);
        Type dystype3 = typeof(StorableStrategyAttribute);

        IStrategyHolder sut = new StrategyHolder(strategies);

        //Act
        bool result  = sut.AddStrategy(dystype, ds);
        bool result1 = sut.AddStrategy(dystype2, ds);
        bool result2 = sut.AddStrategy(dystype3, ds);

        bool removeResult = sut.RemoveStrategy(dystype);

        //Assert

        Assert.AreEqual(2, sut.GetDisposalStrategies.Count);
    }
示例#15
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 GarbageProcessorProperlyProcessingBurnableGarbageWithBurnableStrategy()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(BurnableGarbage), new BurnableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            IWaste          burnableWasteTestObject = new BurnableGarbage("BurnItUp", 10, 10);
            IProcessingData tempData = this.garbageProcessor.ProcessWaste(burnableWasteTestObject);

            Assert.AreEqual(0, tempData.CapitalBalance);
            Assert.AreEqual(80, tempData.EnergyBalance);
        }
示例#17
0
    public void AddStrategy()
    {
        //Arrange
        Type            dystype = typeof(DisposableAttribute);
        IStrategyHolder sut     = new StrategyHolder(strategies);

        //Act
        bool result = sut.AddStrategy(dystype, ds);


        //Assert

        Assert.IsTrue(result);
    }
示例#18
0
    public void RemovingStrategyTest()
    {
        //Arrange
        IGarbageDisposalStrategy ds = new BurnableGarbageDisposalbeStrategy();
        Type disType = typeof(DisposableAttribute);
        Dictionary <Type, IGarbageDisposalStrategy> strategies = new Dictionary <Type, IGarbageDisposalStrategy>();
        IStrategyHolder sut = new StrategyHolder(strategies);

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


        //Assert
        Assert.IsTrue(sut.RemoveStrategy(disType));
    }
示例#19
0
        public override async Task OnConnectedAsync()
        {
            var  socketId    = Context.ConnectionId;
            int  createdId   = playersController.CreatePlayer(socketId);
            int  CreatedBAId = baController.CreateBA(createdId);
            bool editedBAId  = playersController.AddPlayerID(createdId, CreatedBAId);

            //setting Strategy for newly connected player to -> BasicAttack
            StrategyHolder.AddStrategy(socketId, new BasicAttack());

            await Clients.All.SendAsync("UserConnected", Context.ConnectionId);

            await base.OnConnectedAsync();
        }
示例#20
0
    public void TestPropertyForReadOnlyCollection()
    {
        //Arrange
        IGarbageDisposalStrategy ds = new BurnableGarbageDisposalbeStrategy();
        Type disType = typeof(DisposableAttribute);
        Dictionary <Type, IGarbageDisposalStrategy> strategies = new Dictionary <Type, IGarbageDisposalStrategy>();
        IStrategyHolder sut = new StrategyHolder(strategies);

        //Act
        Type type = sut.GetDisposalStrategies.GetType();

        //Assert
        Assert.IsTrue(sut.AddStrategy(disType, ds));
    }
示例#21
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));
        }
示例#22
0
    public void TestPropertyForReadOnlyColection()
    {
        //Arrange
        Type dystype = typeof(DisposableAttribute);

        IStrategyHolder sut = new StrategyHolder(strategies);

        //Act
        Type type = sut.GetDisposalStrategies.GetType();


        //Assert
        var test = type.GetInterfaces();

        Assert.IsTrue(sut.AddStrategy(dystype, ds));
    }
示例#23
0
        public override string Execute(string[] args, IGarbageProcessor garbageProcessor)
        {
            string name        = args[0];
            double weight      = double.Parse(args[1]);
            double volumePerKg = double.Parse(args[2]);
            string waste       = args[3];
            Type   wasteType   = Type.GetType(wasteNameSpace + waste);

            object[] par =
            {
                name,
                weight,
                volumePerKg
            };
            ConstructorInfo constructor = wasteType.GetConstructor(BindingFlags.Instance | BindingFlags.Public,
                                                                   null, new [] { typeof(string), typeof(double), typeof(double) }, null);
            IWaste garbage = (Recyclable)constructor.Invoke(par);
            var    attr    = garbage.GetType().CustomAttributes;


            garbageProcessor.ProcessWaste(garbage);
            strategyHolder.AddStrategy(wasteType, new RecyclableGarbageStrategy());
            return($"“{weight} kg of {name} successfully processed!");
        }
        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();
            }
        }