Esempio n. 1
0
        public void Get_TestClassObjectPassed_ProperMethodCalled()
        {
            var options = new DbContextOptionsBuilder <DevTestContext>().UseInMemoryDatabase(databaseName: "Payments Test")
                          .Options;

            using (var context = new DevTestContext(options))
            {
                context.Payment.Add(new Payment {
                    ID = 1, Amount = 100, PaymentDate = System.DateTime.Now, AccountID = 2
                });
                context.SaveChanges();
            }
            using (var context = new DevTestContext(options))
            {
                //Arrange
                var repo = new Repository <Payment>(context);

                //method

                var payment = repo.GetById(x => x.ID == 1);


                Assert.Equal(1, payment.ID);
            }
        }
Esempio n. 2
0
        public JsonResult DeleteData(int id)
        {
            string msg = "";

            try
            {
                using (DevTestContext context = new DevTestContext())
                {
                    var data = context.DevTests.FirstOrDefault(d => d.ID == id);
                    context.DevTests.Remove(data);
                    context.SaveChanges();
                    msg = "Data Deleted Successfully..";
                }
                DevTestHub.NotifyCurrentDevInformationToAllClients();
            }
            catch (Exception cc)
            {
                msg = "Error Occur";
            }

            var jsonresult = new
            {
                msg = msg
            };

            return(Json(jsonresult));
        }
Esempio n. 3
0
        public ActionResult Create(Character model)
        {
            if (ModelState.IsValid)
            {
                using (var ctx = new DevTestContext())
                {
                    model.CharacterId = Guid.NewGuid();
                    model.DateAdded   = DateTime.Now;

                    ctx.Characters.Add(model);
                    ctx.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 4
0
        public JsonResult InsertData(DevTest model)
        {
            string msg = "";

            try {
                using (DevTestContext context = new DevTestContext())
                {
                    if (model.ID > 0)
                    {
                        var data = context.DevTests.FirstOrDefault(d => d.ID == model.ID);
                        data.Clicks        = model.Clicks;
                        data.AffiliateName = model.AffiliateName;
                        data.CampaignName  = model.CampaignName;
                        data.Conversions   = model.Conversions;
                        data.Date          = model.Date;
                        data.Impressions   = model.Impressions;
                    }
                    else
                    {
                        context.DevTests.Add(model);
                    }
                    context.SaveChanges();
                    msg = "Data Saved Successfully..";
                }
                DevTestHub.NotifyCurrentDevInformationToAllClients();
            }
            catch (Exception cc)
            {
                msg = "Error Occur";
            }

            var jsonresult = new
            {
                msg = msg
            };

            return(Json(jsonresult));
        }
Esempio n. 5
0
 public void Commit()
 {
     context.SaveChanges();
 }