Ejemplo n.º 1
0
        public void Execute()
        {
            string query      = "select * from table";
            bool   dao1Called = false;
            bool   dao2Called = false;

            Mock <ICommonObjectDao> MockCOD1 = new Mock <ICommonObjectDao>();
            Mock <ICommonObjectDao> MockCOD2 = new Mock <ICommonObjectDao>();

            MockCOD1.Setup(t => t.Query(new ListQuery <NameValueItem> {
                Query = query
            })).Callback(() => { dao1Called = true; });
            MockCOD2.Setup(t => t.Query(new ListQuery <NameValueItem> {
                Query = query
            })).Callback(() => { dao2Called = true; });

            MockCODCreator.Setup(t => t.GetCOD("connectionString1")).Returns(MockCOD1.Object);
            MockCODCreator.Setup(t => t.GetCOD("connectionString2")).Returns(MockCOD2.Object);

            MockConnectionStringMaker.Setup(t => t.Make("ConnectionIp1", "ConnectionDatabase1", "ConnectionId1", "ConnectionPassword1")).Returns("connectionString1");
            MockConnectionStringMaker.Setup(t => t.Make("ConnectionIp2", "ConnectionDatabase2", "ConnectionId2", "ConnectionPassword2")).Returns("connectionString2");

            IList <DbConnectionInfoItem> connectionInfoList = new List <DbConnectionInfoItem>();

            connectionInfoList.Add(new DbConnectionInfoItem {
                ConnectionIp = "ConnectionIp1", ConnectionDatabase = "ConnectionDatabase1", ConnectionId = "ConnectionId1", ConnectionPassword = "******"
            });
            connectionInfoList.Add(new DbConnectionInfoItem {
                ConnectionIp = "ConnectionIp2", ConnectionDatabase = "ConnectionDatabase2", ConnectionId = "ConnectionId2", ConnectionPassword = "******"
            });

            DbExecuter.Execute(connectionInfoList, query);
            Assert.AreEqual(true, dao1Called);
            Assert.AreEqual(true, dao2Called);
        }
Ejemplo n.º 2
0
        //public OperationResult<IEnumerable<Region>> GetRegions(int petitonLevelId)
        //{
        //	OperationResult<IEnumerable<Region>> result;

        //	try
        //	{
        //		using (var db = new EDEntities())
        //		{
        //			var regions = this.FakeRegions.Where(r => r.Level != null && r.Level.ID == petitonLevelId);
        //			foreach (var fakeRegion in this.FakeRegions)
        //			{
        //				// load full level info
        //			}

        //			result = OperationResult<IEnumerable<Region>>.Success(regions);
        //		}
        //	}
        //	catch (Exception exc)
        //	{
        //		result = OperationResult<IEnumerable<Region>>.ExceptionResult(exc);
        //	}

        //	return result;
        //}


        public OperationResult <IEnumerable <Region> > GetRegions(int petitonLevelId)
        {
            Func <EDEntities, OperationResult <IEnumerable <Region> > > getRegions = (db) =>
            {
                var regions = this.FakeRegions.Where(r => r.Level != null && r.Level.ID == petitonLevelId);
                foreach (var fakeRegion in this.FakeRegions)
                {
                    // load full level info
                }

                var result = OperationResult <IEnumerable <Region> > .Success(regions);

                return(result);
            };
            var operationResult = DbExecuter.Execute(getRegions);

            return(operationResult);
        }
        public OperationResult <Model.BusinessEntities.PetitionEmailVote> CreateEmailVoteRequest(EmailVote vote)
        {
            OperationResult <Model.BusinessEntities.PetitionEmailVote> emailVoteRequestResult;

            Func <EDEntities, OperationResult <Model.BusinessEntities.PetitionEmailVote> > procedure = (db) =>
            {
                OperationResult <Model.BusinessEntities.PetitionEmailVote> result;

                var emailVote = db.PetitionEmailVotes.SingleOrDefault(v => v.PetitionID == vote.ID && v.Email == vote.Email);

                if (emailVote != null)
                {
                    var votedPetition = db.Petitions.SingleOrDefault(p => p.ID == vote.ID);
                    result = emailVote.IsConfirmed
                                                ? OperationResult <Model.BusinessEntities.PetitionEmailVote> .Fail(
                        int.Parse(PetitionVoteOperationResult.AlreadyVotedCode),
                        PetitionVoteOperationResult.AlreadyVotedMessage)
                                                : OperationResult <Model.BusinessEntities.PetitionEmailVote> .Success(
                        int.Parse(PetitionVoteOperationResult.WaitingConfirmationCode),
                        string.Format(PetitionVoteOperationResult.WaitingConfirmationMessage, emailVote.Email),
                        new Model.BusinessEntities.PetitionEmailVote(emailVote, votedPetition));

                    return(result);
                }

                emailVote = new PetitionEmailVote
                {
                    PetitionID  = vote.ID,
                    Email       = vote.Email,
                    CreatedDate = DateTime.Now,
                    IsConfirmed = false,
                    Hash        = HashGenerator.Generate()
                };

                db.PetitionEmailVotes.Add(emailVote);
                db.SaveChanges();

                var petition        = new Model.BusinessEntities.Petition(db.Petitions.SingleOrDefault(p => p.ID == emailVote.PetitionID));
                var clientEmailVote =
                    new Model.BusinessEntities.PetitionEmailVote()
                {
                    ID          = emailVote.ID,
                    Petition    = petition,
                    Hash        = emailVote.Hash,
                    Email       = emailVote.Email,
                    CreatedDate = emailVote.CreatedDate,
                    IsConfirmed = emailVote.IsConfirmed
                };

                result = OperationResult <Model.BusinessEntities.PetitionEmailVote> .Success(
                    int.Parse(PetitionVoteOperationResult.EmailVoteRequestCreatedCode),
                    string.Format(PetitionVoteOperationResult.EmailVoteRequestCreatedMessage, emailVote.Email),
                    clientEmailVote);

                return(result);
            };

            emailVoteRequestResult = DbExecuter.Execute(procedure);

            return(emailVoteRequestResult);
        }