protected void Page_Load(object sender, EventArgs e)
        {
            var departmentsID = Request.QueryString["ID"];

            if (!IsPostBack && departmentsID == null)
            {
                ddlInstructorID.DataSource     = Utility.Utility.GetAllInstructor();
                ddlInstructorID.DataTextField  = "ID";
                ddlInstructorID.DataValueField = "ID";
                ddlInstructorID.DataBind();
            }
            if (!IsPostBack && departmentsID != null)
            {
                ddlInstructorID.DataSource     = Utility.Utility.GetAllInstructor();
                ddlInstructorID.DataTextField  = "ID";
                ddlInstructorID.DataValueField = "ID";
                ddlInstructorID.DataBind();
                DepartmentsService departmentsService = new DepartmentsService();
                var departments = departmentsService.GetOneDepartments(Convert.ToInt32(departmentsID));
                departments.ID                = Convert.ToInt32(departmentsID);
                txtName.Text                  = departments.Name.Trim();
                txtBudget.Text                = departments.Budget.ToString();
                txtStartDate.Text             = departments.StartDate.ToString();
                ddlInstructorID.SelectedValue = departments.InstructorID.ToString();
                txtRowVersion.Text            = departments.RowVersion.ToString();
                txtCreatedDate.Text           = departments.CreatedDate.ToString();
                txtCreatedBy.Text             = departments.CreatedBy.Trim();
                txtUpdatedDate.Text           = departments.UpdatedDate.ToString();
                txtUpdatedBy.Text             = departments.UpdatedBy.Trim();
            }
        }
        public void TestGetOneNonExisting()
        {
            DepartmentsService service    = CreateService();
            Department         department = service.Get(3);

            // The service must return default(Department) == null when the department is not found.
            Assert.Null(department);
        }
Exemple #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         DepartmentsService departmentsService = new DepartmentsService();
         repeaterDepartments.DataSource = departmentsService.GetAllDepartments();
         repeaterDepartments.DataBind();
     }
 }
        public DepartmentsServiceTests()
        {
            long Id = singleEntity.Id;

            Mock    = DefaultContextMock.GetMock();
            MockSet = SetUpMock.SetUpFor(testEntities);
            Mock.Setup(c => c.Set <Department>()).Returns(MockSet.Object);
            Mock.Setup(c => c.Department).Returns(MockSet.Object);
            testedService = new DepartmentsService(Mock.Object);
        }
        public void TestGetAll()
        {
            DepartmentsService       service     = CreateService();
            IEnumerable <Department> departments = service.GetAll();

            // The service must always return a collection, even when empty.
            Assert.NotNull(departments);

            // The service must return two items according to test configuration.
            Assert.Equal(2, departments.Count());
        }
        public void TestGetAllEmpty()
        {
            // Parameter named to avoid confusion.
            DepartmentsService       service     = CreateService(empty: true);
            IEnumerable <Department> departments = service.GetAll();

            // The service must always return a collection, even when empty.
            Assert.NotNull(departments);

            // The service must return no items according to test configuration.
            Assert.Empty(departments);
        }
        /// <summary>
        /// Controller Initialization
        /// </summary>
        /// <param name="emptyEmployees">Creates a context without any departments</param>
        /// <returns></returns>
        private EmployeesController CreateController(bool emptyDepartments = false, bool emptyEmployees = false, [CallerMemberName] string databaseName = "")
        {
            IHost host = Host.CreateDefaultBuilder().Build();
            ILogger <EmployeesController> logger = host.Services.GetRequiredService <ILogger <EmployeesController> >();

            DbContextOptions <VogContext> contextOptions = new DbContextOptionsBuilder <VogContext>().UseInMemoryDatabase(databaseName: databaseName).Options;

            VogContext context = new VogContext(contextOptions);

            if (!emptyDepartments)
            {
                context.Departments.Add(new Department {
                    Id = 1, Name = "Ecology Department", Address = "1865 Reserve St Campbellford, ON K0L 1L0"
                });
                context.Departments.Add(new Department {
                    Id = 2, Name = "Construction Department", Address = "2635 Hammarskjold Dr Burnaby, BC V5B 3C9"
                });
                context.SaveChanges();
            }

            if (!emptyEmployees)
            {
                context.Employees.Add(new Employee {
                    Id = 1, DepartmentId = 1, FirstName = "Dan", LastName = "Loden", JobTitle = "Nature Inspector", MailingAddress = "4652 Bates Brothers Road Hilliard, OH 43026"
                });
                context.Employees.Add(new Employee {
                    Id = 2, DepartmentId = 1, FirstName = "Jennifer", LastName = "Evans", JobTitle = "Range Ecologist", MailingAddress = "4278 Walnut Avenue Newark, NJ 07102"
                });
                context.Employees.Add(new Employee {
                    Id = 3, DepartmentId = 2, FirstName = "Teresa", LastName = "Hill", JobTitle = "Construction Equipment Technician", MailingAddress = "3789 Cook Hill Road Stamford, CT 06995"
                });
                context.Employees.Add(new Employee {
                    Id = 4, DepartmentId = 2, FirstName = "Shane", LastName = "Headrick", JobTitle = "Construction Equipment Operator", MailingAddress = "1020 Yoho Valley Road Golden, BC V0A 1H0"
                });
                context.SaveChanges();
            }

            DepartmentsRepository departmentsRepository = new DepartmentsRepository(context);
            DepartmentsService    departmentsService    = new DepartmentsService(departmentsRepository);

            EmployeesRepository employeesRepository = new EmployeesRepository(context);
            EmployeesService    employeesService    = new EmployeesService(employeesRepository);

            return(new EmployeesController(logger, employeesService, departmentsService));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var departmentsID = Request.QueryString["ID"];
         DepartmentsService departmentsService = new DepartmentsService();
         var departments = departmentsService.GetOneDepartments(Convert.ToInt32(departmentsID));
         NameLabel.Text         = departments.Name;
         BudgetLabel.Text       = departments.Budget.ToString();
         StartDateLabel.Text    = departments.StartDate.ToString();
         InstructorIDLabel.Text = departments.InstructorID.ToString();
         RowVersionLabel.Text   = departments.RowVersion.ToString();
         CreatedDateLabel.Text  = departments.CreatedDate.ToString();
         CreatedByLabel.Text    = departments.CreatedBy;
         UpdatedDateLabel.Text  = departments.UpdatedDate.ToString();
         UpdatedByLabel.Text    = departments.UpdatedBy;
     }
 }
