Пример #1
2
        public void Members_check_arguments()
        {
            Assert.Equal(
                "context",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => new DbSet<Random>(null)).ParamName);

            var set = new DbSet<Random>(new Mock<DbContext>().Object);

            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => set.Add(null)).ParamName);
            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.ThrowsAsync<ArgumentNullException>(() => set.AddAsync(null)).Result.ParamName);
            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(
                    () => set.AddAsync(null, new CancellationToken()).GetAwaiter().GetResult()).ParamName);

            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.Throws<ArgumentNullException>(() => set.Update(null)).ParamName);
            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.ThrowsAsync<ArgumentNullException>(() => set.UpdateAsync(null)).Result.ParamName);
            Assert.Equal(
                "entity",
                // ReSharper disable once AssignNullToNotNullAttribute
                Assert.ThrowsAsync<ArgumentNullException>(() => set.UpdateAsync(null, new CancellationToken())).Result.ParamName);
        }
Пример #2
0
        public Boolean Add <TModel>(TModel model)
            where TModel : LogicalModelBase
        {
            DbSet set = Set(model.Entity.GetType());

            set?.Add(model.Entity);
            return(SaveChanges() == 1);
        }
Пример #3
0
 public void Add(TEntityBase entity)
 {
     if (entity.Id != default(Guid))
     {
         return;
     }
     entity.Id = Guid.NewGuid();
     _dbSet?.Add(entity);
 }
Пример #4
0
            public void With_valid_entity_returns_the_added_entity()
            {
                var set = new DbSet<FakeEntity>(new Mock<InternalSetForMock<FakeEntity>>().Object);
                var entity = new FakeEntity();

                var retVal = set.Add(entity);

                Assert.Same(entity, retVal);
            }
 public static IEnumerable<Exchange> RetrieveAndPopulateExchanges(IEnumerable<DateTime> datesToRetrieve, string targetCurrencyCode, DbSet<Exchange> exchangesDbSet)
 {
     var retrievedExchanges = Enumerable.Empty<Exchange>();
     foreach (var dateToProcess in datesToRetrieve)
     {
         IEnumerable<Exchange> exchangesOfDate;
         try
         {
             try
             {
                 exchangesOfDate = RequestDefaultExternalResource(dateToProcess, targetCurrencyCode);
             }
             catch (ExchangeResource.ResourceBrokageException rbEx)
             {
                 throw new ExchangeResource.NotifyResourceMaintainer("The resource is broken or violates protocol.", rbEx);
             }
             catch (ExchangeResource.BaseException)
             {
                 throw;
             }
             catch (Exception ex)
             {
                 var erEx = new ExchangeResource.NotifyResourceDeveloper(ex);
                 erEx.AddFailedDate(dateToProcess);
                 throw erEx;
             }
         }
         catch (ExchangeResource.BaseException resEx)
         {
             var triedDates = retrievedExchanges.Select(e => e.Date).Concat(resEx.GetFailedDates());
             var untouchedDates = datesToRetrieve.Except(triedDates);
             resEx.AddUntouchedDates(untouchedDates);
             throw;
         }
         foreach (var exchange in exchangesOfDate)
             exchangesDbSet.Add(exchange); // TODO: dangerous if given exchange is in the DB already. `SaveChanges` will fail (and drop other changes?).
         Trace.WriteLine("Database is populated with "+exchangesOfDate.Count()+" entries for date "+dateToProcess.ToString("yyyy-MM-dd")+".");
         retrievedExchanges = retrievedExchanges.Concat(exchangesOfDate);
         var targetExchanges = exchangesOfDate.Where(ex => ex.CurrencyCode == targetCurrencyCode);
         if (targetExchanges.Count() == 0)
         {
             var resEx = new ExchangeResource.TryRequestingOtherDatesOrCurrency(
                 String.Format(
                     "No rates for currency code {0} on {1}.",
                     targetCurrencyCode,
                     dateToProcess.ToString("yyyy-MM-dd")
                 )
             );
             resEx.AddFailedDate(dateToProcess);
             throw resEx;
         }
     }
     return retrievedExchanges;
 }
