コード例 #1
0
        public void FindById_Finds()
        {
            var sprocket = new VersionedSprocket {
                Id = Guid.NewGuid(), Name = "FindMe"
            };

            SprocketCollection.Insert(sprocket);
            SprocketRepo.Find(sprocket.Id).Name.Should().Be("FindMe");
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }