示例#1
0
        static void Main(string[] args)
        {
            // var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", false, true);


            EntityRepository a = new EntityRepository();
            Category         b = new Category();
            Item             c = new Item();

            b.Name = "lol";
            a.Add(b);
            a.Add(c);
            Console.ReadLine();
        }
示例#2
0
        public void AddUpdateAlarm()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ENTITITES.First(e => e.Name.Equals("Starbucks")));

            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();
            EntityAlarm           alarm           = new EntityAlarm("1", "1", SentimentType.NEGATIVE, ENTITITES.First(e => e.Name.Equals("Starbucks")));

            alarmRepository.Add(alarm);

            SentimentRepository sentimentRepository = new SentimentRepository();

            sentimentRepository.Add(new Sentiment(SentimentType.NEGATIVE, "i dont like"));

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            Phrase phrase = new Phrase("I dont like Starbucks", DateTime.Now, AUTHOR);

            REPOSITORY.Add(phrase);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 1);
        }
示例#3
0
        /// <summary>
        /// Creates new entity and saves changings
        /// </summary>
        /// <param name="entity">An instance of new entity</param>
        /// <returns>Returns created entity</returns>
        public virtual T Create(T entity)
        {
            var newEntity = _repository.Add(entity);

            _repository.Commit();
            return(newEntity);
        }
示例#4
0
        //returns false when user is returning, true when he is a new user
        public bool LogInUser(string FBgraphJSON)
        {
            this.FBAccount = JsonConvert.DeserializeObject <FacebookAccount>(FBgraphJSON);

            var isNew = EntityRepository.Add(this);

            if (isNew)
            {
#if IS_RUNNING_ON_SERVER
                if (FBAccount.verified) //for production deployment we do care if user is verified FB user
#else
                if (true)               //for testing we don't care if user is verified FB user
#endif
                {
                    Console.WriteLine("Stored new user {0} with FB id: {1}", this.Id, this.FBAccount.id);
                    //this is a new user, create a new model and send it to him
                    FinishLogIn();
                }
                else
                {
                    //send error message to user informing about nonverified account
                }
            }
            else
            {
                var returningUser = EntityRepository.allUsers.First <User>(x => x.Equals(this));
                returningUser.connection = this.connection;
                returningUser.FinishLogIn();
                this.connection = null;
                //this is returning user, send him his model he had last  time
            }
            return(isNew);
        }
示例#5
0
        protected override void OnExecute()
        {
            Guard.ArgumentNotNull(_entity, "Entity");
            _entity.CreatedBy = UserId;
            EntityRepository <U> .Add(_entity);

            base.OnExecute();
        }
        public void AddExistentAlarm()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            REPOSITORY.Add(ALARM);
            REPOSITORY.Add(ALARM);
        }
        public void ModifySentimentNoUpdateDifferentSentimentTypeAlarm()
        {
            PhraseRepository      phraseRepository = new PhraseRepository();
            EntityRepository      entityRepository = new EntityRepository();
            AuthorRepository      authorRepository = new AuthorRepository();
            EntityAlarmRepository alarmRepository  = new EntityAlarmRepository();

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity    google    = new Entity("google");
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            authorRepository.Add(AUTHOR);

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            try
            {
                entityRepository.Add(google);
            }
            catch (AnalysisException) { }

            try
            {
                phrase.AnalyzePhrase(new List <Entity> {
                    google
                }, new List <Sentiment> {
                    sentiment
                });
            }
            catch (AnalysisException) { }

            try
            {
                REPOSITORY.Add(sentiment);
            }
            catch (AnalysisException) { }

            SENTIMENT.Word = "i dont like";
            SENTIMENT.Type = SentimentType.NEGATIVE;

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.NEGATIVE, google);

            alarmRepository.Add(alarm);

            SENTIMENT.Word = "i really like";

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 0);
        }
        public void AddAlarm()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            REPOSITORY.Add(ALARM);

            Assert.IsNotNull(REPOSITORY.Get(ALARM.Id));
        }
        public void ModifyAlarm()
        {
            Entity entity = new Entity("Uber");

            ALARM.Entity = entity;

            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);
            entityRepository.Add(ENTITY);

            REPOSITORY.Add(ALARM);

            ALARM.Entity = ENTITY;

            REPOSITORY.Modify(ALARM.Id, ALARM);

            Assert.AreEqual(REPOSITORY.Get(ALARM.Id).Entity, ENTITY);
        }
