public void FindById_Finds() { var sprocket = new VersionedSprocket { Id = Guid.NewGuid(), Name = "FindMe" }; SprocketCollection.Insert(sprocket); SprocketRepo.Find(sprocket.Id).Name.Should().Be("FindMe"); }
public void Delete_Removes() { var sprocket = new VersionedSprocket { Id = Guid.NewGuid(), Name = "DeleteMe" }; SprocketCollection.Insert(sprocket); SprocketRepo.Delete(sprocket.Id); SprocketCollection.FindAll().Count(s => s.Id == sprocket.Id).Should().Be(0); }
public void StaleUpdate_ThrowsException() { var sprocket = new VersionedSprocket { Id = Guid.NewGuid(), Version = 1 }; SprocketCollection.Insert(sprocket); sprocket.Version = 0; sprocket.Name = "Saved"; SprocketRepo.Invoking(r => r.Update(sprocket)) .ShouldThrow <StaleObjectException>() .WithMessage("*VersionedSprocket*") .WithMessage("*updated by another transaction*"); sprocket.Version.Should().Be(0); }
public void Add_Inserts() { var sprocket = new VersionedSprocket { Id = Guid.NewGuid(), Name = "Outer", Sprockets = new[] { new VersionedSprocket { Id = Guid.NewGuid(), Name = "Inner" } } }; SprocketRepo.Add(sprocket); VersionedSprocket found = SprocketCollection.AsQueryable().Single(s => s.Id == sprocket.Id); found.Name.Should().Be("Outer"); found.Sprockets.Single().Name.Should().Be("Inner"); found.Version.Should().Be(0); }
public void Update_Saves() { var sprocket = new VersionedSprocket { Id = Guid.NewGuid(), Name = "Outer", Sprockets = new[] { new VersionedSprocket { Id = Guid.NewGuid(), Name = "Inner" } } }; SprocketCollection.Insert(sprocket); sprocket.Version.Should().Be(0); sprocket = SprocketCollection.AsQueryable().Single(s => s.Id == sprocket.Id); sprocket.Name = "Saved"; SprocketRepo.Update(sprocket); sprocket.Version.Should().Be(1); VersionedSprocket found = SprocketCollection.AsQueryable().Single(s => s.Id == sprocket.Id); found.Name.Should().Be("Saved"); found.Version.Should().Be(1); }