Exemplo n.º 1
0
 public void TestAddingTypeWithNullStrategyShouldThrowException()
 {
     this.strategyHolder = new StrategyHolder();
     this.strategyHolder.AddStrategy(
         typeof(RecyclableGarbageDisposableAttribute),
         null);
 }
Exemplo n.º 2
0
 public void TestAddingNullTypeWithStrategyShouldThrowException()
 {
     this.strategyHolder = new StrategyHolder();
     this.strategyHolder.AddStrategy(
         null,
         new RecyclableGarbageDisposableStrategy());
 }
Exemplo n.º 3
0
        public void Initialize()
        {
            this.strategyHolder = new StrategyHolder();

            this.mockedStrategy = new Mock <IGarbageDisposalStrategy>();
            this.data           = new Dictionary <Type, IGarbageDisposalStrategy>();
        }
Exemplo n.º 4
0
        public GarbageProcessor(IProcessingData processingData, IStrategyHolder strategyHolder)
        {
            this.ProcessingData = processingData;
            this.StrategyHolder = new StrategyHolder();

            this.InitialiseStrategyHoder();
        }
 public RecyclingStationController(GarbageFactory garbageFactory, IStrategyHolder strategyHolder, IRecyclingStation recyclingStation)
 {
     this.garbageFactory   = garbageFactory;
     this.RecylingStation  = recyclingStation;
     this.strategyHolder   = strategyHolder;
     this.garbageProcessor = new GarbageProcessor(strategyHolder);
 }
Exemplo n.º 6
0
 public void TestRemovingNonExistantStrategyShouldThrowException()
 {
     this.strategyHolder = new StrategyHolder();
     this.strategyHolder.AddStrategy(
         typeof(RecyclableGarbageDisposableAttribute),
         new RecyclableGarbageDisposableStrategy());
     this.strategyHolder.RemoveStrategy(typeof(BurnableGarbageDisposableAttribute));
 }
        public void Initialize()
        {
            this.strategyHolder = new StrategyHolder();
            this.strategyHolder.AddStrategy(typeof(BurnableAttribute), new BurnableStrategy());
            this.strategyHolder.AddStrategy(typeof(RecyclableAttribute), new RecyclableStrategy());

            this.garbageProcessor = new GarbageProcessor(this.strategyHolder);
        }
Exemplo n.º 8
0
        public void TestRemoveStrategyShouldDecreaseCountCorrectly()
        {
            this.strategyHolder = new StrategyHolder();
            this.strategyHolder.AddStrategy(
                typeof(RecyclableGarbageDisposableAttribute),
                new RecyclableGarbageDisposableStrategy());
            this.strategyHolder.RemoveStrategy(typeof(RecyclableGarbageDisposableAttribute));

            Assert.AreEqual(0, this.strategyHolder.GetDisposalStrategies.Count, "Removing strategy should decrease count by 1!");
        }
Exemplo n.º 9
0
 public void TestAddingSameTypeShouldNotIncreaseCount()
 {
     this.strategyHolder = new StrategyHolder();
     this.strategyHolder.AddStrategy(
         typeof(RecyclableGarbageDisposableAttribute),
         new RecyclableGarbageDisposableStrategy());
     this.strategyHolder.AddStrategy(
         typeof(RecyclableGarbageDisposableAttribute),
         new BurnableGarbageDisposableStrategy());
 }
Exemplo n.º 10
0
 public Engine(IResourcesDatabase resDatabase)
 {
     this.resDatabase      = resDatabase;
     this.strategyholder   = new StrategyHolder();
     this.garbageProcessor = new GarbageProcessor(this.strategyholder);
     this.resController    = new ResourcesController(this.resDatabase, this.garbageProcessor);
     this.comExecutor      = new CommandExecutor(this.resController);
     this.consoleReader    = new ConsoleReader();
     this.consoleWriter    = new ConsoleWriter();
     this.inputInterpreter = new InputInterpreter();
 }
Exemplo n.º 11
0
        public void TestAddingAStrategyShouldAddItCorrectly()
        {
            this.strategyHolder = new StrategyHolder();
            this.strategyHolder.AddStrategy(
                typeof(RecyclableGarbageDisposableAttribute),
                new RecyclableGarbageDisposableStrategy());

            var isContained =
                this.strategyHolder.GetDisposalStrategies.ContainsKey(typeof(RecyclableGarbageDisposableAttribute));

            Assert.IsTrue(isContained, "After adding attribute type-strategy pair strategies should contain it!");
        }