示例#10
0
        public void Add_SessionNotReadOnly_SessionMethodCalled()
        {
            var session    = new Mock <ISession>();
            var repository = new EntityRepository <TestEntity>(session.Object);
            var entity     = new TestEntity();

            repository.Add(entity);

            session.Verify(x => x.SaveOrUpdate(entity), Times.Once);
        }
        public void IsNotEmpty()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            REPOSITORY.Add(ALARM);

            Assert.IsFalse(REPOSITORY.IsEmpty());
        }
示例#12
0
        public void Add_SessionReadOnly_ExceptionThrown()
        {
            var session = new Mock <ISession>();

            session.Setup(x => x.DefaultReadOnly)
            .Returns(true);
            var repository = new EntityRepository <TestEntity>(session.Object);
            var entity     = new TestEntity();

            Assert.Throws <EntityRepositoryException>(() => repository.Add(entity), "The Repository is read-only");
        }
        public void ModifyNonExitentAlarm()
        {
            EntityRepository entityRepository = new EntityRepository();
            Entity           entity           = new Entity("Uber");

            entityRepository.Add(entity);

            ALARM.Entity = entity;

            REPOSITORY.Modify(ALARM.Id, ALARM);
        }
        public void DeleteAlarm()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            REPOSITORY.Add(ALARM);

            REPOSITORY.Delete(ALARM.Id);

            REPOSITORY.Get(ALARM.Id);
        }
示例#15
0
        //基类方法+扩展方法(PingYourPackage)
        private static void Moduel2()
        {
            IEntityRepository <UserInfo> userRepo = new EntityRepository <UserInfo>(new EntitiesContext());

            userRepo.Add(new UserInfo
            {
                Key       = System.Guid.NewGuid(),
                Name      = "James",
                CreatedOn = DateTime.Now
            });

            userRepo.Add(new UserInfo
            {
                Key       = System.Guid.NewGuid(),
                Name      = "Mary",
                CreatedOn = DateTime.Now
            });

            userRepo.Save();

            UserInfo user = userRepo.GetSingleByUsername("James");
        }
示例#16
0
 public override bool RegisterVote(Vote vote)
 {
     {
         if (this.State == VotingStates.Ongoing)
         {
             return(EntityRepository.Add(vote));
         }
         else
         {
             return(false);
         }
     }
 }
        public override void ApplyChanges()
        {
            if (IsNew)
            {
                EntityRepository.Add(this.Entity);
            }
            else
            {
                EntityRepository.Update(this.Entity);
            }

            DialogHostExtensions.CloseCurrent();
        }
        public void ModityAlarmSentimentType()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            REPOSITORY.Add(ALARM);

            ALARM.Type = SentimentType.NEGATIVE;

            REPOSITORY.Modify(ALARM.Id, ALARM);

            Assert.AreEqual(ALARM.Type, SentimentType.NEGATIVE);
        }
示例#19
0
        public async Task Add_Success(ToDoItem item)
        {
            //arrange
            CancellationToken    token       = new CancellationToken();
            Mock <ToDoDbContext> mockContext = new Mock <ToDoDbContext>();

            mockContext.Setup(x => x.Add(It.IsAny <ToDoItem>())).Verifiable();
            mockContext.Setup(x => x.SaveChangesAsync(token)).Returns(() => Task.Run(() => { return(1); })).Verifiable();
            EntityRepository <ToDoItem> repo = new EntityRepository <ToDoItem>(mockContext.Object);

            //act
            await repo.Add(item);

            //assert
            mockContext.VerifyAll();
        }
