public void DoesNotAllowReceiveNewBidWhenAuctionIsClosed(
            int quantityBidsExpected, double[] amounts)
        {
            //Arranje
            var evaluation = new UpperAmount();
            var auction    = new Auction("Van Gogh", evaluation);
            var johnDoe    = new Interested("John Doe");
            var janeDoe    = new Interested("Jane Doe");

            auction.StartAuction();

            for (int i = 0; i < amounts.Length; i++)
            {
                var amount = amounts[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(johnDoe, amount);
                }
                else
                {
                    auction.ReceiveBid(janeDoe, amount);
                }
            }

            auction.FinishAuction();

            //Act
            auction.ReceiveBid(johnDoe, 1000);

            //Assert
            Assert.Equal(quantityBidsExpected, auction.Bids.Count());
        }
        public void DoesntAllowNewBidsAfterAuctionIsFinished(int quantityExpected, double[] offers)
        {
            //Arranje
            IEvaluationType evaluationType = new HigherValue();
            var             auction        = new Auction("Van Gogh", evaluationType);
            var             john           = new Interested("Jhon", auction);
            var             mike           = new Interested("Mike", auction);

            auction.StartAuction();
            for (int i = 0; i < offers.Length; i++)
            {
                var value = offers[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(john, value);
                }
                else
                {
                    auction.ReceiveBid(mike, value);
                }
            }

            auction.FinishAuction();

            //Act
            auction.ReceiveBid(john, 1000);

            //Assert
            var quantityGot = auction.Bids.Count();

            Assert.Equal(quantityExpected, quantityGot);
        }
        public void ReturnHigherValueCloserForAuctionOfThisType(
            double destinyValue,
            double expectedValue,
            double[] offers)
        {
            //Arranje
            IEvaluationType evaluationType = new HigherOfferCloser(destinyValue);
            var             auction        = new Auction("Van Gogh", evaluationType);
            var             john           = new Interested("Jhon", auction);
            var             mike           = new Interested("Mike", auction);

            auction.StartAuction();

            for (int i = 0; i < offers.Length; i++)
            {
                if ((i % 2 == 0))
                {
                    auction.ReceiveBid(john, offers[i]);
                }
                else
                {
                    auction.ReceiveBid(mike, offers[i]);
                }
            }

            //Act
            auction.FinishAuction();

            //Assert
            Assert.Equal(expectedValue, auction.BidWinner.Value);
        }
        public void ReturnHigherValueForAuctionWithAtLeastOneAuction(
            double expectedValue,
            double[] offers)
        {
            //Arranje
            IEvaluationType evaluationType = new HigherValue();
            var             auction        = new Auction("Van Gogh", evaluationType);
            var             john           = new Interested("Jhon", auction);
            var             mike           = new Interested("Mike", auction);

            auction.StartAuction();

            for (int i = 0; i < offers.Length; i++)
            {
                var valor = offers[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(john, valor);
                }
                else
                {
                    auction.ReceiveBid(mike, valor);
                }
            }

            //Act
            auction.FinishAuction();

            //Assert
            var valueGot = auction.BidWinner.Value;

            Assert.Equal(expectedValue, valueGot);
        }
        public void ReturnMaxAmountWhenHaveAtLastOneBid(double expectedAmount, double[] amounts)
        {
            //Arrange
            var modality = new UpperAmount();
            var auction  = new Auction("Van Gogh", modality);
            var johnDoe  = new Interested("John Doe");
            var janeDoe  = new Interested("Jane Doe");

            auction.StartAuction();

            for (int i = 0; i < amounts.Length; i++)
            {
                double amount = amounts[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(johnDoe, amount);
                }
                else
                {
                    auction.ReceiveBid(janeDoe, amount);
                }
            }

            //Act
            auction.FinishAuction();

            //Assert
            Assert.Equal(expectedAmount, auction.Winner.Amount);
        }
        public void ReturnNearestUpperAmountWhenAuctionIsNearestUpperAmountModality(double targetAmount, double expectedAmount, double[] amounts)
        {
            //Arrange
            IEvaluationMode mode    = new NearestUpperAmount(targetAmount);
            var             auction = new Auction("Van Gogh", mode);
            var             johnDoe = new Interested("John Doe");
            var             janeDoe = new Interested("Jane Doe");

            auction.StartAuction();

            for (int i = 0; i < amounts.Length; i++)
            {
                double amount = amounts[i];
                if ((i % 2) == 0)
                {
                    auction.ReceiveBid(johnDoe, amount);
                }
                else
                {
                    auction.ReceiveBid(janeDoe, amount);
                }
            }

            //Act
            auction.FinishAuction();

            //Assert
            Assert.Equal(expectedAmount, auction.Winner.Amount);
        }
示例#7
0
 public IActionResult addtocart(Interested obj)
 {
     if (ModelState.IsValid)
     {
         _db.Interested.Add(obj);
         _db.SaveChanges();
         return(RedirectToAction("Interest"));
     }
     return(View(obj));
 }
示例#8
0
        public Bid(Interested client, double value)
        {
            if (value < 0)
            {
                throw new System.ArgumentException("Bid`s value should be greater or equals to zero.");
            }

            Client = client;
            Value  = value;
        }
示例#9
0
 public IActionResult PostAddInteresterd([FromBody] Interested i)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Model is not valid."));
     }
     if (vinylContext.Interested.SingleOrDefault(e => (e.EventRef == i.EventRef) && (e.AttenderRef == i.AttenderRef)) != null)
     {
         return(Conflict("Alredy exists."));
     }
     vinylContext.Interested.Add(i);
     vinylContext.SaveChanges();
     return(Ok());
 }
