Exemple #1
0
        public void AddItemShouldAddBaggageAndReturnIdWhenOnAddItemEventIsRaised()
        {
            var type         = BaggageType.Cabin;
            var maxKilograms = 32;
            var size         = "test size";
            var price        = 1;
            var bookingId    = 1;

            var bagEventArgs = new BaggageManagementEventArgs()
            {
                Type         = type,
                MaxKilograms = maxKilograms,
                Size         = size,
                Price        = price,
                BookingId    = bookingId
            };

            this.baggageView.Raise(b => b.OnBaggageAddItem += null, bagEventArgs);

            var expectedId = 1;

            this.baggageServices.Verify(
                b => b.AddBaggage(
                    It.Is <Baggage>(m => m.Type == type && m.MaxKilograms == maxKilograms &&
                                    m.Size == size && m.Price == price && m.BookingId == bookingId)),
                Times.Once);

            Assert.AreEqual(expectedId, bagEventArgs.Id);
        }
Exemple #2
0
        private void View_OnBaggageUpdateItem(object sender, BaggageManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(BaggageManagementEventArgs));
            }

            var baggage = this.baggageServices.GetBaggage(e.Id);

            if (baggage == null)
            {
                this.View.ModelState.AddModelError(
                    ErrorMessages.MODEL_ERROR_KEY,
                    string.Format(ErrorMessages.MODEL_ERROR_MESSAGE, e.Id));

                return;
            }

            this.View.TryUpdateModel(baggage);

            if (this.View.ModelState.IsValid)
            {
                this.baggageServices.UpdateBaggage(e.Id, baggage);
            }
        }
        protected void CreateBaggageBtn_Click(object sender, EventArgs e)
        {
            decimal price = this.GetValidPrice();

            if (this.Page.IsValid && price != -1)
            {
                BaggageType type;
                bool        isValid = Enum.TryParse(this.BaggageTypeDropDownList.SelectedItem.Text, out type);

                if (!isValid)
                {
                    return;
                }

                var bagEventArgs = new BaggageManagementEventArgs()
                {
                    Type         = type,
                    MaxKilograms = int.Parse(this.MaxKilogramsTextBox.Text),
                    Size         = this.SizeTextBox.Text,
                    Price        = price,
                    BookingId    = int.Parse(this.BookingsDropDownList.SelectedItem.Value)
                };

                this.OnBaggageAddItem?.Invoke(sender, bagEventArgs);

                this.SuccessPanel.Visible   = true;
                this.AddedBagIdLiteral.Text = bagEventArgs.Id.ToString();

                this.ClearFields();
            }
        }
Exemple #4
0
        private void View_OnBaggageDeleteItem(object sender, BaggageManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(BaggageManagementEventArgs));
            }

            this.baggageServices.DeleteBaggage(e.Id);
        }
Exemple #5
0
        private void View_OnBaggageAddItem(object sender, BaggageManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(BaggageManagementEventArgs));
            }

            var bag = new Baggage()
            {
                Type         = e.Type,
                MaxKilograms = e.MaxKilograms,
                Size         = e.Size,
                Price        = e.Price,
                BookingId    = e.BookingId
            };

            e.Id = this.baggageServices.AddBaggage(bag);
        }