Пример #6
0
        //var groups = scenario.ScenarioGroups;
        //var sc = scenario.Scenarios;
        //DateTime now = DateTime.UtcNow;
        //        try
        //        {
        //            AddGroups1(groups, now);
        //scenario.SaveChanges();
        //            AddGroups2(groups, now);
        //scenario.SaveChanges();
        //            //AddScenarios(sc, now);
        //        }
        //        catch (DbEntityValidationException dbEx)
        //        {
        //            foreach (var validationErrors in dbEx.EntityValidationErrors)
        //            {
        //                Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", validationErrors.Entry.Entity.GetType().Name, validationErrors.Entry.State);
        //                foreach (var validationError in validationErrors.ValidationErrors)
        //                {
        //                    Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
        //                }
        //            }
        //        }
        //        Console.WriteLine("*****Scenario Group List*****");
        //        foreach (ScenarioGroup item in groups)
        //        {
        //            Console.WriteLine(item.ScenarioGroupID);
        //            foreach (ScenarioGroupDetail item2 in item.ScenarioGroupDetails)
        //            {
        //                Console.WriteLine(item2.ScenarioGroupDetailID + " " + item2.Name);
        //            }
        //        }
        static void AddGroups1(DbSet<ScenarioGroup> root, DateTime now)
        {
            ScenarioGroup sg = new ScenarioGroup();
            sg.StartTime = now.AddDays(-100);
            sg.EndTime = DateTime.MaxValue;
            sg.CreatedBy = "me";
            sg.CreatedAt = now;
            root.Add(sg);

            ScenarioGroupDetail sgd = new ScenarioGroupDetail();
            sgd.Name = "Test 2-1";
            sgd.StartTime = now.AddDays(-100);
            sgd.EndTime = now.AddDays(-50);
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now.AddDays(-50);
            //sgd.ScenarioGroup = sg;
            sg.ScenarioGroupDetails.Add(sgd);

            sgd = new ScenarioGroupDetail();
            sgd.Name = "Test 2-2";
            sgd.StartTime = now.AddDays(-50);
            sgd.EndTime = now.AddDays(-20);
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now.AddDays(-20);
            //sgd.ScenarioGroup = sg;
            sg.ScenarioGroupDetails.Add(sgd);

            sgd = new ScenarioGroupDetail();
            sgd.Name = "Test 2-3";
            sgd.StartTime = now.AddDays(-20);
            sgd.EndTime = DateTime.MaxValue;
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now.AddDays(-20);
            //sgd.ScenarioGroup = sg;
            sg.ScenarioGroupDetails.Add(sgd);
        }
Пример #7
0
        public TEntity Insert(TEntity entity)
        {
            var result = _dbSet.Add(entity).Entity;

            return(result);
        }
Пример #8
0
 public void Create(T entity)
 {
     DbSet.Add(entity);
 }
 public void Insert(T entity)
 {
     table.Add(entity);
 }
Пример #10
0
 public void Add(T entity)
 {
     dbSet.Add(entity);
 }
Пример #11
0
 public void Add(TEntity entity)
 {
     //Context.Set<TEntity>().Add(entity);
     _dbSet.Add(entity);
 }
Пример #12
0
 public Task AddResultAsync(QuestionResult questionResult)
 {
     questionResultsDataSet.Add(questionResult);
     return(dbContext.SaveChangesAsync());
 }
Пример #13
0
 public T Insert(T entity)
 {
     return(_dbSet.Add(entity));
 }
Пример #14
0
 public void Insert(T p)
 {
     _object.Add(p);
     c.SaveChanges();
 }
 public void Add(Models.ProjectEmployee pe)
 {
     _projectEmployees.Add(pe);
 }
Пример #16
0
 public void Adicionar(T entity)
 {
     _set.Add(entity);
 }
Пример #17
0
 public virtual async Task Adicionar(TEntity entity)
 {
     DbSet.Add(entity);
     await SaveChanges();
 }
Пример #18
0
 public Task AddUserAsync(User user)
 {
     DbSet.Add(user);
     return(Task.CompletedTask);
 }
Пример #19
0
 public void Insert(Category category)
 {
     _category.Add(category);
     context.SaveChanges();
 }
Пример #20
0
 public Task AddResultAnswerAsync(QuestionResultAnswers questionResultAnswer)
 {
     questionResultAnswersDataSet.Add(questionResultAnswer);
     return(dbContext.SaveChangesAsync());
 }
Пример #21
0
 public void Add(T entity)
 {
     _object.Add(entity);
     context.SaveChanges();
 }
        public virtual TEntity Adicionar(TEntity obj)
        {
            var objreturn = DbSet.Add(obj);

            return(objreturn);
        }
Пример #23
0
 public virtual void Add(T entity)
 {
     _dbSet.Add(entity);
 }
Пример #24
0
 public void Insert(T item) => Set.Add(item);
Пример #25
0
 public void Add(TEntity entity)
 {
     _dbSet.Add(entity);
 }
Пример #26
0
        private void CreateCodeTemplateIfNeeded(IDataService dataService, DbSet<SigCodeTemplate> codeTemplates, string codeTemplateValue, string codeTemplateDisplayeName)
        {
            if ((from c in codeTemplates where c.Code.Equals(codeTemplateValue) select c).Any() == false)
            {
                SigCodeTemplate codeNodeTemplate = new SigCodeTemplate();
                codeNodeTemplate.Code = codeTemplateValue;
                codeNodeTemplate.Libelle = codeTemplateDisplayeName;
                codeTemplates.Add(codeNodeTemplate);
                dataService.DataContext.SaveChanges();

            }
        }
 public void Add(Tournament tournament)
 {
     _tournaments.Add(tournament);
 }
Пример #28
0
 public void Add(TEntity entity)
 {
     _db.Add(entity);
     _ctx.SaveChanges();
 }
