Ejemplo n.º 1
0
        public void WhenSavingEntityTwice_ThenCanReloadIt()
        {
            var id = Guid.NewGuid();

            using (var context = new SqlDataContext <TestAggregateRoot>(() => new TestDbContext(), Mock.Of <IEventBus>()))
            {
                var aggregateRoot = new TestAggregateRoot(id);
                context.Save(aggregateRoot);
            }

            using (var context = new SqlDataContext <TestAggregateRoot>(() => new TestDbContext(), Mock.Of <IEventBus>()))
            {
                var aggregateRoot = context.Find(id);
                aggregateRoot.Title = "test";

                context.Save(aggregateRoot);
            }

            using (var context = new SqlDataContext <TestAggregateRoot>(() => new TestDbContext(), Mock.Of <IEventBus>()))
            {
                var aggregateRoot = context.Find(id);

                Assert.Equal("test", aggregateRoot.Title);
            }
        }
Ejemplo n.º 2
0
        public void WhenSavingEntityTwice_ThenCanReloadIt()
        {
            var id = Guid.NewGuid();

            using (var context = new SqlDataContext<TestAggregateRoot>(() => new TestDbContext(), Mock.Of<IEventBus>()))
            {
                var aggregateRoot = new TestAggregateRoot(id);
                context.Save(aggregateRoot);
            }

            using (var context = new SqlDataContext<TestAggregateRoot>(() => new TestDbContext(), Mock.Of<IEventBus>()))
            {
                var aggregateRoot = context.Find(id);
                aggregateRoot.Title = "test";

                context.Save(aggregateRoot);
            }

            using (var context = new SqlDataContext<TestAggregateRoot>(() => new TestDbContext(), Mock.Of<IEventBus>()))
            {
                var aggregateRoot = context.Find(id);

                Assert.Equal("test", aggregateRoot.Title);
            }
        }
Ejemplo n.º 3
0
 public bool DeleteBulkResponse(IEnumerable <Response> responses, out string status)
 {
     try
     {
         SqlDataContext.Repository <Response>().DeleteMany(responses);
         SqlDataContext.Save();
         status = "Success";
         return(true);
     }
     catch (Exception ex)
     {
         status = ex.GetAllMessages();
         return(false);
     }
 }
Ejemplo n.º 4
0
        public bool CheckSnipeValidity(Snipe snipe, UltimateSniper_Services.ServiceEBay eBayService)
        {
            bool res = false;
            SqlDataContext myDataConnection = new SqlDataContext();

            User user = this.GetUserForSnipe(snipe);

            if (user == null)
            {
                snipe.SnipeStatus = EnumSnipeStatus.ERROR;
                snipe.SnipeErrorReason = "The user assocated to the snipe couldn't be loaded properly.";
            }
            else
            {
                eBayItemData item = eBayService.GetItemDetails(snipe.ItemID);

                if (item.ItemCurrentHighestBid > snipe.SnipeBidInFinalCurrency)
                {
                    UltimateSniper_Services.ServiceEmail emailService = new UltimateSniper_Services.ServiceEmail();

                    snipe.SnipeStatus = EnumSnipeStatus.OVERBID;
                    snipe.SnipeErrorReason = "The snipe bid is lower the current price.";

                    ServiceEmail.SendEmail(user, "[SnipeAgent] Maximum bid reached for: " + snipe.SnipeName, "Hello, you snipe bid is lower the current price. You can still modify it by going on www.snipeagent.com and into the section 'My Snipes'. Kind regards, Snipe Agent.");
                }

                res = true;

                item.ItemCurrentHighestBidUserCurrency = this.ConvertValue(item.ItemCurrentHighestBid, item.ItemCurrencyCode.ToString(), user.UserCurrency.ToString());
                snipe.ItemLastKnownPrice = item.ItemCurrentHighestBidUserCurrency;

                snipe.ItemEndDate = item.ItemEndDate;
                snipe.ItemTitle = item.ItemTitle;
                snipe.ItemURL = item.ItemURL;
                snipe.ItemSellerID = item.ItemSellerID;
                snipe.ItemPictureURL = item.ItemPictureURL;

                snipe.ItemLastUdpate = ServiceTimeZone.DateTimeToUniversal(DateTime.Now);
            }

            snipe.ValidityCheckInProgress = false;

            myDataConnection.Save<Snipe>((object)snipe, snipe);

            return res;
        }
