public void Valid_Test()
        {
            var            builder = PddbTestingInstance.GetFake();
            PersonalDataDB pddb    = PersonalDataDB.Create(new InMemoryDataProvider());

            pddb.CreateDatabase(builder);
        }
Example #2
0
        public void Create_IfNotExist_Twice()
        {
            var pddb = new PersonalDataDB(new InMemoryDataProvider());

            pddb.CreateDatabaseIfNotExist(PddbTestingInstance.GetFake());
            pddb.CreateDatabaseIfNotExist(PddbTestingInstance.GetFake());
        }
        public static PersonalDataDB GetPddbInstanceForTesting()
        {
            var            builder = PddbTestingInstance.GetFake();
            PersonalDataDB pddb    = new PersonalDataDB(new InMemoryDataProvider());

            pddb.CreateDatabase(builder);
            return(pddb);
        }
        public void Missing_Schema_Throws_Exception()
        {
            var builder = PddbTestingInstance.GetFake();

            builder.Schema = null;
            PersonalDataDB pddb = PersonalDataDB.Create(new InMemoryDataProvider());

            Assert.Throws <InitializationException>(() => pddb.CreateDatabase(builder));
        }
Example #5
0
        public void Create_Twice_Throws_Exception()
        {
            var pddb = new PersonalDataDB(new InMemoryDataProvider());

            pddb.CreateDatabase(PddbTestingInstance.GetFake());
            Assert.Throws <PersonalDataDBException>(() =>
            {
                pddb.CreateDatabase(PddbTestingInstance.GetFake());
            });
        }
        public void Invalid_Admin_Throws_Exception()
        {
            var builder = PddbTestingInstance.GetFake();

            ((AdministratorMock)builder.Administrator !).FullName = "";

            PersonalDataDB pddb = PersonalDataDB.Create(new InMemoryDataProvider());

            Assert.Throws <InitializationException>(() => pddb.CreateDatabase(builder));
        }
        public void Invalid_Schema_No_Tables_Throws_Exception()
        {
            var builder = PddbTestingInstance.GetFake();

            ((SchemaMock)builder.Schema !).TableMocks = new List <TableDefinitionMock>();

            PersonalDataDB pddb = PersonalDataDB.Create(new InMemoryDataProvider());

            Assert.Throws <InitializationException>(() => pddb.CreateDatabase(builder));
        }
        public void Invalid_Schema_Duplicate_Columns_Throws_Exception()
        {
            var        builder = PddbTestingInstance.GetFake();
            SchemaMock sm      = ((SchemaMock)builder.Schema !);

            sm.TableMocks[1].ColumnMocks[0].ID = sm.TableMocks[1].ColumnMocks[1].ID;

            PersonalDataDB pddb = PersonalDataDB.Create(new InMemoryDataProvider());

            Assert.Throws <InitializationException>(() => pddb.CreateDatabase(builder));
        }
        public void Invalid_DataManager()
        {
            var builder = PddbTestingInstance.GetFake();

            ((DataManagerMock)builder.DataManager !).Name = "";
            PersonalDataDB pddb = PersonalDataDB.Create(new InMemoryDataProvider());

            Assert.Throws <InitializationException>(() =>
            {
                pddb.CreateDatabase(builder);
            });
        }