Пример #29
0
 private void CreateCodeLayerIfNeeded(IDataService dataService, DbSet<SigCodeLayer> codeLayers, string codeLayerValue)
 {
     if ((from c in codeLayers where c.Code.Equals(codeLayerValue) select c).Any() == false)
     {
         SigCodeLayer codeLayerGoogle = new SigCodeLayer();
         codeLayerGoogle.Code = codeLayerValue;
         codeLayerGoogle.Libelle = codeLayerValue;
         codeLayers.Add(codeLayerGoogle);
         dataService.DataContext.SaveChanges();
     }
 }
Пример #30
0
 public virtual void Insert(TEntity entity)
 {
     dbSet.Add(entity);
 }
Пример #31
0
 public void Add(TModel model)
 {
     _dbSet?.Add(model);
     SaveChanges();
 }
Пример #32
0
 public virtual async Task Adicionar(TEntity entity)
 {
     DbSet.Add(entity);
     await SalvarAlteracoes();
 }
Пример #33
0
        //static void AddGroups3(DbSet<ScenarioGroup> root, DateTime now)
        //{
        //    ScenarioGroup sg = new ScenarioGroup();
        //    sg.Name = "Test-Child2";
        //    sg.ScenarioGroupID = 2;
        //    sg.ScenarioGroupParentID = 1;
        //    sg.StartTime = now.AddDays(-80);
        //    sg.EndTime = DateTime.MaxValue;
        //    sg.CreatedBy = "me";
        //    sg.TimeStamp = now.AddDays(-80);
        //    root.Add(sg);
        //}
        static void AddScenarios(DbSet<ScenarioGroup> setScenarioGroup, DbSet<Scenario> setScenario, DateTime now)
        {
            ScenarioGroup sg = new ScenarioGroup();
            sg.StartTime = now.AddDays(-80);
            sg.EndTime = DateTime.MaxValue;
            sg.CreatedBy = "me";
            sg.CreatedAt = now;
            setScenarioGroup.Add(sg);

            ScenarioGroupDetail sgd = new ScenarioGroupDetail();
            sgd.Name = "Test-Child-2";
            sgd.StartTime = now.AddDays(-80);
            sgd.EndTime = DateTime.MaxValue;
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now;
            sg.ScenarioGroupDetails.Add(sgd);

            Scenario s = new Scenario();
            s.StartTime = now.AddDays(-80);
            s.EndTime = DateTime.MaxValue;
            s.CreatedBy = "me";
            s.CreatedAt = now;
            setScenario.Add(s);

            ScenarioDetail sd = new ScenarioDetail();
            sd.Name = "Scenario A";
            sd.StartTime = now.AddDays(-80);
            sd.EndTime = DateTime.MaxValue;
            sd.CreatedBy = "me";
            sd.CreatedAt = now;
            s.ScenarioDetails.Add(sd);

            Scenario s2 = new Scenario();
            s.StartTime = now.AddDays(-80);
            s.EndTime = DateTime.MaxValue;
            s.CreatedBy = "me";
            s.CreatedAt = now;
            setScenario.Add(s2);

            ScenarioDetail sd2 = new ScenarioDetail();
            sd.Name = "Derive from A";
            sd.StartTime = now.AddDays(-80);
            sd.EndTime = DateTime.MaxValue;
            sd.CreatedBy = "me";
            sd.CreatedAt = now;
            s2.ScenarioDetails.Add(sd2);

            s.DerivedScenarios.Add(s2);
        }
Пример #34
0
 public void Insert(TEntity entity)
 {
     dbset.Add(entity);//实体集添加一个实体
 }
Пример #35
0
        static void AddGroups2(DbSet<ScenarioGroup> root, DateTime now)
        {
            ScenarioGroup sg1 = root.Find(2);

            ScenarioGroup sg = new ScenarioGroup();
            sg.StartTime = now.AddDays(-80);
            sg.EndTime = DateTime.MaxValue;
            sg.CreatedBy = "me";
            sg.CreatedAt = now;
            root.Add(sg);

            ScenarioGroupDetail sgd = new ScenarioGroupDetail();
            sgd.Name = "Test-Child-2";
            sgd.StartTime = now.AddDays(-80);
            sgd.EndTime = now.AddDays(-40);
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now.AddDays(-40);
            sg.ScenarioGroupDetails.Add(sgd);

            sgd = new ScenarioGroupDetail();
            sgd.Name = "Test-Child-2";
            sgd.StartTime = now.AddDays(-40);
            sgd.EndTime = now.AddDays(-20);
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now.AddDays(-20);
            sg.ScenarioGroupDetails.Add(sgd);

            sgd = new ScenarioGroupDetail();
            sgd.Name = "Test-Child-2";
            sgd.StartTime = now.AddDays(-20);
            sgd.EndTime = DateTime.MaxValue;
            sgd.CreatedBy = "me";
            sgd.CreatedAt = now.AddDays(-20);
            sg.ScenarioGroupDetails.Add(sgd);
        }
 public void Insert(T t)
 {
     dbSet.Add(t);
 }
Пример #37
0
 public void Create(TModel model)
 {
     dbSet.Add(model);
 }
Пример #38
0
        /// <summary>
        /// Adds the specified voting process.
        /// </summary>
        /// <param name="votingProcess">The voting process.</param>
        public virtual void Add(T votingProcess)
        {
            DbSet.Add(votingProcess);

            Save();
        }