示例#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)));
        }
示例#2
0
        public void Constructor_NotNullFieldStrategyHolder_Success()
        {
            var holder  = new StrategyHolder();
            var garbage = new GarbageProcessor(holder);

            Assert.That(garbage.StrategyHolder, Is.SameAs(holder));
        }
示例#3
0
        public void TestAddingStrategyHolderToConstructor()
        {
            IStrategyHolder strategyHolder = new StrategyHolder();

            IGarbageProcessor processor = new GarbageProcessor(strategyHolder);

            Assert.AreEqual(strategyHolder, processor.StrategyHolder);
        }
        public void Constructor_ShouldInitializeCorrectlyTheObject()
        {
            // Arrange
            var strategyHolder = new StrategyHolder();

            // Act and Assert
            Assert.IsNotNull(strategyHolder);
        }
        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);
        }
        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 static void Main()
        {
            var strategyHolder          = new StrategyHolder();
            var garbageProcessor        = new GarbageProcessor(strategyHolder);
            var recyclingStationManager = new RecyclingStationManager(garbageProcessor);
            var processStarter          = new ProcessStarter(recyclingStationManager);

            processStarter.Start();
        }
    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 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);
        }
示例#11
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);
        }
示例#12
0
        public async Task Atack(string row, string col)
        {
            var socketId = Context.ConnectionId;
            int posX     = Int32.Parse(row);
            int posY     = Int32.Parse(col);

            if (duelsController.isPlayerTurn(socketId) == false)
            {
                await Clients.Caller.SendAsync("invalidTurn", row, col);
            }
            else
            {
                string enemySockeId = duelsController.GetOpponentSocketId(socketId);

                //returns active caller's strategy
                Strategy activeStrategy = StrategyHolder.GetPlayerStrategy(socketId);
                //executing the strategy returns all affected cells as AttackOutcome and cell coordinates
                List <CellOutcome> outcomes = strategyController.Attack(posX, posY, socketId);

                //for every outcome we inform both players
                foreach (CellOutcome outcome in outcomes)
                {
                    switch (outcome.attackOutcome)
                    {
                    case AttackOutcome.Hit:
                        await Clients.Client(enemySockeId).SendAsync("pingAttack", outcome.posX, outcome.posY, "Hit", false);

                        await Clients.Caller.SendAsync("pingAttack", outcome.posX, outcome.posY, "Hit", true);

                        break;

                    case AttackOutcome.Armor:
                        duelsController.ChangeTurns(socketId);
                        await Clients.Client(enemySockeId).SendAsync("pingAttack", outcome.posX, outcome.posY, "Armor", false);

                        await Clients.Caller.SendAsync("pingAttack", outcome.posX, outcome.posY, "Armor", true);

                        break;

                    //For now, both [Missed and Invalid] trigger default switch
                    default:
                        duelsController.ChangeTurns(socketId);
                        await Clients.Client(enemySockeId).SendAsync("pingAttack", outcome.posX, outcome.posY, "Missed", false);

                        await Clients.Caller.SendAsync("pingAttack", outcome.posX, outcome.posY, "Missed", true);

                        //turn change using the proxy class
                        TurnOutcome turn = proxyPlayerTurn.ChangeTurn();
                        await Clients.Client(turn.InactiveId).SendAsync("changedTurn", turn.CallerTurn);

                        await Clients.Client(turn.ActiveId).SendAsync("changedTurn", turn.OpponetTurn);

                        break;
                    }
                }
            }
        }
        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));
        }
示例#14
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);
        }
        public void GetDisposalStrategies_CollectionIsReadOnly()
        {
            var sh = new StrategyHolder();

            var strategiesType = sh.GetDisposalStrategies.GetType();
            var implementedInterfacesByCollection = ((System.Reflection.TypeInfo)strategiesType).ImplementedInterfaces;
            var implementIReadOnlyInterface       = implementedInterfacesByCollection.Any(x => x.Name.Contains("IReadOnly"));

            Assert.That(implementIReadOnlyInterface);
        }
示例#16
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 List <CellOutcome> Attack(int posx, int posy, string socketId)
        {
            Strategy    strategy = StrategyHolder.GetPlayerStrategy(socketId);
            List <Ship> ships    = GetEnemyShips(GetOpponentSocketId(socketId));
            List <Cell> cells    = GetEnemyCells(GetOpponentArenaId(socketId));

            List <CellOutcome> outcomes = strategy.Attack(posx, posy, cells, ships);

            _context.SaveChanges();
            return(outcomes);
        }
        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);
        }
示例#19
0
        public void Constructor_ShouldInitializeObject_WhenValidItemIsPassed()
        {
            // Arrange
            var strategyHolder = new StrategyHolder();


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

            // Assert
            Assert.AreEqual(strategyHolder, garbageProcessor.StrategyHolder);
        }
示例#20
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);
        }
示例#21
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();
        }
示例#22
0
    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);
    }
        private static void Main(string[] args)
        {
            var garbageFactory             = new GarbageFactory();
            var strategyHolder             = new StrategyHolder();
            var recyclingStation           = new RecyclingStation();
            var recyclingStationController = new RecyclingStationController(garbageFactory, strategyHolder, recyclingStation);
            var commandInterpreter         = new CommandInterpreter(recyclingStationController);
            var writer = new ConsoleWriter();
            var reader = new ConsoleReader();
            var engine = new Engine(writer, reader, commandInterpreter);

            engine.Run();
        }
    public void TestPropertyForReadOnlyCollection()
    {
        //Arrange
        Type            disType = typeof(DisposableAttribute);
        IStrategyHolder sut     = new StrategyHolder(strategies);

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


        //Assert
        Assert.IsTrue(type.GetInterfaces().Contains(typeof(IReadOnlyCollection <>)));
    }
示例#25
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 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));
        }
示例#28
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();
        }
示例#29
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);
    }
示例#30
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));
    }