public void Test_Can_Convert_Numbers_To_Bool()
        {
            Assert.That(TypeConverters.Convert <sbyte, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <byte, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <short, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <ushort, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <int, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <uint, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <long, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <ulong, bool>(0), Is.False);
            Assert.That(TypeConverters.Convert <float, bool>(0.0f), Is.False);
            Assert.That(TypeConverters.Convert <float, bool>(float.NaN), Is.False);
            Assert.That(TypeConverters.Convert <double, bool>(0.0d), Is.False);
            Assert.That(TypeConverters.Convert <double, bool>(double.NaN), Is.False);

            Assert.That(TypeConverters.Convert <sbyte, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <byte, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <short, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <ushort, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <int, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <uint, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <long, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <ulong, bool>(123), Is.True);
            Assert.That(TypeConverters.Convert <float, bool>(123.0f), Is.True);
            Assert.That(TypeConverters.Convert <double, bool>(123.0d), Is.True);
        }
Пример #2
0
        public async Task LoadAll()
        {
            //Load Categories
            var allCategories = (await _cmsAdminService.GetCategories()).ToList();

            Categories = TypeConverters.Convert(allCategories, Guid.Empty);
            //Load Tags
            AllTags = (await _cmsAdminService.GetPublicTags()).ToList();

            //Load Self
            if (Id.IsNotNullOrEmpty())
            {
                var entity = await _dataAdminService.GetProduct(Guid.Parse(Id));

                this.MergeDataFrom(entity.To <ProductViewModel>(), new List <string> {
                    "Categories", "AllTags", "IsLoaded"
                });
            }
            else
            {
                Id = Guid.NewGuid().ToString();
            }

            IsLoaded = true;
        }
Пример #3
0
 /// <summary>Return the typed value of an item of the tuple, given its position</summary>
 /// <typeparam name="TItem">Expected type of the item</typeparam>
 /// <param name="index">Position of the item (if negative, means relative from the end)</param>
 /// <returns>Value of the item at position <paramref name="index"/>, adapted into type <typeparamref name="TItem"/>.</returns>
 public TItem Get <TItem>(int index)
 {
     if (index > 0 || index < -1)
     {
         return(TupleHelpers.FailIndexOutOfRange <TItem>(index, 1));
     }
     return(TypeConverters.Convert <T1, TItem>(this.Item1));
 }
Пример #4
0
 public TItem Get <TItem>(int index)
 {
     if (index == this.Depth || index == -1)
     {
         return(TypeConverters.Convert <T, TItem>(this.Tail));
     }
     if (index < -1)
     {
         index++;
     }
     return(this.Head.Get <TItem>(index));
 }
 public void Test_Can_Convert_Numbers_To_Int64()
 {
     Assert.That(TypeConverters.Convert <sbyte, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <byte, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <short, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <ushort, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <int, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <uint, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <long, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <ulong, long>(123), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <float, long>(123.0f), Is.EqualTo(123L));
     Assert.That(TypeConverters.Convert <double, long>(123.0d), Is.EqualTo(123L));
 }
 public void Test_Can_Convert_Numbers_To_Single()
 {
     Assert.That(TypeConverters.Convert <sbyte, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <byte, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <short, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <ushort, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <int, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <uint, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <long, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <ulong, float>(123), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <float, float>(123.0f), Is.EqualTo(123f));
     Assert.That(TypeConverters.Convert <double, float>(123.0d), Is.EqualTo(123f));
 }
 public void Test_Can_Convert_Numbers_To_String()
 {
     Assert.That(TypeConverters.Convert <sbyte, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <byte, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <short, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <ushort, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <int, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <uint, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <long, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <ulong, string>(123), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <float, string>(123.0f), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <float, string>(123.4f), Is.EqualTo("123.4"));
     Assert.That(TypeConverters.Convert <double, string>(123.0d), Is.EqualTo("123"));
     Assert.That(TypeConverters.Convert <double, string>(123.4d), Is.EqualTo("123.4"));
 }