Ejemplo n.º 5
0
        public void WhenSavingAggregateRoot_ThenCanRetrieveIt()
        {
            var id = Guid.NewGuid();

            using (var context = new SqlDataContext<TestAggregateRoot>(() => new TestDbContext(), Mock.Of<IEventBus>()))
            {
                var aggregateRoot = new TestAggregateRoot(id) { Title = "test" };

                context.Save(aggregateRoot);
            }

            using (var context = new SqlDataContext<TestAggregateRoot>(() => new TestDbContext(), Mock.Of<IEventBus>()))
            {
                var aggregateRoot = context.Find(id);

                Assert.NotNull(aggregateRoot);
                Assert.Equal("test", aggregateRoot.Title);
            }
        }
        public void WhenSavingAggregateRoot_ThenCanRetrieveIt()
        {
            var id = Guid.NewGuid();

            using (var context = new SqlDataContext <TestAggregateRoot>(() => new TestDbContext(), Mock.Of <IEventBus>())) {
                var aggregateRoot = new TestAggregateRoot(id)
                {
                    Title = "test"
                };
                context.Save(aggregateRoot);
            }

            using (var context = new SqlDataContext <TestAggregateRoot>(() => new TestDbContext(), Mock.Of <IEventBus>())) {
                var aggregateRoot = context.Find(id);

                Assert.NotNull(aggregateRoot);
                Assert.AreEqual("test", aggregateRoot.Title);
            }
        }
Ejemplo n.º 7
0
        public bool SaveRequest(out string status)
        {
            try
            {
                var user = SqlDataContext.Repository <User>().Query()
                           .Get().FirstOrDefault();

                if (user == null)
                {
                    status = "There is no registered User in the database";
                    return(false);
                }

                var requestType = SqlDataContext.Repository <RequestType>()
                                  .Query().Get().FirstOrDefault();

                if (requestType != null)
                {
                    SqlDataContext.Repository <Request>().InsertGraph(new Request
                    {
                        Id            = Guid.NewGuid(),
                        RequestTypeId = requestType.Id,
                        Header        = "Test Request",
                        Body          = "Body text for test request",
                        UserId        = user.Id
                    });

                    SqlDataContext.Save();

                    status = "Success";
                    return(true);
                }

                status = "There is no registered Request Type in the database";
                return(false);
            }
            catch (Exception ex)
            {
                status = ex.GetAllMessages();
                return(false);
            }
        }
        public void WhenEntityExposesEvent_ThenRepositoryPublishesIt()
        {
            var busMock = new Mock <IEventBus>();
            var events  = new List <IEvent>();

            busMock.Setup(x => x.Publish(It.IsAny <IEnumerable <Envelope <IEvent> > >()))
            .Callback <IEnumerable <Envelope <IEvent> > >(x => events.AddRange(x.Select(e => e.Body)));

            var @event = new TestEvent();

            using (var context = new SqlDataContext <TestEventPublishingAggregateRoot>(() => new TestDbContext(), busMock.Object)) {
                var aggregate = new TestEventPublishingAggregateRoot(Guid.NewGuid());
                aggregate.AddEvent(@event);

                context.Save(aggregate);
            }

            Assert.AreEqual(1, events.Count);
            Assert.IsTrue(events.Contains(@event));
        }
Ejemplo n.º 9
0
        public bool SaveBulkResponse(out string status)
        {
            try
            {
                var user = SqlDataContext.Repository <User>().Query().Get().FirstOrDefault();

                if (user == null)
                {
                    status = "There is no registered User in the database";
                    return(false);
                }

                var request = SqlDataContext.Repository <Request>().Query().Include(r => r.Response).Get().FirstOrDefault();
                if (request == null)
                {
                    status = "There is no registered Request in the database";
                    return(false);
                }

                var responses = Enumerable.Range(0, 1000).Select(p => new Response
                {
                    Id        = Guid.NewGuid(),
                    Body      = "Bulk insert test for responses",
                    Header    = "Bulk insert test",
                    RequestId = request.Id,
                    UserId    = user.Id
                });

                SqlDataContext.Repository <Response>().InsertMany(responses);

                SqlDataContext.Save();

                status = "Success";
                return(true);
            }
            catch (Exception ex)
            {
                status = ex.GetAllMessages();
                return(false);
            }
        }
