Example #1
0
        private string BooksWithImagesDatabaseDump()
        {
            LocalDbRepository <Book>  books;
            LocalDbRepository <Image> images;

            using (new DatabaseScope())
            {
                books  = new LocalDbRepository <Book>(new DbConfig(true));
                images = new LocalDbRepository <Image>(new DbConfig(true));
                Assert.IsFalse(books.ReposetoryCreated);
                Assert.IsFalse(images.ReposetoryCreated);
            }

            for (var i = 0; i < 3; i++)
            {
                var book = new Book();
                books.Add(book);

                var image = new Image();
                image.IdBook = book.BookId;
                images.Add(image);
            }

            var serializableContent = books.Database.GetSerializableContent();
            var xmlSer = new XmlSerializer(typeof(DataContent));

            using (var memStream = new MemoryStream())
            {
                xmlSer.Serialize(memStream, serializableContent);
                var content = Encoding.ASCII.GetString(memStream.ToArray());
                Assert.That(content, Is.Not.Null.And.Not.Empty);
                return(content);
            }
        }
Example #2
0
        public void ReadBooksWithImages()
        {
            _booksWithImagesDatabaseDump = BooksWithImagesDatabaseDump();

            LocalDbRepository <Book>  books;
            LocalDbRepository <Image> images;

            using (var scope = new DatabaseScope())
            {
                var config = new DbConfig(true);
                books            = new LocalDbRepository <Book>(config);
                images           = new LocalDbRepository <Image>(config);
                scope.SetupDone += Scope_SetupDone;
            }

            Assert.That(books.Count, Is.EqualTo(3));
            Assert.That(images.Count, Is.EqualTo(3));
            CollectionAssert.AllItemsAreInstancesOfType(books, typeof(Book));
            CollectionAssert.AllItemsAreNotNull(books);
            CollectionAssert.AllItemsAreUnique(books);

            CollectionAssert.AllItemsAreInstancesOfType(images, typeof(Image));
            CollectionAssert.AllItemsAreNotNull(images);
            CollectionAssert.AllItemsAreUnique(images);
            Assert.That(books, Is.All.Property("BookId").Not.EqualTo(0).And.All.Property("BookName").Null);
            Assert.That(images, Is.All.Property("ImageId").Not.EqualTo(0)
                        .And.All.Property("Text").Null
                        .And.All.Property("IdBook").Not.EqualTo(0));
        }
Example #3
0
        private string UsersDatabaseDump()
        {
            LocalDbRepository <Users> users;

            using (new DatabaseScope())
            {
                users = new LocalDbRepository <Users>(new DbConfig(true));
                Assert.IsFalse(users.ReposetoryCreated);
            }

            for (var i = 0; i < 3; i++)
            {
                var user = new Users();
                users.Add(user);
            }

            var serializableContent = users.Database.GetSerializableContent();
            var xmlSer = new XmlSerializer(typeof(DataContent));

            using (var memStream = new MemoryStream())
            {
                xmlSer.Serialize(memStream, serializableContent);
                var content = Encoding.ASCII.GetString(memStream.ToArray());
                Assert.That(content, Is.Not.Null.And.Not.Empty);
                return(content);
            }
        }
		public LocalDbRepository<Image> TestInit(IEnumerable<ILocalDbCheckConstraint<Image>> checks,
			IEnumerable<ILocalDbUniqueConstraint<Image>> unique,
			IEnumerable<ILocalDbDefaultConstraint<Image>> defaults)
		{
			LocalDbRepository<Image> images;
			using (new DatabaseScope())
			{
				images = new LocalDbRepository<Image>(new DbConfig());
				if (checks != null)
					foreach (var localDbCheckConstraint in checks)
					{
						images.Constraints.Check.Add(localDbCheckConstraint);
					}
				if (unique != null)
					foreach (var localDbCheckConstraint in unique)
					{
						images.Constraints.Unique.Add(localDbCheckConstraint);
					}
				if (defaults != null)
					foreach (var localDbCheckConstraint in defaults)
					{
						images.Constraints.Default.Add(localDbCheckConstraint);
					}
			}
			return images;
		}
