public async Task GivenOnePairInStore_WhenGetById_ThenReturnOnlyTheOne() { var pair = new SocksPair(SocksColour.White); Session.Save(pair); Session.Flush(); var response = (await Client.GetAsync($"api/drawer/{pair.Id}")).BodyAs<SocksPair>(); response.Colour.ShouldBe(pair.Colour); response.Id.ShouldBe(pair.Id); }
public void GivenOnePairInStore_WhenGetById_ThenReturnOnlyTheOne() { var pair = new SocksPair(SocksColour.White); Session.Save(pair); Session.Flush(); var response = Get($"/api/drawer/{pair.Id}").BodyAs <SocksPair>(); response.Colour.ShouldBe(pair.Colour); response.Id.ShouldBe(pair.Id); }
public async Task GivenOnePairInStore_WhenGetById_ThenReturnOnlyTheOne() { var pair = new SocksPair(SocksColour.White); Session.Save(pair); Session.Flush(); var response = (await Client.GetAsync($"api/drawer/{pair.Id}")).BodyAs <SocksPair>(); response.Colour.ShouldBe(pair.Colour); response.Id.ShouldBe(pair.Id); }
public void GivenTwoBlackPairsInStore_WhenDeleteOne_ThenOnlyOneRemains() { Session.Save(new SocksPair(SocksColour.Black)); var pairTwo = new SocksPair(SocksColour.Black); Session.Save(pairTwo); Session.Flush(); var response = Client.DeleteAsync($"api/drawer/{pairTwo.Id}").Result; response.StatusCode.ShouldBe(HttpStatusCode.OK); Session.Query<SocksPair>().Count().ShouldBe(1); Session.Query<SocksPair>().SingleOrDefault(p => p.Id == pairTwo.Id).ShouldBeNull(); }
public void GivenTwoBlackPairsInStore_WhenDeleteOne_ThenOnlyOneRemains() { Session.Save(new SocksPair(SocksColour.Black)); var pairTwo = new SocksPair(SocksColour.Black); Session.Save(pairTwo); Session.Flush(); var response = Delete($"/api/drawer/{pairTwo.Id}"); response.StatusCode.ShouldBe(HttpStatusCode.OK); Session.Query <SocksPair>().Count().ShouldBe(1); Session.Query <SocksPair>().SingleOrDefault(p => p.Id == pairTwo.Id).ShouldBeNull(); }
public IActionResult Post([FromBody]NewPairDto newPairDto) { var newSocksPair = new SocksPair((SocksColour)Enum.Parse(typeof(SocksColour), newPairDto.Colour, ignoreCase: true)); // yes, this is domain logic and shouldn't live in the controller if (_session.Query<SocksPair>().Count(p => p.Colour == SocksColour.White) == 6 && newSocksPair.Colour == SocksColour.White) return new ContentResult { StatusCode = (int?)HttpStatusCode.Forbidden, Content = "Maximum of 6 white pairs in the drawer at one time." }; _session.Save(newSocksPair); return Created($"api/drawer/{newSocksPair.Id}", newSocksPair); }
public IHttpActionResult Post(NewPairDto newPairDto) { var newSocksPair = new SocksPair((SocksColour)Enum.Parse(typeof(SocksColour), newPairDto.Colour, ignoreCase: true)); // yes, this is domain logic and shouldn't live in the controller if (_session.Query <SocksPair>().Count(p => p.Colour == SocksColour.White) == 6 && newSocksPair.Colour == SocksColour.White) { return(Content(HttpStatusCode.Forbidden, "Maximum of 6 white pairs in the drawer at one time.")); } _session.Save(newSocksPair); _session.Flush(); return(Created($"api/drawer/{newSocksPair.Id}", newSocksPair)); }