Exemplo n.º 12
0
        public void Initialize()
        {
            this.strategyHolder = new StrategyHolder();
            var mockStrategy  = new Mock <IGarbageDisposalStrategy>();
            var mockStrategy2 = new Mock <IGarbageDisposalStrategy>();

            this.mockedDisposableAttribute   = typeof(MockedDisposableAttribute);
            this.mockedDisposableAttribute2  = typeof(SecondMockedDisposableAttribute);
            this.abstractDisposableAttribute = typeof(AbstractDisposableAttribute);
            this.mockedStrategy  = mockStrategy;
            this.mockedStrategy2 = mockStrategy2;
        }
Exemplo n.º 13
0
        public void TestAddingStrategyIncreasesCountCorrectly()
        {
            this.strategyHolder = new StrategyHolder();
            this.strategyHolder.AddStrategy(
                typeof(RecyclableGarbageDisposableAttribute),
                new RecyclableGarbageDisposableStrategy());

            Assert.AreEqual(
                1,
                this.strategyHolder.GetDisposalStrategies.Count,
                "Add Strategy should increase count of strategies correctly!");
        }
Exemplo n.º 14
0
        public Engine(
            IRecyclingStationRepository repository,
            IGarbageProcessor garbageProcessor,
            IStrategyHolder strategyHolder,
            IInputOutput inputOutput)
        {
            this.repository       = repository;
            this.garbageProcessor = garbageProcessor;
            this.strategyHolder   = strategyHolder;
            this.inputOutput      = inputOutput;

            this.LoadStrategies();
        }
        public void RemoveStrategyWithInvalidAttributeTypeShouldBeUnsucceful()
        {
            // Act
            this.strategies[typeof(RecyclableStrategyAttribute)] = new RecyclableGarbageDisposalStrategy();
            this.strategyHolder = new StrategyHolder(this.strategies);

            // Act
            var success = this.strategyHolder.RemoveStrategy(typeof(string));

            // Assert
            Assert.AreEqual(false, success,
                            "Removing strategy with invalid attribute type was unsuccessful!");
        }
        public void RemoveStrategyWithExisingAttributeTypeShouldBeSuccessful()
        {
            // Act
            this.strategies[typeof(RecyclableStrategyAttribute)] = new RecyclableGarbageDisposalStrategy();
            this.strategies[typeof(BurnableStrategyAttribute)]   = new BurnableGarbageDisposalStrategy();
            this.strategies[typeof(StorableStrategyAttribute)]   = new StorableGarbageDisposalStrategy();
            this.strategyHolder = new StrategyHolder(this.strategies);

            // Act
            var success = this.strategyHolder.RemoveStrategy(typeof(RecyclableStrategyAttribute));

            // Assert
            Assert.AreEqual(true, success, "Existing existing strategy was not removed!");
        }
Exemplo n.º 17
0
        public void TestRemovingStrategyRemovesCorrectStrategy()
        {
            this.strategyHolder = new StrategyHolder();
            this.strategyHolder.AddStrategy(
                typeof(RecyclableGarbageDisposableAttribute),
                new RecyclableGarbageDisposableStrategy());
            this.strategyHolder.AddStrategy(
                typeof(BurnableGarbageDisposableAttribute),
                new BurnableGarbageDisposableStrategy());
            this.strategyHolder.RemoveStrategy(typeof(RecyclableGarbageDisposableAttribute));
            var isContained =
                this.strategyHolder.GetDisposalStrategies.ContainsKey(typeof(RecyclableGarbageDisposableAttribute));

            Assert.IsFalse(isContained, "After removing attribute type-strategy pair strategies should not contain it!");
        }
        public void RemoveStrategyWithExistingAttributeTypesShouldDecreaseStrategiesCount()
        {
            // Act
            this.strategies[typeof(RecyclableStrategyAttribute)] = new RecyclableGarbageDisposalStrategy();
            this.strategies[typeof(BurnableStrategyAttribute)]   = new BurnableGarbageDisposalStrategy();
            this.strategies[typeof(StorableStrategyAttribute)]   = new StorableGarbageDisposalStrategy();
            this.strategyHolder = new StrategyHolder(this.strategies);

            // Act
            var success = this.strategyHolder.RemoveStrategy(typeof(RecyclableStrategyAttribute));

            // Assert
            Assert.AreEqual(2, this.strategyHolder.GetDisposalStrategies.Count,
                            "Removing existing strategies did not decrease strategies count!");
        }
        public void RemoveStrategyWithNonExistingAttributeTypeShouldNotChangeStrategiesCount()
        {
            // Act
            this.strategies[typeof(RecyclableStrategyAttribute)] = new RecyclableGarbageDisposalStrategy();
            this.strategyHolder = new StrategyHolder(this.strategies);
            var initialStrategiesCount = this.strategyHolder.GetDisposalStrategies.Count;

            // Act
            var success = this.strategyHolder.RemoveStrategy(typeof(StorableGarbageDisposalStrategy));

            // Assert
            Assert.AreEqual(initialStrategiesCount,
                            this.strategyHolder.GetDisposalStrategies.Count,
                            "Strategies count changed upon removing a non-existing strategy!");
        }
        public void GetDisposalStrategiesShouldMatchTheInputStrategies()
        {
            // Arrange
            this.strategies[typeof(RecyclableStrategyAttribute)] = new RecyclableGarbageDisposalStrategy();
            this.strategies[typeof(BurnableStrategyAttribute)]   = new BurnableGarbageDisposalStrategy();
            this.strategies[typeof(StorableStrategyAttribute)]   = new StorableGarbageDisposalStrategy();
            this.strategyHolder = new StrategyHolder(this.strategies);

            // Act
            var fetchedStrategies = this.strategyHolder.GetDisposalStrategies;

            // Assert
            CollectionAssert.AreEqual(this.strategies, fetchedStrategies,
                                      "Fetched strategies did not match input strategies!");
        }