示例#10
0
        public IActionResult ReceiveBid(BidViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Auction    auction    = _auctionRepository.GetById(model.AuctionId);
            Interested interested = _interestedRepository.GetById(model.LoggedUserId);

            auction.ReceiveBid(interested, model.Amount);
            _auctionRepository.Update(auction);
            return(Ok());
        }
        public void DoesNotAllowReceiveBidWhenLastBidIsFromSameInterested()
        {
            //Arrange
            var evaluation = new UpperAmount();
            var auction    = new Auction("Van Gogh", evaluation);
            var johnDoe    = new Interested("John Doe");

            auction.StartAuction();
            auction.ReceiveBid(johnDoe, 800);

            //Act
            auction.ReceiveBid(johnDoe, 1000);

            //Assert
            Assert.Single(auction.Bids);
        }
示例#12
0
 public void addRespond(InterestedModel interestedModel)
 {
     using (var context = new toletBDdbEntities1())
     {
        Interested users = new Interested()
         {
             users_id=interestedModel.users_id,
             name=interestedModel.name,
             ad_id=interestedModel.ad_id,
             phone=interestedModel.phone,
             occupation=interestedModel.occupation,
             familymembers=interestedModel.familymembers,
             presentAddress=interestedModel.presentAddress
         };
         context.Interesteds.Add(users);
         context.SaveChanges();
     }
 }
        public void DoesntAcceptBidFromTheLastClientWhoMadeBid()
        {
            //Arranje
            IEvaluationType evaluationType = new HigherValue();
            var             auction        = new Auction("Van Gogh", evaluationType);
            var             john           = new Interested("John", auction);

            auction.StartAuction();
            auction.ReceiveBid(john, 800);

            //Act
            auction.ReceiveBid(john, 1000);

            //Assert
            var quantityExpected = 1;
            var quantityGot      = auction.Bids.Count();

            Assert.Equal(quantityExpected, quantityGot);
        }
示例#14
0
        public object GetAll()
        {
            var queryValues = Request.RequestUri.ParseQueryString();

            int page  = Convert.ToInt32(queryValues["page"]);
            int start = Convert.ToInt32(queryValues["start"]);
            int limit = Convert.ToInt32(queryValues["limit"]);
            int id    = Convert.ToInt32(queryValues["id"]);
            int orden = Convert.ToInt32(queryValues["orden"]);

            string strFieldFilters = queryValues["fieldFilters"];

            FieldFilters fieldFilters = new FieldFilters();

            if (!String.IsNullOrEmpty(strFieldFilters))
            {
                fieldFilters = JsonConvert.DeserializeObject <FieldFilters>(strFieldFilters);
            }


            #region Configuramos el orden de la consulta si se obtuvo como parametro
            string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
            strOrder = strOrder.Replace('[', ' ');
            strOrder = strOrder.Replace(']', ' ');

            Sort sort;

            if (!string.IsNullOrWhiteSpace(strOrder))
            {
                sort = JsonConvert.DeserializeObject <Sort>(strOrder);
            }
            else
            {
                sort = new Sort();
            }
            #endregion

            string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

            int totalRecords = 0;

            try
            {
                if (id == 0)
                {
                    object json;
                    var    lista = repository.GetList(query, fieldFilters, sort, page, start, limit, ref totalRecords);

                    json = new
                    {
                        total   = totalRecords,
                        data    = lista,
                        success = true
                    };

                    return(json);
                }
                else
                {
                    Interested model = repository.Get(id);

                    object json = new
                    {
                        data    = model,
                        success = true
                    };

                    return(json);
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object json = new
                {
                    message = ex.Message,
                    success = false
                };

                return(json);
            }
        }
示例#15
0
 private void OnInterested()
 {
     Interested?.Invoke(this);
 }
示例#16
0
        public static ParsedMessage?TryParseMessage(ReadOnlySequence <byte> buf)
        {
            var be = Binary.BigEndian;

            if (buf.Length < 4)
            {
                return(null);
            }

            var off = 4;
            var len = be.GetUInt32(buf.Slice(0, 4).ToArray());

            if (len == 0)
            {
                return new ParsedMessage {
                           Message  = new KeepAlive(),
                           Position = buf.GetPosition(off)
                }
            }
            ;

            if (len + off > buf.Length)
            {
                return(null);
            }

            var type = buf.Slice(off++, 1).FirstSpan[0];

            IProtocolMessage?parsed = null;

            switch (type)
            {
            case 0:
                parsed = new Choke();
                break;

            case 1:
                parsed = new Unchoke();
                break;

            case 2:
                parsed = new Interested();
                break;

            case 3:
                parsed = new NotInterested();
                break;

            case 4: {
                var idx = be.GetUInt32(buf.Slice(off, 4).ToArray());
                off   += 4;
                parsed = new Have {
                    PieceIndex = idx
                };
                break;
            }

            case 5: {
                var bitfieldLen = (int)(len - 1);
                var bits        = buf.Slice(off, bitfieldLen).ToArray();
                off   += bitfieldLen;
                parsed = new Bitfield {
                    Bits = bits
                };
                break;
            }

            case 6:
                throw new NotImplementedException("Request");

            case 7:
                throw new NotImplementedException("Piece");

            case 8:
                throw new NotImplementedException("Cancel");

            case 20:
                throw new NotImplementedException("Extension Message");

            default:
                throw new ArgumentOutOfRangeException(nameof(type), $"Invalid Peer Message type {type}");
            }

            if (parsed != null)
            {
                return new ParsedMessage {
                           Message  = parsed,
                           Position = buf.GetPosition(off)
                }
            }
            ;

            return(null);
        }
    }
}