コード例 #1
0
        public void Pass_OnRegisterFlyweight()
        {
            // arrange
            var provider = new NamedFlyweightProvider();

            // act
            provider.RegisterFlyweight(TestFlyweight.FlyweightOne);

            // assert
            Assert.AreSame(TestFlyweight.FlyweightOne, provider.GetFlyweight(TestFlyweight.FlyweightOne.Name));
        }
コード例 #2
0
        public void Fail_OnRegister_ByArgumentException_BecauseOfDoubleRegistration()
        {
            // arrange
            var provider = new NamedFlyweightProvider();

            // act
            provider.RegisterFlyweight(TestFlyweight.FlyweightOne);

            // assert
            Assert.Throws<ArgumentException>(() => provider.RegisterFlyweight(TestFlyweight.FlyweightOne));
        }
コード例 #3
0
        public void Pass_OnGetAllFlyweights()
        {
            // arrange
            var provider = new NamedFlyweightProvider();
            provider.RegisterFlyweight(TestFlyweight.FlyweightOne);
            provider.RegisterFlyweight(TestFlyweight.FlyweightTwo);
            IFlyweight[] flyweights = null;

            // arrange
            flyweights = provider.GetAllFlyweights();

            // assert
            Assert.IsNotNull(flyweights);
            Assert.AreEqual(2, flyweights.Count());
            Assert.AreSame(TestFlyweight.FlyweightOne, flyweights[0]);
            Assert.AreSame(TestFlyweight.FlyweightTwo, flyweights[1]);
        }