示例#20
0
        public Uploadable SaveUplodable(UploadableArg uplodableArg, string personId, string userLoginId)
        {
            var fileUplodable = _uplodableRepository.FirstOrDefault(t => t.FileUploadId == uplodableArg.FileUploadId);

            if (fileUplodable == null)
            {
                fileUplodable = SetUplodable(uplodableArg, personId, userLoginId);
                _uplodableRepository.Add(fileUplodable);
            }
            else
            {
                fileUplodable.FileData = uplodableArg.File;
                fileUplodable          = _uplodableRepository.UpdateEntity(fileUplodable);
            }
            return(fileUplodable);
        }
        public void TestRepository_Update_Success()
        {
            // Log results.
            var log = (Globals.LOG_TO_FILE == true ? sw : Console.Out);

            try
            {
                // Change this value to test adding x number of people
                int recordsToCreate = 1;
                int IdToUpdate      = 1;

                // Arrange
                // 1. Create Mock dbSet
                FakeDbSet <Person> FakeDbSet = new FakeDbSet <Person>();
                // 2. Add records to Mock dbSet
                IEnumerable <Person> recordList = AddPeopleToFakeDbSet(FakeDbSet, recordsToCreate);
                // 3. Create Mock db context
                Mock <IPeopleContext> MockdDbContextObject = new Mock <IPeopleContext>();
                // 4. Create Repository from Fake dbSet
                EntityRepository <Person> repository = CreateRepository(MockdDbContextObject, FakeDbSet);
                // Act
                Person originalRecord   = recordList.ElementAt(IdToUpdate - 1);
                IEnumerator <Person> en = recordList.GetEnumerator();
                while (en.MoveNext())
                {
                    Person addedRecord = repository.Add(en.Current);
                }
                Person updatedRecord = recordList.FirstOrDefault(x => x.Id == IdToUpdate);
                updatedRecord.Name += "Updated";
                Person storedPerson = repository.Update(updatedRecord);

                // Assert
                MockdDbContextObject.Verify(pc => pc.Set <Person>(), Times.Once());
                Assert.NotSame(originalRecord, updatedRecord);
                Assert.Same(updatedRecord, storedPerson);

                // Log success
                log.WriteLine("{0}(): Passed - record {1} updated\n", MethodBase.GetCurrentMethod().Name, IdToUpdate);
            }
            //Log failure
            catch (Exception ex)
            {
                // Log failure
                log.WriteLine("{0}(): Failed - Exception: {1} Stack: {2}\n", MethodBase.GetCurrentMethod().Name, ex.GetBaseException(), ex.StackTrace);
            }
        }
        public void TestRepository_Add_Success()
        {
            // Init log
            var log = (Globals.LOG_TO_FILE == true ? sw : Console.Out);

            try
            {
                // Change this value to test adding x number of people
                int recordsToCreate = 2;

                // Arrange
                // 1. Create Mock dbSet
                FakeDbSet <Person> FakeDbSet = new FakeDbSet <Person>();
                // 2. Add records to Mock dbSet
                IEnumerable <Person> recordList = GetFakePeople(recordsToCreate).ToList();
                // 3. Create Mock db context
                Mock <IPeopleContext> MockdDbContextObject = new Mock <IPeopleContext>();
                // 4. Create Fake Repository from Fake dbSet
                EntityRepository <Person> repository = CreateRepository(MockdDbContextObject, FakeDbSet);

                int addedNbOfRecord     = 0;
                int storedCount         = 0;
                IEnumerator <Person> en = recordList.GetEnumerator();
                while (en.MoveNext())
                {
                    // Act
                    Person addedRecord = repository.Add(en.Current);
                    addedNbOfRecord++;

                    // Assert
                    MockdDbContextObject.Verify(pc => pc.Set <Person>(), Times.Once());
                    Assert.Same(addedRecord, en.Current);
                    storedCount = repository.GetCount();
                    Assert.Equal(addedNbOfRecord, storedCount);
                }

                // Log success
                log.WriteLine("{0}(): Passed - {1} records created {2} record stored\n", MethodBase.GetCurrentMethod().Name, addedNbOfRecord, storedCount);
            }
            //Log failure
            catch (Exception ex)
            {
                // Log failure
                log.WriteLine("{0}(): Failed - Exception: {1} Stack: {2}\n", MethodBase.GetCurrentMethod().Name, ex.GetBaseException(), ex.StackTrace);
            }
        }
        public async Task <IHttpActionResult> CreateItem(ItemRequest request)
        {
            //convert from DTO
            Item dbObject = request.ToDB();

            //add and save

            itemDB.Add(dbObject);
            await itemDB.Save();

            return(CreatedAtRoute("DefaultApi",
                                  new
            {
                ID = dbObject.ID
            },
                                  dbObject));
        }
        public void AddSentimentUpdateAlarm()
        {
            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();

            alarmRepository.Clear();

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Clear();

            PhraseRepository phraseRepository = new PhraseRepository();

            phraseRepository.Clear();

            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Clear();

            authorRepository.Add(AUTHOR);

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity    google    = new Entity("google");
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            try
            {
                entityRepository.Add(google);
            }
            catch (AnalysisException) { }

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, google);

            alarmRepository.Add(alarm);

            REPOSITORY.Add(sentiment);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 1);
        }