Example #5
0
        public void Create()
        {
            using (new DatabaseScope())
            {
                var dbConfig = new DbConfig(true);
                AppUsers     = new LocalDbRepository <AppUserEntity>(dbConfig);
                UserData     = new LocalDbRepository <UserDataEntity>(dbConfig);
                Roles        = new LocalDbRepository <RoleEntity>(dbConfig);
                ChatGroups   = new LocalDbRepository <ChatGroupEntity>(dbConfig);
                ChatMessages = new LocalDbRepository <ChatMessageEntity>(dbConfig);
                ChatGroupMap = new LocalDbRepository <ChatGroupUserMap>(dbConfig);

                var storeLocation = ConfigurationManager.AppSettings["SaveLocation"];
                if (File.Exists(storeLocation))
                {
                    using (var fs = new FileStream(storeLocation, FileMode.Open))
                    {
                        using (new TransactionScope())
                        {
                            using (new ReplicationScope())
                            {
                                new XmlSerializer(typeof(DataContent)).Deserialize(fs);
                            }
                        }
                    }
                }
            }
        }
        public LocalDbRepository <Image> TestInit(IEnumerable <ILocalDbCheckConstraint <Image> > checks,
                                                  IEnumerable <ILocalDbUniqueConstraint <Image> > unique,
                                                  IEnumerable <ILocalDbDefaultConstraint <Image> > defaults)
        {
            LocalDbRepository <Image> images;

            using (new DatabaseScope())
            {
                images = new LocalDbRepository <Image>(new DbConfig(true));
                if (checks != null)
                {
                    foreach (var localDbCheckConstraint in checks)
                    {
                        images.Constraints.Check.Add(localDbCheckConstraint);
                    }
                }
                if (unique != null)
                {
                    foreach (var localDbCheckConstraint in unique)
                    {
                        images.Constraints.Unique.Add(localDbCheckConstraint);
                    }
                }
                if (defaults != null)
                {
                    foreach (var localDbCheckConstraint in defaults)
                    {
                        images.Constraints.Default.Add(localDbCheckConstraint);
                    }
                }
            }
            return(images);
        }
Example #7
0
        public AdminController()
        {
            repo      = new LocalDbRepository();
            repo_data = new VisualDataRepository(ConfigurationManager.AppSettings["dbPath"]);
            repo_ext  = new ExternalRepository(ConfigurationManager.AppSettings["dbPath"]);

            //Thread.CurrentThread.CurrentCulture.
        }
Example #8
0
		public void TestInit()
		{
			using (new DatabaseScope())
			{
				_users = new LocalDbRepository<Users>(new DbConfig(), _useObjectCopy, null);
			}

			Assert.IsTrue(_users.ReposetoryCreated);
		}
		private LocalDbRepository<Users> MockRepro()
		{
			LocalDbRepository<Users> users;
			using (var db = new DatabaseScope())
			{
				users = new LocalDbRepository<Users>(new DbConfig());
			}
			return users;
		}
 public void TestInit()
 {
     using (new DatabaseScope())
     {
         _books          = new LocalDbRepository <Book>(new DbConfig(true));
         _images         = new LocalDbRepository <Image>(new DbConfig(true));
         _imagesNullable = new LocalDbRepository <ImageNullable>(new DbConfig(true));
     }
 }
Example #11
0
        public void TestInit()
        {
            using (new DatabaseScope())
            {
                _users = new LocalDbRepository <Users>(new DbConfig(true), _useObjectCopy, null);
            }

            Assert.IsTrue(_users.ReposetoryCreated);
        }
		public void TestInit()
		{
			using (new DatabaseScope())
			{
				_books = new LocalDbRepository<Book>(new DbConfig());
				_images = new LocalDbRepository<Image>(new DbConfig());
				_imagesNullable = new LocalDbRepository<ImageNullable>(new DbConfig());
			}
		}
Example #13
0
        private LocalDbRepository <Users> MockRepro()
        {
            LocalDbRepository <Users> users;

            using (var db = new DatabaseScope())
            {
                users = new LocalDbRepository <Users>(new DbConfig(true));
            }
            return(users);
        }
Example #14
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ConstraintCollection{TEntity}" /> class.
 /// </summary>
 /// <param name="localDbRepository">The local database repository.</param>
 /// <param name="primaryKey">The primary key.</param>
 internal ConstraintCollection(
     LocalDbRepository <TEntity> localDbRepository,
     ILocalDbPrimaryKeyConstraint primaryKey)
 {
     _localDbRepository = localDbRepository;
     PrimaryKey         = primaryKey;
     Unique             = new UniqueConstrains <TEntity>(localDbRepository);
     Default            = new DefaultConstraints <TEntity>(localDbRepository);
     Check = new CheckConstraints <TEntity>(localDbRepository);
 }