Example #10
0
        public void Create()
        {
            var builder = new DefaultInitializationDataProvider()
                          .UseDataManager(new DataManagerInitialization()
            {
                Name                           = "SomeCompany",
                Address                        = "Street 1",
                Email                          = "*****@*****.**",
                Phone                          = "123456789",
                RegistrationNumber             = "123",
                PersonalDataRegistrationNumber = "456"
            })
                          .UseAdministrator(new AdministratorInitialization()
            {
                FullName            = "Karel Admin",
                Phone               = "123456789",
                Email               = "*****@*****.**",
                OfficeNumber        = "123",
                InternalPhoneNumber = "456",
                Supervisor          = "Charles Supervisor"
            })
                          .UseConfiguration(new ConfigurationInitialization()
            {
                AllowPurposeChoiceOnAgreementCreation = false
            })
                          .UseSchema((b) =>
            {
                b.AddTable("Persons", tb =>
                {
                    tb.Name        = "Persons table";
                    tb.Description = "Contains personal data of people";
                    tb.AddColumn("FullName", ColumnType.String, false);
                    tb.AddColumn("Phone", ColumnType.String, true);
                });
                b.AddTable("GPSPositions", tb =>
                {
                    tb.Name        = "GPS positions";
                    tb.Description = "Tracking data of people";
                    tb.AddForeignKeyColumn("PersonID", "Persons", false);
                    tb.AddColumn("Latitude", ColumnType.Double, false);
                    tb.AddColumn("Longitude", ColumnType.Double, false);
                });
            });

            var pddb = new PersonalDataDB(new InMemoryDataProvider());

            pddb.CreateDatabase(builder);
        }
        public void Insert_Administrator()
        {
            PersonalDataDB pddb = PddbTestingInstance.GetPddbInstanceForTesting();

            IAdministrator admin      = pddb.ListAdministrators().Single();
            object         newAdminId = pddb.InsertAdministrator(admin.ID, new AdministratorInsertModel("Karel Varel", "123456789", "*****@*****.**", null, null, null));

            var administrators = pddb.ListAdministrators();

            Assert.Equal(2, administrators.Count());

            Assert.Contains(administrators, t => t.ID.Equals(newAdminId));

            IAdministrator newAdmin = administrators.FirstOrDefault(t => t.ID.Equals(newAdminId));

            Assert.Equal("Karel Varel", newAdmin.FullName);
            Assert.Equal("123456789", newAdmin.Phone);
            Assert.Equal("*****@*****.**", newAdmin.Email);
        }
        public void List_DataManagers()
        {
            var            builder = PddbTestingInstance.GetFake();
            PersonalDataDB pddb    = new PersonalDataDB(new InMemoryDataProvider());

            pddb.CreateDatabase(builder);

            IEnumerable <IDataManager> dataManagers = pddb.ListDataManagers();

            Assert.NotEmpty(dataManagers);
            Assert.Single(dataManagers);

            IDataManager dataManager = dataManagers.Single();

            Assert.Equal(builder.DataManager !.Name, dataManager.Name);
            Assert.Equal(builder.DataManager !.Phone, dataManager.Phone);
            Assert.Equal(builder.DataManager !.Email, dataManager.Email);
            Assert.Equal(builder.DataManager !.RegistrationNumber, dataManager.RegistrationNumber);
            Assert.Equal(builder.DataManager !.PersonalDataRegistrationNumber, dataManager.PersonalDataRegistrationNumber);
        }
        public void Update_Administrator()
        {
            PersonalDataDB pddb  = PddbTestingInstance.GetPddbInstanceForTesting();
            IAdministrator admin = pddb.ListAdministrators().Single();

            pddb.UpdateAdministrator(admin.ID, new AdministratorUpdateModel(admin.ID, "999", "*****@*****.**", "666", "satan", "super"));

            var administrators = pddb.ListAdministrators();

            Assert.Single(administrators);

            admin = pddb.ListAdministrators().Single();

            Assert.Equal("Karel Admin", admin.FullName);
            Assert.Equal("999", admin.Phone);
            Assert.Equal("*****@*****.**", admin.Email);
            Assert.Equal("666", admin.OfficeNumber);
            Assert.Equal("satan", admin.InternalPhoneNumber);
            Assert.Equal("super", admin.Supervisor);
        }
        public void List_Administrators()
        {
            var            builder = PddbTestingInstance.GetFake();
            PersonalDataDB pddb    = new PersonalDataDB(new InMemoryDataProvider());

            pddb.CreateDatabase(builder);

            IEnumerable <IAdministrator> administrators = pddb.ListAdministrators();

            Assert.NotEmpty(administrators);
            Assert.Single(administrators);

            IAdministrator administrator = administrators.Single();

            Assert.Equal(builder.Administrator !.FullName, administrator.FullName);
            Assert.Equal(builder.Administrator !.Email, administrator.Email);
            Assert.Equal(builder.Administrator !.InternalPhoneNumber, administrator.InternalPhoneNumber);
            Assert.Equal(builder.Administrator !.OfficeNumber, administrator.OfficeNumber);
            Assert.Equal(builder.Administrator !.Phone, administrator.Phone);
            Assert.Equal(builder.Administrator !.Supervisor, administrator.Supervisor);
        }
Example #15
0
        public void Update_User()
        {
            PersonalDataDB pddb  = PddbTestingInstance.GetPddbInstanceForTesting();
            var            users = pddb.ListUsers();

            Assert.Empty(users);

            IAdministrator admin = pddb.ListAdministrators().Single();
            object         newId = pddb.InsertUser(admin.ID, new UserInsertModel("Karel", "123", "*****@*****.**", "5", "6", "Some Supervisor"));

            pddb.UpdateUser(admin.ID, new UserUpdateModel(newId, "99999", "*****@*****.**", null, null, null));

            var insertedUser = pddb.ListUsers().Single();

            Assert.Equal("Karel", insertedUser.FullName);
            Assert.Equal("99999", insertedUser.Phone);
            Assert.Equal("*****@*****.**", insertedUser.Email);
            Assert.Null(insertedUser.OfficeNumber);
            Assert.Null(insertedUser.InternalPhoneNumber);
            Assert.Null(insertedUser.Supervisor);
        }
Example #16
0
        public void List_And_Insert_Users()
        {
            PersonalDataDB pddb  = PddbTestingInstance.GetPddbInstanceForTesting();
            var            users = pddb.ListUsers();

            Assert.Empty(users);

            IAdministrator admin = pddb.ListAdministrators().Single();
            object         newId = pddb.InsertUser(admin.ID, new UserInsertModel("Karel", "123", "*****@*****.**", "5", "6", "Some Supervisor"));

            users = pddb.ListUsers();
            Assert.Single(users);
            Assert.Equal(newId, users.Single().ID);

            var insertedUser = users.Single();

            Assert.Equal("Karel", insertedUser.FullName);
            Assert.Equal("123", insertedUser.Phone);
            Assert.Equal("*****@*****.**", insertedUser.Email);
            Assert.Equal("5", insertedUser.OfficeNumber);
            Assert.Equal("6", insertedUser.InternalPhoneNumber);
            Assert.Equal("Some Supervisor", insertedUser.Supervisor);
        }