public async Task WhenClassHasNoMetaName_ThrowsArgumentException()
        {
            var t = new InvalidTestObject();

            Assert.Throws <ArgumentException>(() =>
            {
                var helper = new AzureFileStorage <InvalidTestObject>(new Mock <ICloudBlobContainer>().Object,
                                                                      o => new byte[0]);
            });
        }
        public async Task WhenStoringObjectDateTimeMin_LeavesMetaEmpty()
        {
            var t = new ValidTestObject()
            {
                Name = "StoreDateTimeMinTest", SomeDateTime = DateTime.MinValue
            };
            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            Assert.IsFalse(meta.ContainsKey("meta_SomeDateTime"));
        }
        public async Task WhenRetrievingObject_HasOriginalLongValue()
        {
            var t = new ValidTestObject()
            {
                Name = "IntMapTest", SomeLong = 1215135
            };
            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual(1215135, res.SomeLong);
        }
        public async Task WhenRetrievingObject_HasOriginalNullableDateTimeValue()
        {
            var t = new ValidTestObject()
            {
                Name = "NullableDateTimeMapTest", SomeNullableDateTime = new DateTime(2010, 6, 12)
            };
            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual(new DateTime(2010, 6, 12), res.SomeNullableDateTime);
        }
        public async Task WhenRetrievingObjectDateTimeMin_ObjectDateTimeMin()
        {
            var t = new ValidTestObject()
            {
                Name = "RetDateTimeMinTest", SomeDateTime = DateTime.MinValue
            };
            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var o = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual(DateTime.MinValue, o.SomeDateTime);
        }
        public async Task WhenRetrievingObject_HasOriginalEnumValue()
        {
            var t = new ValidTestObject()
            {
                Name = "EnumMapTest", SomeEnum = TestEnum.SecondValue
            };
            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual(TestEnum.SecondValue, res.SomeEnum);
        }
        public async Task WhenRetrievingObjectDateTimeNull_ObjectDateTimeNull()
        {
            var t = new ValidTestObject()
            {
                Name = "DateTimeNullTest", SomeNullableDateTime = null
            };
            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            Assert.IsFalse(meta.ContainsKey("meta_SomeNullableDateTime"));
            var o = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual(null, o.SomeNullableDateTime);
        }
        public async Task WhenRetrievingObjectGuidId_HasId()
        {
            var t = new ValidTestObjectGuidId()
            {
                Description = "GuidIdObject", Id = Guid.NewGuid()
            };
            var helper = new AzureFileStorage <ValidTestObjectGuidId>(GetMetaContainer(t.Id.ToString()).Object, id => new byte[0]);

            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Id.ToString());

            Assert.AreEqual(t.Id, res.Id);
        }
        public async Task WhenClassHasMetaName_GetsUsingName()
        {
            var t = new ValidTestObject()
            {
                Name = "NameNameName", Description = "NotNameNotName"
            };

            var cont = GetMetaContainer(t.Name);


            var helper = new AzureFileStorage <ValidTestObject>(cont.Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            cont.Verify(container => container.GetBlockBlobReference(t.Name), Times.Once);
        }
        public async Task WhenRetrievingObject_HasOriginalKeyValue()
        {
            var t = new ValidTestObject()
            {
                Name = "StringMapTest", Description = "TestString"
            };


            var helper = new AzureFileStorage <ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual("StringMapTest", res.Name);
        }
        public async Task WhenClassHasNoMetaName_ThrowsArgumentException()
        {
            var t = new InvalidTestObject();
            Assert.Throws<ArgumentException>(() =>
            {
                var helper = new AzureFileStorage<InvalidTestObject>(new Mock<ICloudBlobContainer>().Object,
                    o => new byte[0]);
            });

        }
        public async Task WhenRetrievingObject_HasOriginalLongValue()
        {
            var t = new ValidTestObject() { Name = "IntMapTest", SomeLong = 1215135 };
            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual(1215135, res.SomeLong);
        }
        public async Task WhenRetrievingObject_HasOriginalNullableDateTimeValue()
        {
            var t = new ValidTestObject() { Name = "NullableDateTimeMapTest", SomeNullableDateTime = new DateTime(2010, 6, 12) };
            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);
            Assert.AreEqual(new DateTime(2010, 6, 12), res.SomeNullableDateTime);
        }
        public async Task WhenStoringObjectDateTimeMin_LeavesMetaEmpty()
        {
            var t = new ValidTestObject() { Name = "StoreDateTimeMinTest", SomeDateTime = DateTime.MinValue };
            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);
            Assert.IsFalse( meta.ContainsKey("meta_SomeDateTime"));

        }
        public async Task WhenRetrievingObjectDateTimeMin_ObjectDateTimeMin()
        {
            var t = new ValidTestObject() { Name = "RetDateTimeMinTest", SomeDateTime = DateTime.MinValue };
            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var o = await helper.GetMetaItemAsync(t.Name);
            Assert.AreEqual(DateTime.MinValue, o.SomeDateTime);

        }
        public async Task WhenRetrievingObjectDateTimeNull_ObjectDateTimeNull()
        {
            var t = new ValidTestObject() { Name = "DateTimeNullTest", SomeNullableDateTime = null};
            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);
            Assert.IsFalse(meta.ContainsKey("meta_SomeNullableDateTime"));
            var o = await helper.GetMetaItemAsync(t.Name);
            Assert.AreEqual(null, o.SomeNullableDateTime);

        }
        public async Task WhenRetrievingObject_HasOriginalEnumValue()
        {
            var t = new ValidTestObject() {Name = "EnumMapTest", SomeEnum = TestEnum.SecondValue};
            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);
            Assert.AreEqual(TestEnum.SecondValue, res.SomeEnum);
        }
        public async Task WhenRetrievingObjectGuidId_HasId()
        {
            var t = new ValidTestObjectGuidId() {Description = "GuidIdObject", Id = Guid.NewGuid()};
            var helper = new AzureFileStorage<ValidTestObjectGuidId>(GetMetaContainer(t.Id.ToString()).Object, id => new byte[0]);

            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Id.ToString());
            Assert.AreEqual(t.Id, res.Id);
        }
        public async Task WhenRetrievingObject_HasOriginalKeyValue()
        {
            var t = new ValidTestObject() { Name = "StringMapTest", Description = "TestString" };


            var helper = new AzureFileStorage<ValidTestObject>(GetMetaContainer(t.Name).Object, emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            var res = await helper.GetMetaItemAsync(t.Name);

            Assert.AreEqual("StringMapTest", res.Name);
        }
        public async Task WhenClassHasMetaName_GetsUsingName()
        {
            var t = new ValidTestObject() {Name = "NameNameName", Description = "NotNameNotName"};

            var cont = GetMetaContainer(t.Name);


            var helper = new AzureFileStorage<ValidTestObject>(cont.Object,emptyByteFunc);
            await helper.TrySaveItemAsync(t);

            cont.Verify(container => container.GetBlockBlobReference(t.Name), Times.Once);
        }