Пример #1
0
 public void GetObjectRequiresNonNullOrEmptyHash()
 {
     Database db = new Database(new HashGenerator(new SHA1Managed()), new Mock<IReferenceDirectory>().Object, new Mock<IPersistentDictionary>().Object, new GitObjectCodec(), new Mock<IPackedObjectDatabase>().Object);
     Assert.Throws<ArgumentException>(() => db.GetObject(null))
           .WithParamName("hash")
           .WithMessage(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "hash");
     Assert.Throws<ArgumentException>(() => db.GetObject(String.Empty))
           .WithParamName("hash")
           .WithMessage(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "hash");
 }
Пример #2
0
        public void GetObjectReturnsNullIfObjectDoesNotExist()
        {
            // Arrange
            Mock<IPersistentDictionary> mockStorage = new Mock<IPersistentDictionary>();
            Database db = new Database(new HashGenerator(new SHA1Managed()), new Mock<IReferenceDirectory>().Object, mockStorage.Object, new GitObjectCodec(), new Mock<IPackedObjectDatabase>().Object);
            mockStorage.Setup(s => s.Exists("abcdefghij")).Returns(false);

            // Act/Assert
            Assert.Null(db.GetObject("abcdefghij"));
        }
Пример #3
0
        public void GetObjectReturnsDecodedObjectIfObjectExists()
        {
            // Arrange
            Mock<IPersistentDictionary> mockStorage = new Mock<IPersistentDictionary>(MockBehavior.Strict);
            Mock<IObjectCodec> mockCodec = new Mock<IObjectCodec>(MockBehavior.Strict);
            Database db = new Database(new HashGenerator(new SHA1Managed()), new Mock<IReferenceDirectory>().Object, mockStorage.Object, mockCodec.Object, new Mock<IPackedObjectDatabase>().Object);
            Stream expectedStrm = new MemoryStream();
            DatabaseObject expectedObj = DatabaseObject.Null();
            mockStorage.Setup(s => s.Exists("abcdefghij")).Returns(true);
            mockStorage.Setup(s => s.OpenRead("abcdefghij")).Returns(expectedStrm);
            mockCodec.Setup(d => d.Decode(expectedStrm)).Returns(expectedObj);

            // Act/Assert
            Assert.Same(expectedObj, db.GetObject("abcdefghij"));
        }