Exemple #9
0
        protected void repeaterDepartments_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            var departmentsID = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "edit")
            {
                Response.Redirect("AddDepartments.aspx?id=" + departmentsID);
            }
            if (e.CommandName == "delete")
            {
                DepartmentsService departmentsService = new DepartmentsService();
                departmentsService.DeleteDepartments(Convert.ToInt32(departmentsID));
                Response.Redirect("ListDepartments.aspx");
            }
            if (e.CommandName == "details")
            {
                Response.Redirect("DetailsDepartments.aspx?id=" + departmentsID);
            }
        }
        public void TestGetOneExisting()
        {
            DepartmentsService service     = CreateService();
            Department         department1 = service.Get(1);

            // The service must find this item.
            Assert.NotNull(department1);

            // Checks if the service is returning the proper item.
            Assert.Equal(1, department1.Id);
            Assert.Equal("Ecology Department", department1.Name);
            Assert.Equal("1865 Reserve St Campbellford, ON K0L 1L0", department1.Address);

            // Second check to verify if the service is correctly considering the Id on search.
            Department department2 = service.Get(2);

            Assert.NotNull(department2);
            Assert.Equal(2, department2.Id);
            Assert.Equal("Construction Department", department2.Name);
            Assert.Equal("2635 Hammarskjold Dr Burnaby, BC V5B 3C9", department2.Address);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var departmentsID = Request.QueryString["ID"];

            if (departmentsID == null)
            {
                Contoso.Models.Departments departments = new Contoso.Models.Departments();
                departments.Name         = txtName.Text;
                departments.Budget       = Convert.ToDouble(txtBudget.Text);
                departments.StartDate    = Convert.ToDateTime(txtStartDate.Text);
                departments.InstructorID = Convert.ToInt32(ddlInstructorID.SelectedValue);
                departments.RowVersion   = Convert.ToInt32(txtRowVersion.Text);
                departments.CreatedDate  = Convert.ToDateTime(txtCreatedDate.Text);
                departments.CreatedBy    = txtCreatedBy.Text;
                departments.UpdatedDate  = Convert.ToDateTime(txtUpdatedDate.Text);
                departments.UpdatedBy    = txtUpdatedBy.Text;

                DepartmentsService departmentsService = new DepartmentsService();
                departmentsService.AddDepartments(departments);
            }
            if (departmentsID != null)
            {
                Contoso.Models.Departments departments = new Models.Departments();
                departments.ID           = Convert.ToInt32(departmentsID);
                departments.Name         = txtName.Text;
                departments.Budget       = Convert.ToDouble(txtBudget.Text);
                departments.StartDate    = Convert.ToDateTime(txtStartDate.Text);
                departments.InstructorID = Convert.ToInt32(ddlInstructorID.SelectedValue);
                departments.RowVersion   = Convert.ToInt32(txtRowVersion.Text);
                departments.CreatedDate  = Convert.ToDateTime(txtCreatedDate.Text);
                departments.CreatedBy    = txtCreatedBy.Text;
                departments.UpdatedDate  = Convert.ToDateTime(txtUpdatedDate.Text);
                departments.UpdatedBy    = txtUpdatedBy.Text;
                DepartmentsService departmentsService = new DepartmentsService();
                departmentsService.UpdateDepartments(departments);
            }
        }
Exemple #12
0
 public DepartmentsController(DepartmentsService departmentsService)
 {
     _departmentsService = departmentsService;
 }
Exemple #13
0
 public SellersController(SellerService sellerService, DepartmentsService departmentService)
 {
     _sellerService     = sellerService;
     _departmentService = departmentService;
 }
Exemple #14
0
 public DepartmentsController(IRepository <Department> repository, DepartmentsService service)
 {
     _repository = repository ?? throw new ArgumentNullException(nameof(repository));
     _service    = service ?? throw new ArgumentNullException(nameof(service));
 }
Exemple #15
0
        public static List <Departments> GetAllDepartments()
        {
            DepartmentsService departmentsService = new DepartmentsService();

            return(departmentsService.GetAllDepartments());
        }