Example #15
0
        public void WriteBooksWithImages()
        {
            LocalDbRepository <Book>  books;
            LocalDbRepository <Image> images;

            using (new DatabaseScope())
            {
                books  = new LocalDbRepository <Book>(new DbConfig(true));
                images = new LocalDbRepository <Image>(new DbConfig(true));
                Assert.IsFalse(books.ReposetoryCreated);
                Assert.IsFalse(images.ReposetoryCreated);
            }

            for (var i = 0; i < 3; i++)
            {
                var book = new Book();
                books.Add(book);

                var image = new Image();
                image.IdBook = book.BookId;
                images.Add(image);
            }

            var serializableContent = books.Database.GetSerializableContent();
            var xmlSer = new XmlSerializer(typeof(DataContent));

            using (var memStream = new MemoryStream())
            {
                xmlSer.Serialize(memStream, serializableContent);
                var content = Encoding.ASCII.GetString(memStream.ToArray());
                Assert.That(content, Is.Not.Null.And.Not.Empty);
                memStream.Seek(0, SeekOrigin.Begin);

                LocalDbRepository <Book>  booksN;
                LocalDbRepository <Image> imagesN;
                using (new DatabaseScope())
                {
                    booksN  = new LocalDbRepository <Book>(new DbConfig(true));
                    imagesN = new LocalDbRepository <Image>(new DbConfig(true));
                    Assert.IsFalse(booksN.ReposetoryCreated);
                    Assert.IsFalse(imagesN.ReposetoryCreated);
                    using (new TransactionScope())
                    {
                        using (new ReplicationScope())
                        {
                            xmlSer.Deserialize(memStream);
                        }
                    }
                }
            }
        }
Example #16
0
        public void TestInit()
        {
            using (new DatabaseScope())
            {
                _books          = new LocalDbRepository <Book>(new DbConfig(true));
                _images         = new LocalDbRepository <Image>(new DbConfig(true));
                _imagesNullable = new LocalDbRepository <ImageNullable>(new DbConfig(true));
                Assert.IsFalse(_books.ReposetoryCreated);
                Assert.IsFalse(_images.ReposetoryCreated);
                Assert.IsFalse(_imagesNullable.ReposetoryCreated);
            }

            Assert.IsTrue(_books.ReposetoryCreated);
            Assert.IsTrue(_images.ReposetoryCreated);
            Assert.IsTrue(_imagesNullable.ReposetoryCreated);
        }
Example #17
0
		public void TestInit()
		{
			using (new DatabaseScope())
			{
				_books = new LocalDbRepository<Book>(new DbConfig());
				_images = new LocalDbRepository<Image>(new DbConfig());
				_imagesNullable = new LocalDbRepository<ImageNullable>(new DbConfig());
				Assert.IsFalse(_books.ReposetoryCreated);
				Assert.IsFalse(_images.ReposetoryCreated);
				Assert.IsFalse(_imagesNullable.ReposetoryCreated);
			}

			Assert.IsTrue(_books.ReposetoryCreated);
			Assert.IsTrue(_images.ReposetoryCreated);
			Assert.IsTrue(_imagesNullable.ReposetoryCreated);
		}
Example #18
0
        public void ReadUsers()
        {
            _usersDatabaseDump = UsersDatabaseDump();
            LocalDbRepository <Users> users;

            using (var scope = new DatabaseScope())
            {
                users = new LocalDbRepository <Users>(new DbConfig(true));

                scope.SetupDone += Scope_SetupDone1;
            }

            Assert.That(users.Count, Is.EqualTo(3));
            Assert.That(users.ElementAt(0), Is.Not.Null.And.Property("UserID").EqualTo(1));
            Assert.That(users.ElementAt(1), Is.Not.Null.And.Property("UserID").EqualTo(2));
            Assert.That(users.ElementAt(2), Is.Not.Null.And.Property("UserID").EqualTo(3));
        }
