public void DeleteOfferWithGivenId_WhenExecuted()
        {
            // Arrange
            var mockedContext          = new Mock <IMotorSystemContext>();
            var offerInputProviderMock = new Mock <IOfferInputProvider>();
            int idToDelete             = 3;

            var data = new List <Offer>
            {
                new Offer()
                {
                    Id = idToDelete
                }
            };

            var mockSet = Helpers.GetQueryableMockDbSet(data);

            //mockedOffersDbSet.Object.Add(offerToDelete);

            mockedContext.SetupGet(c => c.Offers)
            .Returns(mockSet.Object);

            offerInputProviderMock.Setup(i => i.RemoveOfferInput())
            .Returns(new List <string> {
                idToDelete.ToString()
            });

            var deleteOfferCommand = new DeleteOfferCommand(mockedContext.Object, offerInputProviderMock.Object);

            // Act
            string result = deleteOfferCommand.Execute();

            // Assert
            mockedContext.Verify(c => c.SaveChanges(), Times.Once);
        }
Beispiel #2
0
        protected void off_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            ImageButton action       = (ImageButton)e.CommandSource;
            string      actionString = action.ID;

            if (action.ID.Equals("delete"))
            {
                try
                {
                    Offer  offer = new Offer();
                    string id    = ((Label)off_data.Items[e.Item.ItemIndex].FindControl("Id")).Text;
                    offer.Id = Int32.Parse(id);
                    DeleteOfferCommand cmd = new DeleteOfferCommand(offer);
                    cmd.Execute();
                    if (offer.Code == 200)
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true);
                    }
                    else
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertmeErr()", true);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else if (action.ID.Equals("modify"))
            {
                try
                {
                    string id = ((Label)off_data.Items[e.Item.ItemIndex].FindControl("Id")).Text;
                    Session["Id_off"] = id;
                    Response.Redirect("/site/admin/adm_offert/Edit_offert.aspx");
                }
                catch (Exception ex)
                {
                }
            }
        }