示例#25
0
        private void AddNewTask(object param, StartTimeCommand startTimeCommand)
        {
            CommitWrapper(() =>
            {
                var task = new Job
                {
                    State     = TaskState.New,
                    StartTime = startTimeCommand.StartTime,
                    Name      = startTimeCommand.Name,
                    Version   = param.GetClientStartVersion(),
                    Params    = _serializer.Serialize(param),
                    MimeType  = _serializer.GetMimeType(),
                    Type      = param.GetTaskType(),
                };


                _taskRepository.Add(task);
            });
        }
示例#26
0
        //public Vote(string userID, string subjectID, bool stance)
        ////public Vote()
        //{

        //    VotableItem subject = (VotableItem)ServerClientEntity.GetEntityFromSetsByID(subjectID);
        //    User user = Dem2Hub.allUsers.First(x => x.Id == casterUserID);
        //   // Agrees = stance;
        //    castedTime = DateTime.Now;
        //    InitVote(user, subject);

        //    Dem2Hub.StoreThis(this);
        //}

        public bool InitVote(User caster)
        {
            castedTime   = DateTime.Now;
            OwnerId      = caster.Id;
            casterUserId = OwnerId;
            VotableItem subject = (VotableItem)EntityRepository.GetEntityFromSetsByID(subjectId);

            if (subject != null)
            {
                if (EntityRepository.Add(this))
                {
                    subject.IncrementVotableVersion(); // this triggers on change and notifies the subscribers, because on the subject, properties VoteCounts changed
                    return(true);
                }
                else
                {
                }
            }
            return(false);
        }
示例#27
0
        static void Main(string[] args)
        {
            var user = new User {
                Id = 1, Name = "Name"
            };

            var phone = new Phone {
                Id = 1, PhoneCode = "123", Value = "123124"
            };

            var userRepository = new EntityRepository <User>();

            userRepository.Add(user);

            var contactRepository = new EntityRepository <Contact>();

            contactRepository.Add(phone);

            Console.WriteLine(contactRepository.GetById(1));
        }
示例#28
0
        public bool EntityInsert <TEntity>(IEntity entity) where TEntity : IEntity
        {
            bool success = false;

            try
            {
                ApplicationPlatformContext <TEntity> ContextEntity = new ApplicationPlatformContext <TEntity>();
                ContextEntity.Initialized();
                EntityRepository <TEntity> repository = new EntityRepository <TEntity>(ContextEntity, entity, true);
                repository.Add(entity);
                success = true;
            }
            catch (SqliteException ex)
            {
                SqLiteExceptionHandler <SqliteException> error = new SqLiteExceptionHandler <SqliteException>(ex);
                LoggerHelper.LogConsole("Database Error : ");
                LoggerHelper.LogConsole("Description" + error.GetDescription());
                LoggerHelper.LogConsole("TrackTrace" + error.GetTrackTrace());
            }
            return(success);
        }
示例#29
0
        public virtual T Create(T entity)
        {
            try
            {
                Authorize(Can_Create);
                With.Transaction(
                    delegate { EntityRepository <T> .Add(entity); });
                return(entity);
            }
            catch (System.Exception ex)
            {
                bool reThrow = ExceptionHandler.HandleBusinessLogicLayerException(ex);

                if (reThrow)
                {
                    throw;
                }

                return(null);
            }
        }
        public void UpdateAlarmWithOldPhrases()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            SentimentRepository sentimentRepository = new SentimentRepository();

            sentimentRepository.Add(new Sentiment(SentimentType.POSITIVE, "i like"));

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            PhraseRepository phraseRepository = new PhraseRepository();

            phraseRepository.Add(new Phrase($"i like {ALARM.Entity.Name}", DateTime.Now.AddDays(-1), AUTHOR));

            REPOSITORY.Add(ALARM);

            Assert.AreEqual(REPOSITORY.Get(ALARM.Id).PostCount, 1);
        }