public void Factory_CreateNewHero_ShouldThrowArgumentExceptionForInvalidInput()
        {
            //Arrange
            IHeroFactory factory = CreateFactoryInstance();

            //Act
            Assert.That(() => factory.CreateNewHero("", 50, 0.5f), Throws.InstanceOf <ArgumentException>(),
                        "An empty name should not be allowed");
            Assert.That(() => factory.CreateNewHero(null, 50, 0.5f), Throws.InstanceOf <ArgumentException>(),
                        "An empty name should not be allowed");

            Assert.That(() => factory.CreateNewHero("John", 0, 0.5f), Throws.InstanceOf <ArgumentException>(),
                        "Strength of zero or less should not be allowed");
            Assert.That(() => factory.CreateNewHero("John", -10, 0.5f), Throws.InstanceOf <ArgumentException>(),
                        "Strength of zero or less should not be allowed");
            Assert.That(() => factory.CreateNewHero("John", 101, 0.5f), Throws.InstanceOf <ArgumentException>(),
                        "Strength bigger than 100 should not be allowed");
            Assert.That(() => factory.CreateNewHero("John", 120, 0.5f), Throws.InstanceOf <ArgumentException>(),
                        "Strength bigger than 100 should not be allowed");

            Assert.That(() => factory.CreateNewHero("John", 50, -1.0f), Throws.InstanceOf <ArgumentException>(),
                        "A negative supermode likeliness should not be allowed");
            Assert.That(() => factory.CreateNewHero("John", 50, -10.0f), Throws.InstanceOf <ArgumentException>(),
                        "A negative supermode likeliness should not be allowed");
            Assert.That(() => factory.CreateNewHero("John", 50, 1.1f), Throws.InstanceOf <ArgumentException>(),
                        "A supermode likeliness bigger than 1.0f should not be allowed");
            Assert.That(() => factory.CreateNewHero("John", 50, 10.0f), Throws.InstanceOf <ArgumentException>(),
                        "A supermode likeliness bigger than 1.0f should not be allowed");
        }
예제 #2
0
 public GameController(IUnitFactory unitFactory, IHeroFactory heroFactory, IItemFactory itemFactory)
 {
     this.unitFactory = unitFactory;
     this.heroFactory = heroFactory;
     this.itemFactory = itemFactory;
     this.heroes = new List<IHero>();
     this.numberOfDay = 1;
 }
예제 #3
0
    public HeroManager(IHeroFactory heroFactory, IItemFactory itemFactory, IRecipeFactory recipeFactory)
    {
        this.heroFactory   = heroFactory;
        this.itemFactory   = itemFactory;
        this.recipeFactory = recipeFactory;

        this.heroes = new Dictionary <string, IHero>();
    }
        private IHeroFactory CreateFactoryInstance()
        {
            AssertHasNestedFactory();
            IHeroFactory factory = Activator.CreateInstance(_factoryType) as IHeroFactory;

            Assert.That(factory, Is.Not.Null,
                        "Could not create an instance of the 'Factory' class and cast it to 'IHeroFactory'.");
            return(factory);
        }
        public void Factory_CreateNewHero_ShouldCreateAValidHero()
        {
            //Arrange
            IHeroFactory factory = CreateFactoryInstance();

            //Act
            AssertCreateValidHero(factory, "Joe", 50, 0.5f);
            AssertCreateValidHero(factory, "John", 1, 0.0f);
            AssertCreateValidHero(factory, "Jane", 100, 1.0f);
        }
 public CommandInterpreter(
     IHeroRepository heroRepository,
     IHeroFactory heroFactory,
     IItemFactory itemFactory,
     IRecipeFactory recipeFactory)
 {
     this.heroRepository = heroRepository;
     this.heroFactory    = heroFactory;
     this.itemFactory    = itemFactory;
     this.recipeFactory  = recipeFactory;
 }
        private static void AssertCreateValidHero(IHeroFactory factory, string name, int strength, float superModeLikeliness)
        {
            IHero  hero = factory.CreateNewHero(name, strength, superModeLikeliness);
            string call = $@"CreateNewHero(""{name}"", {strength}, {superModeLikeliness})";

            Assert.That(hero, Is.Not.Null, $"{call} should not return null.");
            Assert.That(hero.Name, Is.EqualTo(name), $"{call} does not set name correctly.");
            Assert.That(hero.Strength, Is.EqualTo(strength), $"{call} does not set strength correctly.");
            Assert.That(hero.SuperModeLikeliness, Is.EqualTo(superModeLikeliness),
                        $"{call} does not set supermode likeliness correctly.");
            Assert.That(hero.Health, Is.EqualTo(100), "Health should be 100.");
        }
예제 #8
0
 public Engine(
     IInputReader reader,
     IOutputWriter writer,
     IManager manager,
     IHeroFactory heroFactory,
     ICommonItemFactory commonItemFactory,
     IRecipeFactory recipeFactory)
 {
     this.reader            = reader;
     this.writer            = writer;
     this.heroManager       = manager;
     this.heroFactory       = heroFactory;
     this.commonItemFactory = commonItemFactory;
     this.recipeFactory     = recipeFactory;
 }
예제 #9
0
 private void ConstructRepository(IHeroFactory heroFactory)
 {
     try
     {
         _heroRepository = Activator.CreateInstance(typeof(InMemoryHeroRepository),
                                                    BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null,
                                                    new object[] { heroFactory },
                                                    null) as InMemoryHeroRepository;
     }
     catch (Exception)
     {
         _heroRepository = null;
     }
     Assert.That(_heroRepository, Is.Not.Null, "Failed to instantiate an InMemoryHeroRepository.");
 }
 public BattleAnalyzer(IFightAlgorithm fightAlgorithm, IArena arena, IHeroFactory heroFactory)
 {
     FightAlgorithm = fightAlgorithm;
     Arena          = arena;
     Factory        = heroFactory;
 }
예제 #11
0
파일: Program.cs 프로젝트: Belython/ITMO
 public Hero(IHeroFactory fact)
 {
     Weapon   = fact.GetHit();
     Movement = fact.GetMovement();
 }
예제 #12
0
 public HeroManager(IHeroFactory heroFactory, IInventory inventory, IList <IHero> heroes)
 {
     this.heroFactory = heroFactory;
     this.inventory   = inventory;
     this.heroes      = heroes;
 }
예제 #13
0
 public AddHeroCommand(IRepository<IHero> heroRepository, IHeroFactory heroFactory)
 {
     this.heroRepository = heroRepository;
     this.heroFactory = heroFactory;
 }
 public DCHeroesController()
 {
     _heroFactory = HttpContext.Current.Application["HeroFactory"] as IHeroFactory;
 }
예제 #15
0
 public HeroManager()
 {
     this.heroes = new Dictionary <string, IHero>();
     heroFactory = new HeroFactory();
 }
예제 #16
0
 public Engine(IReader reader, IWriter writer, IHeroFactory heroFactory)
 {
     this.reader      = reader;
     this.writer      = writer;
     this.heroFactory = heroFactory;
 }
예제 #17
0
 public Hero(IHeroFactory heroFactory)
 {
     _weapon = heroFactory.CreateWeapon();
     _armor  = heroFactory.CreateArmor();
 }