Exemple #1
0
        public async Task Put_PositiveTest(int id, Medicament medicament)
        {
            // Utworzenie kontekstu bazy danych.
            var dbContext = AppDbContextMocker.GetMemoryDbContext(nameof(Put_PositiveTest) + Guid.NewGuid());

            try
            {
                // Za³adowanie danych.
                dbContext.Medicaments_Positive_Put();

                // Utworzenie instancji kontrolera.
                var controller = new MedicamentsController(dbContext, new Logger <MedicamentsController>(new LoggerFactory()));

                try
                {
                    // Aktualizacja elementu.
                    await controller.Put(id, medicament);
                }
                catch
                {
                    // Assert.
                    Assert.Fail("Nie uda³o siê zaktualizowaæ danych elementu: '{0}'.", id);
                }
            }
            finally
            {
                // Zniszczenie kontekstu bazy danych.
                dbContext.Dispose();
            }
        }
Exemple #2
0
        public async Task Get_PositiveTest(int id)
        {
            // Utworzenie kontekstu bazy danych.
            var dbContext = AppDbContextMocker.GetMemoryDbContext(nameof(Get_PositiveTest) + Guid.NewGuid());

            try
            {
                // Za³adowanie danych.
                dbContext.Medicaments_Positive_Get();

                // Utworzenie instancji kontrolera.
                var controller = new MedicamentsController(dbContext, new Logger <MedicamentsController>(new LoggerFactory()));

                // Pobranie elementu o wskazanym ID.
                var response = await controller.Get(id);

                // Pobranie wyniku.
                var result = response.Value;

                // Assert.
                Assert.IsTrue(result != null, "Nie znaleziono elementu: '{0}'.", id);
            }
            finally
            {
                // Zniszczenie kontekstu bazy danych.
                dbContext.Dispose();
            }
        }
Exemple #3
0
        public async Task GetAll_PositiveTest(QueryMedicaments filter)
        {
            // Utworzenie kontekstu bazy danych.
            var dbContext = AppDbContextMocker.GetMemoryDbContext(nameof(GetAll_PositiveTest) + Guid.NewGuid());

            try
            {
                // Za³adowanie danych.
                dbContext.Medicaments_Positive_GetAll();

                // Utworzenie instancji kontrolera.
                var controller = new MedicamentsController(dbContext, new Logger <MedicamentsController>(new LoggerFactory()));

                // Pobranie elementów wed³ug filtra.
                var response = await controller.GetAll(filter);

                // Pobranie wyniku.
                var result = response.Value;

                // Assert.
                Assert.IsTrue(result.GetEnumerator().MoveNext(), "Lista powinna zawieraæ elementy.");
            }
            finally
            {
                // Zniszczenie kontekstu bazy danych.
                dbContext.Dispose();
            }
        }
Exemple #4
0
        public async Task Delete_PositiveTest(int id)
        {
            // Utworzenie kontekstu bazy danych.
            var dbContext = AppDbContextMocker.GetMemoryDbContext(nameof(Delete_PositiveTest) + Guid.NewGuid());

            try
            {
                // Za³adowanie danych.
                dbContext.Medicaments_Positive_Delete();

                // Utworzenie instancji kontrolera.
                var controller = new MedicamentsController(dbContext, new Logger <MedicamentsController>(new LoggerFactory()));

                // Usuniêcie elementu.
                await controller.Delete(id);

                // Pobranie elementu.
                var response = await controller.Get(id);

                var result = response.Value;

                // Assert.
                Assert.IsTrue(result == null, "Nie uda³o siê usun¹æ elementu: '{0}'.", id);
            }
            finally
            {
                // Zniszczenie kontekstu bazy danych.
                dbContext.Dispose();
            }
        }
Exemple #5
0
        public async Task Post_PositiveTest(Medicament medicament)
        {
            // Utworzenie kontekstu bazy danych.
            var dbContext = AppDbContextMocker.GetMemoryDbContext(nameof(Post_PositiveTest) + Guid.NewGuid());

            try
            {
                // Za³adowanie danych.
                dbContext.Medicaments_Positive_Post();

                // Utworzenie instancji kontrolera.
                var controller = new MedicamentsController(dbContext, new Logger <MedicamentsController>(new LoggerFactory()));

                // Dodanie elementu.
                var response = await controller.Post(medicament);

                // Pobranie wyniku.
                var result = (response.Result as CreatedAtActionResult).Value as Medicament;

                // Assert.
                Assert.IsTrue(result != null && result.IdMedicament > 0, "Nie uda³o siê dodaæ elementu: '{0}'.", medicament.Name);
            }
            finally
            {
                // Zniszczenie kontekstu bazy danych.
                dbContext.Dispose();
            }
        }