Ejemplo n.º 10
0
        public bool SaveTestUser(out string status)
        {
            try
            {
                SqlDataContext.Repository <User>().InsertGraph(new User
                {
                    Id       = Guid.NewGuid(),
                    Email    = "*****@*****.**",
                    FullName = "Emre Gulay",
                    IsActive = true,
                    Password = "******"
                });

                SqlDataContext.Save();

                status = "Saved";
                return(true);
            }
            catch (Exception ex)
            {
                status = ex.GetAllMessages();
                return(false);
            }
        }
Ejemplo n.º 11
0
        public void WhenEntityExposesEvent_ThenRepositoryPublishesIt()
        {
            var busMock = new Mock<IEventBus>();
            var events = new List<IEvent>();

            busMock
                .Setup(x => x.Publish(It.IsAny<IEnumerable<Envelope<IEvent>>>()))
                .Callback<IEnumerable<Envelope<IEvent>>>(x => events.AddRange(x.Select(e => e.Body)));

            var @event = new TestEvent();

            using (var context = new SqlDataContext<TestEventPublishingAggregateRoot>(() => new TestDbContext(), busMock.Object))
            {
                var aggregate = new TestEventPublishingAggregateRoot(Guid.NewGuid());
                aggregate.AddEvent(@event);
                context.Save(aggregate);
            }

            Assert.Equal(1, events.Count);
            Assert.True(events.Contains(@event));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This code should be executed just before the item ends
        /// </summary>
        /// <param name="snipe">Snipe to be executed</param>
        /// <returns></returns>
        public void PlaceBids()
        {
            try
            {

                SqlDataContext myDataConnection = new SqlDataContext();

                UltimateSniper_Services.ServiceOthers otherServ = new UltimateSniper_Services.ServiceOthers();

                User user = otherServ.GetUserForSnipe(_Snipe);

                if (user == null)
                {
                    _Snipe.SnipeErrorReason = "The user assocated to the snipe couldn't be loaded properly.";
                }
                else
                {
                    if (!_Snipe.SnipeInProgress)
                    {
                        _Snipe.SnipeInProgress = true;

                        myDataConnection.Save<Snipe>((object)_Snipe, _Snipe);
                    }

                    try
                    {
                        SL_Scheduler.eBayService.User = user;

                        while (true)
                        {
                            if (SL_Scheduler.eBayService.IsUserWinning(this._Snipe)) break;
                            SL_Scheduler.eBayService.SetSnipe(this._Snipe);
                            System.Threading.Thread.Sleep(1000);
                        }
                    }
                    catch (ControlObjectException ex)
                    {
                        foreach (UserMessage message in ex.ErrorList)
                        {
                            if (message.MessageCode == EnumMessageCode.SnipeBidOptimizerMaxBidReached)
                            {
                                UltimateSniper_Services.ServiceEmail emailService = new UltimateSniper_Services.ServiceEmail();

                                _Snipe.SnipeStatus = EnumSnipeStatus.OVERBID;
                                _Snipe.SnipeErrorReason = "The snipe bid is lower the current price.";

                                ServiceEmail.SendEmail(user, "[SnipeAgent] Maximum bid reached for: " + _Snipe.SnipeName, "Hello, the maximum bid for your item has been reached. You can still modify it and win the item. To do so, go on www.snipeagent.com and into the section 'My Snipes'. Kind regards, Snipe Agent.");
                            }
                        }
                        _Snipe.SnipeErrorReason = ex.Message;
                    }
                    catch (Exception ex)
                    {
                        _Snipe.SnipeErrorReason = ex.Message;
                    }
                }

                _Snipe.ItemLastUdpate = ServiceTimeZone.DateTimeToUniversal(DateTime.Now);
                _Snipe.SnipeInProgress = false;

                myDataConnection.Save<Snipe>((object)_Snipe, _Snipe);

            }
            catch (ControlObjectException ex)
            {
                foreach (UserMessage error in ex.ErrorList)
                    Logger.CreateLog("Error__Timer_BidOptimizer_RefreshSnipes_" + error.MessageCode.ToString() + error.Severity.ToString(), null, ex, EnumLogLevel.ERROR);
            }
            catch (Exception ex)
            {
                Logger.CreateLog("Error__Timer_BidOptimizer_RefreshSnipes", null, ex, EnumLogLevel.ERROR);
            }
        }