public void CreateCompiled_ShouldHandlePrimitiveArray()
        {
            var storage = SizeStorageProvider.CreateCompiled <PrimitiveArray>();

            Assert.Equal(SizeOfPrimitiveArray,
                         storage.Calculate(Sizing, new PrimitiveArray {
                Array = new int[PrimitiveArrayLength]
            }));
        }
        public void CreateCompiled_ShouldHandleTypeValueArray()
        {
            var storage = SizeStorageProvider.CreateCompiled <TypeValueArray>();

            Assert.Equal(SizeOfPrimitive * 2 + 4, // size of array + length
                         storage.Calculate(Sizing, new TypeValueArray
            {
                Primitives = new [] { new Primitive(), new Primitive() }
            }));
        }
        public void CreateLazy_ShouldBuildOnFirstCall()
        {
            var builder = new SizingBuilder();

            Assert.Null(LazySizeOfCache <LazyPrimitive> .Builder); // ensure nothing is set yet

            var storage = SizeStorageProvider.CreateLazy <LazyPrimitive>();

            Assert.NotNull(LazySizeOfCache <LazyPrimitive> .Builder);                           // should be set now
            Assert.Throws <KeyNotFoundException>(() => SizeOfCache <LazyPrimitive> .Calculate); // still not registered, should be null

            builder.Register(storage);
            Assert.NotNull(SizeOfCache <LazyPrimitive> .Calculate); // should be set now

            Assert.Equal(4, builder.Build().SizeOf(new LazyPrimitive()));
        }
        public void CreateCompiled_ShouldHandleTypeValue()
        {
            var storage = SizeStorageProvider.CreateCompiled <TypeValue>();

            Assert.Equal(SizeOfPrimitive, storage.Calculate(Sizing, new TypeValue()));
        }