Example #19
0
        internal ReplicationNode(LocalDbRepository <TEntity> table, IReplicationNode <TEntity> duplication = null)
        {
            var table1       = table;
            var duplication1 = duplication;

            if (duplication != null)
            {
                For       = new SequentialSequentialTriggerCollection <TEntity>(table1, duplication1.For);
                After     = new SequentialSequentialTriggerCollection <TEntity>(table1, duplication1.After);
                InsteadOf = new TriggerInsteadtOfCollection <TEntity>(table1, duplication1.InsteadOf);
            }
            else
            {
                For       = new SequentialSequentialTriggerCollection <TEntity>(table1);
                After     = new SequentialSequentialTriggerCollection <TEntity>(table1);
                InsteadOf = new TriggerInsteadtOfCollection <TEntity>(table1);
            }
        }
Example #20
0
        public void WriteUsers()
        {
            LocalDbRepository <Users> users;

            using (new DatabaseScope())
            {
                users = new LocalDbRepository <Users>(new DbConfig(true));
            }

            users.Add(new Users());
            users.Add(new Users());
            users.Add(new Users());

            var serializableContent = users.Database.GetSerializableContent();
            var xmlSer = new XmlSerializer(typeof(DataContent));

            using (var memStream = new MemoryStream())
            {
                xmlSer.Serialize(memStream, serializableContent);
                var content = Encoding.ASCII.GetString(memStream.ToArray());
                Assert.That(content, Is.Not.Null.And.Not.Empty);
            }
        }
Example #21
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TriggerException{TEntity}" /> class.
 /// </summary>
 /// <param name="reason">The reason.</param>
 /// <param name="table">The table.</param>
 public TriggerException(string reason, LocalDbRepository <TEntity> table)
     : base("One trigger rejected the change. See reason.")
 {
     Reason = reason;
     _table = table;
 }
Example #22
0
 internal TriggerInsteadtOfCollection(LocalDbRepository <TEntity> tabel,
                                      ITriggerInsteadtOfCollection <TEntity> duplication = null)
 {
     _tabel       = tabel;
     _duplication = duplication;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="SequentialSequentialTriggerCollection{TEntity}" /> class.
 /// </summary>
 /// <param name="tabel">The tabel.</param>
 /// <param name="duplication">The duplication.</param>
 internal SequentialSequentialTriggerCollection(LocalDbRepository <TEntity> tabel,
                                                ISequentialTriggerCollection <TEntity> duplication = null)
 {
     Tabel       = tabel;
     Duplication = duplication;
 }
Example #24
0
 public DbScope()
 {
     database = new DatabaseScope();
     users    = new LocalDbRepository <Users>(new DbConfig(true));
 }
 public AppointmentsService()
 {
     this._localDbRepository = new LocalDbRepository <Appointment>();
 }
Example #26
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DefaultConstraints{TEntity}" /> class.
 /// </summary>
 /// <param name="localDbRepository">The local database repository.</param>
 public DefaultConstraints(LocalDbRepository <TEntity> localDbRepository)
 {
     _constraints       = new HashSet <ILocalDbDefaultConstraint <TEntity> >(new ConstraintComparer());
     _localDbRepository = localDbRepository;
 }
			public DbScope()
			{
				database = new DatabaseScope();
				users = new LocalDbRepository<Users>(new DbConfig());
			}
Example #28
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="UniqueConstrains{TEntity}" /> class.
 /// </summary>
 /// <param name="localDbRepository">The local database repository.</param>
 public UniqueConstrains(LocalDbRepository <TEntity> localDbRepository)
 {
     _constraints       = new HashSet <ILocalDbUniqueConstraint <TEntity> >();
     _localDbRepository = localDbRepository;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="TriggerForTableCollection{TEntity}" /> class.
 /// </summary>
 /// <param name="table">The table.</param>
 internal TriggerForTableCollection(LocalDbRepository <TEntity> table)
 {
     _table            = table;
     NotForReplication = new ReplicationNode <TEntity>(_table);
     WithReplication   = new ReplicationNode <TEntity>(_table, NotForReplication);
 }
Example #30
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="InsteadtOfActionToken{TEntity}" /> class.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="table">The table.</param>
 public InsteadtOfActionToken(TEntity item, LocalDbRepository <TEntity> table)
 {
     Item  = item;
     Table = table;
 }
 public SpecialistsService()
 {
     this._localDbRepository = new LocalDbRepository <Specialist>();
 }