public void IsDeletingPrisoner()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_Delete_Prisoner_database")
                          .Options;


            var appDbContext = new AppDbContext(options);
            var user         = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "abcd"),
            }));

            appDbContext.UserPermissions.Add(new UserPermission
            {
                Id       = 1,
                UserName = "******",
                IdPrison = 1,
                Prison   = new Prison
                {
                    Id         = 1,
                    PrisonName = "prison_test"
                }
            });
            appDbContext.SaveChanges();
            var prisonerRepository = new PrisonerRepository(appDbContext);
            var prisonerService    = new PrisonerService(prisonerRepository);
            var loggerRepository   = new LoggerRepository(appDbContext);
            var loggerService      = new LoggerService(loggerRepository);
            var prisonerController = new PrisonerController(prisonerService, _mapper, loggerService)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext {
                        User = user
                    }
                }
            };


            prisonerController.AddPrisoner(new PrisonerDTO
            {
                Name     = "abc",
                Forname  = "dba",
                Pesel    = "12345678910",
                Address  = "null",
                Pass     = false,
                Behavior = 0,
                Isolated = false,
                IdCell   = 0
            });

            Assert.AreEqual(appDbContext.Prisoners.Count(), 1, "prisoner has not been added");
            prisonerController.DeletePrisoner(1);
            Assert.AreEqual(appDbContext.Prisoners.Count(), 0, "prisoner has not been deleted");
        }
Exemple #2
0
        private void releaseButton_Click(object sender, EventArgs e)
        {
            prisn = new PrisonerService();
            int result = prisn.deletePrisoner(textBox1.Text);

            if (result > 0)
            {
                MessageBox.Show("Deleted Successfully");
                UpdateGridView();
            }
            else
            {
                MessageBox.Show("Error");
            }
        }
Exemple #3
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "")
            {
                MessageBox.Show("You have to Fill Up the Form First");
            }
            else
            {
                prisn = new PrisonerService();

                int result = prisn.savePrisoner(Convert.ToInt32(textBox1.Text), textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, Convert.ToInt32(textBox6.Text), textBox7.Text);

                if (result > 0)
                {
                    MessageBox.Show("User registration successfull.");
                }
                else
                {
                    MessageBox.Show("Error");
                }
            }
        }
        public void IsSelectingRightPrisoner()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_Select_Prisoner_database")
                          .Options;


            var appDbContext       = new AppDbContext(options);
            var prisonerRepository = new PrisonerRepository(appDbContext);
            var prisonerService    = new PrisonerService(prisonerRepository);
            var loggerRepository   = new LoggerRepository(appDbContext);
            var loggerService      = new LoggerService(loggerRepository);
            var prisonerController = new PrisonerController(prisonerService, _mapper, loggerService);


            appDbContext.Prisoners.Add(new Prisoner
            {
                Id          = 0,
                Name        = null,
                Forname     = null,
                Pesel       = null,
                Address     = null,
                Pass        = false,
                Behavior    = 0,
                Isolated    = false,
                IdCell      = 0,
                Cell        = null,
                Isolations  = null,
                Punishments = null
            });
            appDbContext.SaveChanges();

            Assert.AreEqual(appDbContext.Prisoners.Count(), 1, "prisoner has not been added");
            Assert.IsNotNull(prisonerController.SelectedPrisoner(1));

            // Assert.AreEqual(appDbContext.Prisoners.FirstOrDefault(x => x.Id == 1),prisonerController.SelectedPrisoner(1).Value);//rip c#7, gonna be fixed in c#8
        }
Exemple #5
0
 private void GetAllbutton1_Click(object sender, EventArgs e)
 {
     ps = new PrisonerService();
     dataGridView1.DataSource = ps.getAllPrisoner();
 }
Exemple #6
0
 private void loadButton_Click(object sender, EventArgs e)
 {
     prisn = new PrisonerService();
     dataGridView1.DataSource = prisn.getAllPrisoner();
 }