Пример #1
0
        protected override void Inject(Slot source, object target)
        {
            MappingHelper.MapMatchingProperties(target, source);

            var fileSize = target.GetType().GetProperty("FileSize", BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            var nzbName  = target.GetType().GetProperty("NzbName", BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

            if (fileSize == null)
            {
                return;
            }
            if (nzbName == null)
            {
                return;
            }

            var fileSizeVal = MemorySizeConverter.ConvertToMb(source.size);

            if (fileSizeVal == default(double))
            {
                return;
            }


            fileSize.SetValue(target, fileSizeVal.ToString(CultureInfo.CurrentUICulture));
            nzbName.SetValue(target, source.nzb_name);
        }
Пример #2
0
        public void SabNzbdHistoryMapper()
        {
            var f      = new Fixture();
            var source = f.Build <Slot>().With(x => x.size, "20 MB").Create();
            var target = new NzbGetHistoryViewModel();

            target.InjectFrom(new SabNzbdHistoryMapper(), source);

            Assert.That(target.Id, Is.EqualTo(source.id));
            Assert.That(target.NzbName, Is.EqualTo(source.nzb_name));
            Assert.That(target.Status, Is.EqualTo(source.status));
            Assert.That(target.FileSize, Is.EqualTo(MemorySizeConverter.ConvertToMb(source.size).ToString(CultureInfo.CurrentUICulture)));

            Assert.That(target.Id, Is.EqualTo(source.id));
            Assert.That(target.Category, Is.EqualTo(source.category));
            Assert.That(target.Category, Is.EqualTo(source.category));
        }
        public void ConvertToMbTest(string input, double expected)
        {
            var result = MemorySizeConverter.ConvertToMb(input);

            Assert.That(result, Is.EqualTo(expected));
        }