Exemple #1
0
        public void UpdateToAMicrobreweryPersists()
        {
            Microbrewery m = new Microbrewery
            {
                Name      = "Test",
                FoundedOn = new DateTime(2017, 03, 01),
                Id        = Guid.NewGuid()
            };

            mbr.Add(m);

            Microbrewery n = new Microbrewery
            {
                Name      = "Updated",
                FoundedOn = new DateTime(2017, 04, 08),
                Id        = m.Id
            };

            mbr.GetByName("Test").Should().NotBeNull();
            mbr.GetByName("Updated").Should().BeNull();

            mbr.Update(n);

            mbr.GetByName("Test").Should().BeNull();
            var updatedMicrobrewery = mbr.GetByName("Updated");

            updatedMicrobrewery.Should().NotBeNull();
            updatedMicrobrewery.Id.Should().Be(m.Id);
        }
Exemple #2
0
        public void UpdateToNonexistantMicrobreweryThrowsInvalidOperationException()
        {
            Microbrewery m = new Microbrewery
            {
                Name      = "Test",
                FoundedOn = new DateTime(2017, 03, 01),
                Id        = Guid.NewGuid()
            };

            Action a = () => { mbr.Update(m); };

            a.ShouldThrow <InvalidOperationException>();
        }
        public IActionResult UpdateById(Guid microbreweryId, [FromBody] Microbrewery microbrewery)
        {
            if (microbreweryId != microbrewery.Id)
            {
                return(NotFound(microbreweryId));
            }

            try
            {
                _microbreweryRepository.Update(microbrewery);
                return(Ok(microbrewery));
            }
            catch (InvalidOperationException)
            {
                return(NotFound(microbreweryId));
            }
        }
 public IActionResult AddMicrobrewery([FromBody] Microbrewery microbrewery)
 {
     _microbreweryRepository.Add(microbrewery);
     return(Created("microwbrewery", microbrewery));
 }