Exemplo n.º 21
0
 public void TestAddingSameMultipleStrategiesShouldIncreaseCount()
 {
     this.strategyHolder = new StrategyHolder();
     this.strategyHolder.AddStrategy(
         typeof(RecyclableGarbageDisposableAttribute),
         new RecyclableGarbageDisposableStrategy());
     this.strategyHolder.AddStrategy(
         typeof(BurnableGarbageDisposableAttribute),
         new BurnableGarbageDisposableStrategy());
     this.strategyHolder.AddStrategy(
         typeof(StorableGarbageDisposableAttribute),
         new StorableGarbageDisposableStrategy());
     Assert.AreEqual(
         3,
         this.strategyHolder.GetDisposalStrategies.Count,
         "Add Strategy should increase count of strategies correctly when types are different!");
 }
        public void GetDisposalStrategiesCountShouldEqualInputCount()
        {
            // Arrange
            this.strategies[typeof(RecyclableStrategyAttribute)] = new RecyclableGarbageDisposalStrategy();
            this.strategies[typeof(BurnableStrategyAttribute)]   = new BurnableGarbageDisposalStrategy();
            this.strategies[typeof(StorableStrategyAttribute)]   = new StorableGarbageDisposalStrategy();
            var inputStrategiesCount = this.strategies.Count;

            this.strategyHolder = new StrategyHolder(this.strategies);

            // Act
            var fetchedStrategiesCount = this.strategyHolder.GetDisposalStrategies.Count;

            // Assert
            Assert.AreEqual(inputStrategiesCount, fetchedStrategiesCount,
                            "Fetched strategies count did not match input strategies count!");
        }
 public void SetUp()
 {
     this.strategyHolder = new StrategyHolder();
 }
Exemplo n.º 24
0
 public void TestEmptyCtorWorksCorrectly()
 {
     this.strategyHolder = new StrategyHolder();
     Assert.AreEqual(0, this.strategyHolder.GetDisposalStrategies.Count, "Strategy Holder Constructor should initialize strategies as empty dictionary");
 }
 public void InitializeFields()
 {
     this.strategyHolder = new StrategyHolder();
     this.attribute      = new DisposableAttribute();
 }
Exemplo n.º 26
0
 public void TestInit()
 {
     this.sh = new StrategyHolder();
 }
Exemplo n.º 27
0
 public void TestInitializer()
 {
     this.strategyHolder = new StrategyHolder();
 }
 public void TestInit()
 {
     this.strategies     = new Dictionary <Type, IGarbageDisposalStrategy>();
     this.strategyHolder = new StrategyHolder(this.strategies);
 }
Exemplo n.º 29
0
 public GarbageProcessor(IStrategyHolder strategyHolder)
 {
     this.StrategyHolder = strategyHolder;
 }
 public GarbageProcessor(IStrategyHolder strategyHolder)
 {
     this.StrategyHolder = strategyHolder;
     this.AddStratagyHolder();
 }
Exemplo n.º 31
0
 public GarbageProcessor(IStrategyHolder strategyHolder)
 {
     this.StrategyHolder = strategyHolder;
 }