Exemple #6
0
        public async Task Put_NegativeTest(int id, Medicament medicament)
        {
            // Utworzenie kontekstu bazy danych.
            var dbContext = AppDbContextMocker.GetMemoryDbContext(nameof(Put_NegativeTest) + Guid.NewGuid());

            try
            {
                // Za³adowanie danych.
                dbContext.Medicaments_Negative_Put();

                // Utworzenie instancji kontrolera.
                var controller = new MedicamentsController(dbContext, new Logger <MedicamentsController>(new LoggerFactory()));

                try
                {
                    // Aktualizacja elementu.
                    var response = await controller.Put((int)id, medicament);

                    if (response is NoContentResult)
                    {
                        // Assert.
                        Assert.Fail("Uda³o siê zaktualizowaæ dane elementu: '{0}'.", id);
                    }
                }
                catch (AssertFailedException)
                {
                    throw;
                }
            }
            finally
            {
                // Zniszczenie kontekstu bazy danych.
                dbContext.Dispose();
            }
        }
        public DynamicMedicamentsTable(
            Size tableSize,
            Point tableLocation,
            List <Models.Medicament> medicaments,
            MedicamentsController controller
            )
        {
            // Init size; location; data source
            this.tableLocation = tableLocation;
            this.tableSize     = tableSize;
            this.medicaments   = medicaments;
            this.controller    = controller;

            // Init table
            Table = new DataTable();

            // Init datagrid
            DataGrid                     = new DataGridView();
            DataGrid.ReadOnly            = true;
            DataGrid.AllowUserToAddRows  = false;
            DataGrid.Size                = this.tableSize;
            DataGrid.Location            = this.tableLocation;
            DataGrid.RowTemplate.Height  = 40;
            DataGrid.ColumnHeadersHeight = 40;
            DataGrid.BackgroundColor     = Colors.ALTO;
            DataGrid.ColumnCount         = 5;
            DataGrid.Columns[0].Name     = "ID";
            DataGrid.Columns[1].Name     = "Emri";
            DataGrid.Columns[2].Name     = "Përshkrimi";
            DataGrid.Columns[3].Name     = "Data e skadencës";
            DataGrid.Columns[4].Name     = "Përbërësit";

            DataGrid.Columns[1].AutoSizeMode            = DataGridViewAutoSizeColumnMode.Fill;
            DataGrid.Columns[3].AutoSizeMode            = DataGridViewAutoSizeColumnMode.Fill;
            DataGrid.ColumnHeadersDefaultCellStyle.Font = new Font(Fonts.primary, 12, FontStyle.Bold);
            DataGrid.Font              = new Font(Fonts.primary, 12, FontStyle.Regular);
            DataGrid.AutoSizeRowsMode  = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            DataGrid.MultiSelect       = false;
            DataGrid.SelectionChanged += new EventHandler(onSelectionChanged);
        }
        public Medicaments(Panel previousPanel)
        {
            //Dimensions
            tableWidth                    = (int)(Dimensions.PANEL_WIDTH * 0.5);
            tableHeight                   = Dimensions.PANEL_HEIGHT - (Dimensions.NAV_BAR_HEIGHT + 40);
            rightPanelWidth               = (int)(Dimensions.PANEL_WIDTH * 0.4);
            formComponentKeyWidth         = (int)(0.4 * this.rightPanelWidth);
            formComponentValueWidth       = (int)(0.5 * this.rightPanelWidth);
            formComponentHorizontalMargin = (int)(0.1 * this.rightPanelWidth - 2 * Dimensions.PANEL_CARD_PADDING_HORIZONTAL);

            // Init previous panel
            this.PreviousPanel = previousPanel;

            // Init controller
            this.controller = new MedicamentsController(this);

            // Init panel
            this.Panel           = new Panel();
            this.Panel.AutoSize  = true;
            this.Panel.Location  = new Point(0, 0);
            this.Panel.Name      = "medicamentsMainPanel";
            this.Panel.Size      = new Size(Dimensions.PANEL_WIDTH, Dimensions.PANEL_HEIGHT);
            this.Panel.TabIndex  = 0;
            this.Panel.BackColor = Colors.WHITE;
            this.Panel.Visible   = false;

            // Init header
            this.header = new NavigationBar(
                Colors.BAHAMA_BLUE,
                "Menaxhimi i medikamenteve",
                this.Panel,
                this.PreviousPanel,
                "../../Resources/manager.png"
                );
            this.Panel.Controls.Add(this.header.Panel);

            // Medicaments table
            this.tableLocation = new Point(Dimensions.PANEL_PADDING_HORIZONTAL, 80);
            this.tableSize     = new Size(
                this.tableWidth,
                this.tableHeight
                );

            this.MedicamentsTable = new DynamicMedicamentsTable(
                this.tableSize,
                this.tableLocation,
                this.MedicamentsList,
                this.controller
                );
            this.Panel.Controls.Add(this.MedicamentsTable.DataGrid);

            // Init right container
            right          = new GroupBox();
            right.Text     = "Shtimi dhe përditësimi i medikamenteve";
            right.Location = new Point(
                Dimensions.PANEL_WIDTH - (Dimensions.PANEL_PADDING_HORIZONTAL + this.rightPanelWidth),
                80
                );
            right.Size      = new Size(this.rightPanelWidth, this.tableHeight);
            right.FlatStyle = FlatStyle.Flat;
            right.Font      = new Font(Fonts.primary, 12, FontStyle.Regular);
            this.Panel.Controls.Add(this.right);

            // Selected medicament label
            this.medicamentsLabel          = new Label();
            this.medicamentsLabel.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL,
                Dimensions.PANEL_CARD_PADDING_VERTICAL * 2
                );
            this.medicamentsLabel.Width     = this.formComponentKeyWidth;
            this.medicamentsLabel.Height    = this.formComponentHeight;
            this.medicamentsLabel.Text      = "Medikamenti";
            this.medicamentsLabel.Font      = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.medicamentsLabel.ForeColor = Colors.BLACK;
            this.right.Controls.Add(this.medicamentsLabel);

            this.MedicamentLabelValue          = new Label();
            this.MedicamentLabelValue.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL + this.formComponentKeyWidth + this.formComponentHorizontalMargin,
                Dimensions.PANEL_CARD_PADDING_VERTICAL * 2
                );
            this.MedicamentLabelValue.Width     = this.formComponentValueWidth;
            this.MedicamentLabelValue.Height    = this.formComponentHeight;
            this.MedicamentLabelValue.Text      = this.SelectedMedicament != null ? this.SelectedMedicament : "-";
            this.MedicamentLabelValue.Font      = new Font(Fonts.primary, 12, FontStyle.Regular);
            this.MedicamentLabelValue.ForeColor = Colors.BLACK;
            this.right.Controls.Add(this.MedicamentLabelValue);

            /* Init form components */

            // Medicament name
            this.nameLabel          = new Label();
            this.nameLabel.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL,
                (2 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.nameLabel.Width     = this.formComponentKeyWidth;
            this.nameLabel.Height    = this.formComponentHeight;
            this.nameLabel.Text      = "Emri";
            this.nameLabel.Font      = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.nameLabel.ForeColor = Colors.BLACK;
            this.right.Controls.Add(this.nameLabel);

            this.NameTxtBox          = new TextBox();
            this.NameTxtBox.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL + this.formComponentKeyWidth + this.formComponentHorizontalMargin,
                (2 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.NameTxtBox.Width  = this.formComponentValueWidth;
            this.NameTxtBox.Height = this.formComponentHeight;
            this.NameTxtBox.Font   = new Font(Fonts.primary, 12, FontStyle.Regular);
            this.right.Controls.Add(this.NameTxtBox);

            // Medicament description
            this.descriptionLabel          = new Label();
            this.descriptionLabel.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL,
                (3 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.descriptionLabel.Width     = this.formComponentKeyWidth;
            this.descriptionLabel.Height    = this.formComponentHeight;
            this.descriptionLabel.Text      = "Përshkrimi";
            this.descriptionLabel.Font      = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.descriptionLabel.ForeColor = Colors.BLACK;
            this.right.Controls.Add(this.descriptionLabel);

            this.DescriptionTxtBox          = new TextBox();
            this.DescriptionTxtBox.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL + this.formComponentKeyWidth + this.formComponentHorizontalMargin,
                (3 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.DescriptionTxtBox.Width     = this.formComponentValueWidth;
            this.DescriptionTxtBox.Height    = (int)(3 * this.formComponentHeight);
            this.DescriptionTxtBox.Font      = new Font(Fonts.primary, 12, FontStyle.Regular);
            this.DescriptionTxtBox.Multiline = true;
            this.right.Controls.Add(this.DescriptionTxtBox);

            // Expiration Date
            this.expirationDateLabel          = new Label();
            this.expirationDateLabel.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL,
                (6 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.expirationDateLabel.Width     = this.formComponentKeyWidth;
            this.expirationDateLabel.Height    = this.formComponentHeight;
            this.expirationDateLabel.Text      = "Data e skadencës";
            this.expirationDateLabel.Font      = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.expirationDateLabel.ForeColor = Colors.BLACK;
            this.right.Controls.Add(this.expirationDateLabel);

            this.ExpirationDatePicker          = new DateTimePicker();
            this.ExpirationDatePicker.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL + this.formComponentKeyWidth + this.formComponentHorizontalMargin,
                (6 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.ExpirationDatePicker.Width  = this.formComponentValueWidth;
            this.ExpirationDatePicker.Height = this.formComponentHeight;
            this.ExpirationDatePicker.Font   = new Font(Fonts.primary, 12, FontStyle.Regular);
            this.right.Controls.Add(this.ExpirationDatePicker);

            // Ingredients
            this.ingredientsLabel          = new Label();
            this.ingredientsLabel.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL,
                (7 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.ingredientsLabel.Width     = this.formComponentKeyWidth;
            this.ingredientsLabel.Height    = this.formComponentHeight;
            this.ingredientsLabel.Text      = "Përbërësit";
            this.ingredientsLabel.Font      = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.ingredientsLabel.ForeColor = Colors.BLACK;
            this.right.Controls.Add(this.ingredientsLabel);

            this.IngredientsTxtBox          = new TextBox();
            this.IngredientsTxtBox.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL + this.formComponentKeyWidth + this.formComponentHorizontalMargin,
                (7 * this.formComponentVerticalMargin) + (Dimensions.PANEL_CARD_PADDING_VERTICAL * 2)
                );
            this.IngredientsTxtBox.Width     = this.formComponentValueWidth;
            this.IngredientsTxtBox.Height    = (int)(3 * this.formComponentHeight);
            this.IngredientsTxtBox.Font      = new Font(Fonts.primary, 12, FontStyle.Regular);
            this.IngredientsTxtBox.Multiline = true;
            this.right.Controls.Add(this.IngredientsTxtBox);

            /* Buttons */

            this.resetBtn          = new Button();
            this.resetBtn.Size     = new Size(this.formComponentKeyWidth, this.formComponentHeight);
            this.resetBtn.Location = new Point(
                Dimensions.PANEL_CARD_PADDING_HORIZONTAL,
                this.tableHeight - (Dimensions.PANEL_CARD_PADDING_VERTICAL + this.formComponentHeight)
                );
            this.resetBtn.Text = "RESET";
            this.resetBtn.UseVisualStyleBackColor = true;
            this.resetBtn.Font       = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.resetBtn.ForeColor  = Colors.WHITE;
            this.resetBtn.BackColor  = Colors.IMPERIAL_RED;
            this.resetBtn.FlatStyle  = FlatStyle.Flat;
            this.resetBtn.Click     += new EventHandler(onResetButtonClicked);
            this.resetBtn.Image      = Image.FromFile("../../Resources/clear.png");
            this.resetBtn.ImageAlign = ContentAlignment.MiddleLeft;
            this.right.Controls.Add(this.resetBtn);

            this.submitBtn          = new Button();
            this.submitBtn.Size     = new Size(this.formComponentKeyWidth, this.formComponentHeight);
            this.submitBtn.Location = new Point(
                this.rightPanelWidth - (this.formComponentKeyWidth + Dimensions.PANEL_CARD_PADDING_HORIZONTAL),
                this.tableHeight - (Dimensions.PANEL_CARD_PADDING_VERTICAL + this.formComponentHeight)
                );
            this.submitBtn.Text = "RUAJ";
            this.submitBtn.UseVisualStyleBackColor = true;
            this.submitBtn.Font       = new Font(Fonts.primary, 12, FontStyle.Bold);
            this.submitBtn.ForeColor  = Colors.WHITE;
            this.submitBtn.BackColor  = Colors.MALACHITE;
            this.submitBtn.FlatStyle  = FlatStyle.Flat;
            this.submitBtn.Click     += new EventHandler(onSubmitButtonClicked);
            this.submitBtn.Image      = Image.FromFile("../../Resources/save.png");
            this.submitBtn.ImageAlign = ContentAlignment.MiddleLeft;
            this.right.Controls.Add(this.submitBtn);
        }