示例#1
0
        public void TestRemoveRange()
        {
            var processor = new DummyProcessor();
            var editor    = new DatabaseEditor <TestEntity>(processor);

            var entities = new List <TestEntity>()
            {
                new TestEntity()
                {
                    Age       = 100,
                    FirstName = "FN100",
                    LastName  = "LN100",
                    Id        = Guid.NewGuid()
                },
                new TestEntity()
                {
                    Age       = 101,
                    FirstName = "FN101",
                    LastName  = "LN101",
                    Id        = Guid.NewGuid()
                },
            };

            editor.RemoveRange(entities);
            Assert.AreEqual(0, editor.WriteCount);
            Assert.AreEqual(2, editor.RemoveCount);
        }
示例#2
0
        public void TestWrite()
        {
            var processor = new DummyProcessor();
            var editor    = new DatabaseEditor <TestEntity>(processor);

            var entity = new TestEntity()
            {
                Age       = 100,
                FirstName = "FN100",
                LastName  = "LN100",
                Id        = Guid.NewGuid()
            };

            editor.Write(entity);
            Assert.AreEqual(1, editor.WriteCount);
            Assert.AreEqual(0, editor.RemoveCount);

            editor.Commit();
            Assert.AreEqual(0, editor.WriteCount);
            Assert.AreEqual(0, editor.RemoveCount);
            Assert.AreEqual(1, processor.Data.Count);
            Assert.AreEqual(1, processor.Index.Count);
            Assert.AreEqual(entity.Id.ToString(), processor.Data[0]["Id"].ToString());
            Assert.AreEqual(entity.Age, processor.Data[0]["Age"].Value <int>());
            Assert.AreEqual(entity.FirstName, processor.Data[0]["Name"].ToString());
            Assert.AreEqual(entity.LastName, processor.Data[0]["LastName"].ToString());
        }
        internal static IPkpassProcessor CreateByUri(Uri uri)
        {
            PkpassProcessorElement configData = null;

            var matchWithHost = Config.ProcessorsList.ToList().Where(p => p.Domain == uri.Host);

            if (matchWithHost.Count() > 0)
            {
                configData = matchWithHost.First();
            }
            else
            {
                // No match by domain. Let's see first if the uri comes from a banned domain.
                if (Config.BannedDomainList.Get(uri.Host) != null)
                {
                    return(null);
                }
                else
                {
                    // So let's look inside the pkpass for the issuer.
                    PkpassData pkpass = new DummyProcessor().DownloadData(uri);
                    configData = Config.ProcessorsList.Get(pkpass.PassTypeIdentifier);
                }
            }

            IPkpassProcessor returnedValue = (IPkpassProcessor)Activator.CreateInstance(configData.Assembly, configData.Type).Unwrap();

            return(returnedValue);
        }
示例#4
0
        public void TestRemove()
        {
            var processor = new DummyProcessor();
            var editor    = new DatabaseEditor <TestEntity>(processor);

            editor.Remove(new TestEntity()
            {
                Age       = 100,
                FirstName = "FN100",
                LastName  = "LN100",
                Id        = Guid.NewGuid()
            });
            Assert.AreEqual(0, editor.WriteCount);
            Assert.AreEqual(1, editor.RemoveCount);
        }
示例#5
0
        public void TestWriteRange()
        {
            var processor = new DummyProcessor();
            var editor    = new DatabaseEditor <TestEntity>(processor);

            var entities = new List <TestEntity>()
            {
                new TestEntity()
                {
                    Age       = 100,
                    FirstName = "FN100",
                    LastName  = "LN100",
                    Id        = Guid.NewGuid()
                },
                new TestEntity()
                {
                    Age       = 101,
                    FirstName = "FN101",
                    LastName  = "LN101",
                    Id        = Guid.NewGuid()
                },
            };

            entities.Sort((x, y) => x.Id.CompareTo(y.Id));

            editor.WriteRange(entities);
            Assert.AreEqual(2, editor.WriteCount);
            Assert.AreEqual(0, editor.RemoveCount);

            editor.Commit();
            Assert.AreEqual(0, editor.WriteCount);
            Assert.AreEqual(0, editor.RemoveCount);
            Assert.AreEqual(2, processor.Data.Count);
            Assert.AreEqual(2, processor.Index.Count);
            for (int i = 0; i < entities.Count; i++)
            {
                var entity = entities[i];
                Assert.AreEqual(entity.Id.ToString(), processor.Data[i]["Id"].ToString());
                Assert.AreEqual(entity.Age, processor.Data[i]["Age"].Value <int>());
                Assert.AreEqual(entity.FirstName, processor.Data[i]["Name"].ToString());
                Assert.AreEqual(entity.LastName, processor.Data[i]["LastName"].ToString());
            }
        }