示例#1
0
 public Task UpdateAsync(Lot lot)
 {
     var oldLot = FindAsync(lot.Id).Result;
     oldLot.Title = lot.Title;
     oldLot.Description = lot.Description;
     return Task.FromResult("");
 }
示例#2
0
        public void ShouldReturnLotWhenGETForExistingLot()
        {
            var lot = new Lot {Id = 1};

            _lotStore.FindAsync(1).Returns(Task.FromResult(lot));

            var foundLot = _controller.Get(1).Result;

            Assert.Equal(lot, foundLot);
        }
示例#3
0
        public void ShouldReturnAllBidsWhenGETForExistingLot()
        {
            var lot = new Lot(new[] {new Bid(), new Bid()});

            _lotStore.FindAsync(Arg.Any<int>()).Returns(Task.FromResult(lot));

            var foundBids = _controller.GetByLotId(Arg.Any<int>()).Result;

            Assert.Equal(lot.Bids, foundBids);
        }
示例#4
0
        public void ShouldCallCreateAsyncWhenPOSTForNewLot()
        {
            //Arrange
            ConfigureForTesting(_controller, HttpMethod.Post, "http://test.com/lots"); // <1>
            var createdLot = new Lot { Id = 1 };

            //Act
            var response = _controller.Post(createdLot).Result; // <3>

            //Assert
            _lotStore.ReceivedWithAnyArgs().CreateAsync(Arg.Any<Lot>()); // <4>
        }
示例#5
0
        public async Task<HttpResponseMessage> Post(Lot lot)
        {
            await _store.CreateAsync(lot);
            var response = Request.CreateResponse(HttpStatusCode.Created, lot);

            var urlHelper = new UrlHelper(Request);
            var controllerName = this.GetType().Name;
            controllerName = controllerName.Substring(0, controllerName.Length - "controller".Length).ToLower();

            response.Headers.Location = new Uri(urlHelper.Link(RouteConfig.DefaultApi, new { controller = controllerName, id = lot.Id }));

            return response;
        }
        private static JObject BuildEntity(Lot lot)
        {
            if (lot == null) throw new ArgumentNullException();

            return new EntityBuilder("lot", lot.Id.ToString())

                .Properties("Id", lot.Id.ToString())
                .Properties("Title", lot.Title)
                .Properties("Description", lot.Description)
                .Properties("CurrentPrice", lot.CurrentPrice.ToString())
                .Properties("StartTime", lot.StartTime.ToShortDateString())
                .Properties("EndTime", lot.EndTime.ToShortDateString())
                .Properties("StartPrice", lot.StartPrice.ToString())

                .EmbeddedLink("bids", null)

                .EmbeddedRepresentation("owner", lot.Owner.Username,
                    new Dictionary<string, string> {{"username", lot.Owner.Username}})

                .Action("bids", "add-bid", "POST",
                    new Dictionary<string, string> {{"lotId", lot.Id.ToString()}, {"userId", null}, {"amount", null}})

                .Build();
        }
示例#7
0
        public void ShouldSetResponseHeadersWhenPOSTForNewLot()
        {
            //Arrange
            ConfigureForTesting(_controller, HttpMethod.Post, "http://test.com/lots");
            var createdLot = new Lot {Id = 1};
            _lotStore.CreateAsync(createdLot).Returns(Task.FromResult(createdLot)); // <1>

            //Act
            var response = _controller.Post(createdLot).Result; // <2>

            //Assert
            Assert.Equal(response.StatusCode, HttpStatusCode.Created); // <3>
            Assert.Equal(response.Headers.Location.AbsoluteUri, "http://test.com/lots/1");
        }
示例#8
0
 public Task CreateAsync(Lot lot)
 {
     lot.Id = ++_id;
     _lots.Add(lot);
     return Task.FromResult(lot);
 }